From bb0e1a892475f452c21010e05199a4fb0b1f06b8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 11 Nov 2016 07:04:01 -0600 Subject: [PATCH] libwld: Should not depend on dev_pixel_t --- graphics/traveler/tools/libwld/wld_addplane.c | 1 - graphics/traveler/tools/libwld/wld_color.h | 53 +---------- .../traveler/tools/libwld/wld_discardplanes.c | 1 - .../traveler/tools/libwld/wld_findplane.c | 1 - graphics/traveler/tools/libwld/wld_free.c | 1 - .../tools/libwld/wld_initializeplanes.c | 1 - .../traveler/tools/libwld/wld_loadplanefile.c | 1 - .../traveler/tools/libwld/wld_loadplanes.c | 1 - graphics/traveler/tools/libwld/wld_malloc.c | 1 - .../tools/libwld/wld_mergeplanelists.c | 1 - .../traveler/tools/libwld/wld_moveplane.c | 1 - graphics/traveler/tools/libwld/wld_newplane.c | 1 - graphics/traveler/tools/libwld/wld_paltable.h | 6 ++ graphics/traveler/tools/libwld/wld_pcxinit.c | 1 - .../traveler/tools/libwld/wld_pixel2lum.c | 21 ++-- graphics/traveler/tools/libwld/wld_plane.c | 1 - .../traveler/tools/libwld/wld_readdecimal.c | 1 - graphics/traveler/tools/libwld/wld_realloc.c | 1 - .../traveler/tools/libwld/wld_removeplane.c | 1 - .../traveler/tools/libwld/wld_rgb2pixel.c | 1 - .../traveler/tools/libwld/wld_rgblookup.c | 95 ++++++++----------- .../traveler/tools/libwld/wld_saveplanes.c | 1 - graphics/traveler/tools/libwld/wld_utils.h | 1 - 23 files changed, 56 insertions(+), 138 deletions(-) diff --git a/graphics/traveler/tools/libwld/wld_addplane.c b/graphics/traveler/tools/libwld/wld_addplane.c index f7b9bf83e..72b1e3373 100644 --- a/graphics/traveler/tools/libwld/wld_addplane.c +++ b/graphics/traveler/tools/libwld/wld_addplane.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_color.h b/graphics/traveler/tools/libwld/wld_color.h index 9117b2599..875807a52 100644 --- a/graphics/traveler/tools/libwld/wld_color.h +++ b/graphics/traveler/tools/libwld/wld_color.h @@ -40,7 +40,6 @@ * Included Files ****************************************************************************/ -#include "trv_types.h" #include "trv_graphics.h" /**************************************************************************** @@ -80,54 +79,6 @@ # define NCOLOR_FORMS 5 #endif -/* Device pixel color conversions */ - -#if defined(CONFIG_GRAPHICS_TRAVELER_RGB16_565) -/* This macro creates RGB16 (5:6:5) - * - * R[7:3] -> RGB[15:11] - * G[7:2] -> RGB[10:5] - * B[7:3] -> RGB[4:0] - */ - -# define WLD_MKRGB(r,g,b) \ - ((((uint16_t)(r) << 8) & 0xf800) | (((uint16_t)(g) << 3) & 0x07e0) | (((uint16_t)(b) >> 3) & 0x001f)) - -/* And these macros perform the inverse transformation */ - -# define RGB2RED(rgb) (((rgb) >> 8) & 0xf8) -# define RGB2GREEN(rgb) (((rgb) >> 3) & 0xfc) -# define RGB2BLUE(rgb) (((rgb) << 3) & 0xf8) - -# define RGB_MAX_RED 0xf8 -# define RGB_MAX_GREEN 0xfc -# define RGB_MAX_BLUE 0xf8 - -#elif defined(CONFIG_GRAPHICS_TRAVELER_RGB32_888) -/* This macro creates RGB24 (8:8:8) - * - * R[7:3] -> RGB[15:11] - * G[7:2] -> RGB[10:5] - * B[7:3] -> RGB[4:0] - */ - -# define WLD_MKRGB(r,g,b) \ - ((uint32_t)((r) & 0xff) << 16 | (uint32_t)((g) & 0xff) << 8 | (uint32_t)((b) & 0xff)) - -/* And these macros perform the inverse transformation */ - -# define RGB2RED(rgb) (((rgb) >> 16) & 0xff) -# define RGB2GREEN(rgb) (((rgb) >> 8) & 0xff) -# define RGB2BLUE(rgb) ( (rgb) & 0xff) - -# define RGB_MAX_RED 0xff -# define RGB_MAX_GREEN 0xff -# define RGB_MAX_BLUE 0xff - -#else -# error No color format defined -#endif - /**************************************************************************** * Public Types ****************************************************************************/ @@ -195,10 +146,10 @@ typedef struct color_form_s color_form_t; * with distance */ -extern dev_pixel_t *g_devpixel_lut; +extern color_rgb_t *g_rgb_lut; #if RGB_CUBE_SIZE < MIN_LUM_LEVELS -extern color_lum_t *g_pixel2um_lut; +extern color_lum_t *g_lum_lut; /* The following defines the "form" of each color in the g_unit_vector array */ diff --git a/graphics/traveler/tools/libwld/wld_discardplanes.c b/graphics/traveler/tools/libwld/wld_discardplanes.c index ee992e297..347e4f77c 100644 --- a/graphics/traveler/tools/libwld/wld_discardplanes.c +++ b/graphics/traveler/tools/libwld/wld_discardplanes.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_mem.h" #include "wld_plane.h" diff --git a/graphics/traveler/tools/libwld/wld_findplane.c b/graphics/traveler/tools/libwld/wld_findplane.c index f2978d6a6..b5f8259c3 100644 --- a/graphics/traveler/tools/libwld/wld_findplane.c +++ b/graphics/traveler/tools/libwld/wld_findplane.c @@ -40,7 +40,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_free.c b/graphics/traveler/tools/libwld/wld_free.c index b313a2b5f..64aa33ad9 100644 --- a/graphics/traveler/tools/libwld/wld_free.c +++ b/graphics/traveler/tools/libwld/wld_free.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_utils.h" #include "wld_mem.h" diff --git a/graphics/traveler/tools/libwld/wld_initializeplanes.c b/graphics/traveler/tools/libwld/wld_initializeplanes.c index bee6ddafd..a554d8c32 100644 --- a/graphics/traveler/tools/libwld/wld_initializeplanes.c +++ b/graphics/traveler/tools/libwld/wld_initializeplanes.c @@ -41,7 +41,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_loadplanefile.c b/graphics/traveler/tools/libwld/wld_loadplanefile.c index 97a7fa965..7b3b0a994 100644 --- a/graphics/traveler/tools/libwld/wld_loadplanefile.c +++ b/graphics/traveler/tools/libwld/wld_loadplanefile.c @@ -42,7 +42,6 @@ #include #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_loadplanes.c b/graphics/traveler/tools/libwld/wld_loadplanes.c index 359f9ff4d..e6f4ba790 100644 --- a/graphics/traveler/tools/libwld/wld_loadplanes.c +++ b/graphics/traveler/tools/libwld/wld_loadplanes.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_malloc.c b/graphics/traveler/tools/libwld/wld_malloc.c index f1c9bbcf9..d40d4911a 100644 --- a/graphics/traveler/tools/libwld/wld_malloc.c +++ b/graphics/traveler/tools/libwld/wld_malloc.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_mem.h" #include "wld_utils.h" diff --git a/graphics/traveler/tools/libwld/wld_mergeplanelists.c b/graphics/traveler/tools/libwld/wld_mergeplanelists.c index 917beaf90..d90db0577 100644 --- a/graphics/traveler/tools/libwld/wld_mergeplanelists.c +++ b/graphics/traveler/tools/libwld/wld_mergeplanelists.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_moveplane.c b/graphics/traveler/tools/libwld/wld_moveplane.c index 9f064cadc..53943d76d 100644 --- a/graphics/traveler/tools/libwld/wld_moveplane.c +++ b/graphics/traveler/tools/libwld/wld_moveplane.c @@ -40,7 +40,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_newplane.c b/graphics/traveler/tools/libwld/wld_newplane.c index 1e2581ee4..ae0e48540 100644 --- a/graphics/traveler/tools/libwld/wld_newplane.c +++ b/graphics/traveler/tools/libwld/wld_newplane.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_mem.h" #include "wld_plane.h" diff --git a/graphics/traveler/tools/libwld/wld_paltable.h b/graphics/traveler/tools/libwld/wld_paltable.h index 09be692a0..a30bbb768 100644 --- a/graphics/traveler/tools/libwld/wld_paltable.h +++ b/graphics/traveler/tools/libwld/wld_paltable.h @@ -42,6 +42,12 @@ extern "C" { #endif /* __cplusplus */ +/************************************************************************* + * Included Files + *************************************************************************/ + +#include "trv_types.h" /* For trv_pixel_t */ + /************************************************************************* * Pre-processor Definitions *************************************************************************/ diff --git a/graphics/traveler/tools/libwld/wld_pcxinit.c b/graphics/traveler/tools/libwld/wld_pcxinit.c index 89f023a26..8af2879be 100644 --- a/graphics/traveler/tools/libwld/wld_pcxinit.c +++ b/graphics/traveler/tools/libwld/wld_pcxinit.c @@ -42,7 +42,6 @@ # include # include -# include "trv_types.h" # include "wld_mem.h" # include "wld_pcx.h" diff --git a/graphics/traveler/tools/libwld/wld_pixel2lum.c b/graphics/traveler/tools/libwld/wld_pixel2lum.c index 6caf78efc..0df9ff27d 100644 --- a/graphics/traveler/tools/libwld/wld_pixel2lum.c +++ b/graphics/traveler/tools/libwld/wld_pixel2lum.c @@ -41,7 +41,6 @@ #include -#include "trv_types.h" #include "wld_paltable.h" #include "wld_color.h" @@ -56,26 +55,20 @@ void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t * lum) { - dev_pixel_t devpixel = g_devpixel_lut[pixel_value]; - - /* Convert the pixel to its RGB components */ - - lum->red = (float)RGB2RED(devpixel) / (float)RGB_MAX_RED; - lum->green = (float)RGB2GREEN(devpixel) / (float)RGB_MAX_GREEN; - lum->blue = (float)RGB2BLUE(devpixel) / (float)RGB_MAX_BLUE; + color_rgb_t *rgb = &g_rgb_lut[pixel_value]; /* Get the luminance associated with the RGB value */ - lum->luminance = sqrt(lum->red * lum->red + - lum->green * lum->green + - lum->blue * lum->blue); + lum->luminance = sqrt(rgb->red * rgb->red + + rgb->green * rgb->green + + rgb->blue * rgb->blue); /* Convert the RGB Component into unit vector + luminance */ if (lum->luminance > 0.0) { - lum->red /= lum->luminance; - lum->blue /= lum->luminance; - lum->green /= lum->luminance; + lum->red = rgb->red * lum->luminance; + lum->blue = rgb->green * lum->luminance; + lum->green = rgb->blue * lum->luminance; } } diff --git a/graphics/traveler/tools/libwld/wld_plane.c b/graphics/traveler/tools/libwld/wld_plane.c index 05e3e6261..4922a9486 100644 --- a/graphics/traveler/tools/libwld/wld_plane.c +++ b/graphics/traveler/tools/libwld/wld_plane.c @@ -40,7 +40,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_readdecimal.c b/graphics/traveler/tools/libwld/wld_readdecimal.c index 6582d6e80..75c92062b 100644 --- a/graphics/traveler/tools/libwld/wld_readdecimal.c +++ b/graphics/traveler/tools/libwld/wld_readdecimal.c @@ -40,7 +40,6 @@ #include #include -#include "trv_types.h" #include "wld_utils.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_realloc.c b/graphics/traveler/tools/libwld/wld_realloc.c index ae53676d3..0fb944448 100644 --- a/graphics/traveler/tools/libwld/wld_realloc.c +++ b/graphics/traveler/tools/libwld/wld_realloc.c @@ -39,7 +39,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_mem.h" #include "wld_utils.h" diff --git a/graphics/traveler/tools/libwld/wld_removeplane.c b/graphics/traveler/tools/libwld/wld_removeplane.c index 0693b82cc..054991b14 100644 --- a/graphics/traveler/tools/libwld/wld_removeplane.c +++ b/graphics/traveler/tools/libwld/wld_removeplane.c @@ -40,7 +40,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_rgb2pixel.c b/graphics/traveler/tools/libwld/wld_rgb2pixel.c index 4344bb905..f1d555433 100644 --- a/graphics/traveler/tools/libwld/wld_rgb2pixel.c +++ b/graphics/traveler/tools/libwld/wld_rgb2pixel.c @@ -39,7 +39,6 @@ #include -#include "trv_types.h" #include "wld_color.h" /**************************************************************************** diff --git a/graphics/traveler/tools/libwld/wld_rgblookup.c b/graphics/traveler/tools/libwld/wld_rgblookup.c index 1bd30d8c0..c9c091031 100644 --- a/graphics/traveler/tools/libwld/wld_rgblookup.c +++ b/graphics/traveler/tools/libwld/wld_rgblookup.c @@ -40,7 +40,6 @@ #include #include -#include "trv_types.h" #include "wld_mem.h" #include "wld_utils.h" #include "wld_color.h" @@ -59,7 +58,7 @@ ****************************************************************************/ #if RGB_CUBE_SIZE >= MIN_LUM_LEVELS -static color_rgb_t *g_devpixel_lut = NULL; +static color_rgb_t *g_rgb_lut = NULL; static float g_wld_cube2pixel; #endif @@ -68,7 +67,7 @@ static float g_wld_cube2pixel; ****************************************************************************/ #if RGB_CUBE_SIZE < MIN_LUM_LEVELS -color_lum_t *g_pixel2um_lut; +color_lum_t *g_lum_lut; /* The following defines the "form" of each color in the g_unit_vector array */ @@ -152,30 +151,30 @@ const color_lum_t g_unit_vector[NUNIT_VECTORS] = void wld_rgblookup_allocate(void) { #if RGB_CUBE_SIZE < MIN_LUM_LEVELS - dev_pixel_t *lut; + color_rgb_t *lut; int uvndx; int lumndx; int index; /* Check if a color lookup table has been allocated */ - g_devpixel_lut = (dev_pixel_t *) - wld_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS * NLUMINANCES)); + g_rgb_lut = (color_rgb_t *) + wld_malloc(sizeof(color_rgb_t) * (NUNIT_VECTORS * NLUMINANCES)); - if (!g_devpixel_lut) + if (!g_rgb_lut) { wld_fatal_error("ERROR: Failed to allocate color lookup table\n"); } - lut = g_devpixel_lut; + lut = g_rgb_lut; /* Save the color information and color lookup table for use in color mapping * below. */ - g_pixel2um_lut = (color_lum_t *) + g_lum_lut = (color_lum_t *) wld_malloc(sizeof(color_lum_t) * (NUNIT_VECTORS * NLUMINANCES)); - if (!g_pixel2um_lut) + if (!g_lum_lut) { wld_fatal_error("ERROR: Failed to allocate luminance table\n"); } @@ -187,41 +186,36 @@ void wld_rgblookup_allocate(void) { for (lumndx = 0; lumndx < NLUMINANCES; lumndx++) { - color_rgb_t color; color_lum_t *lum; /* Get a convenience pointer to the lookup table entry */ - lum = &g_pixel2um_lut[index]; + lum = &g_lum_lut[index]; *lum = g_unit_vector[uvndx]; /* Get the luminance associated with this lum for this unit vector. */ lum->luminance = (lum->luminance * (float)(lumndx + 1)) / NLUMINANCES; - /* Convert to RGB and allocate the color */ + /* Convert to RGB in lookup table */ - color.red = (short)(lum->red * lum->luminance); - color.green = (short)(lum->green * lum->luminance); - color.blue = (short)(lum->blue * lum->luminance); - - /* Save the RGB to pixel lookup data */ - - lut[index] = WLD_MKRGB(color.red, color.green, color.blue); + lut[index].red = (short)(lum->red * lum->luminance); + lut[index].green = (short)(lum->green * lum->luminance); + lut[index].blue = (short)(lum->blue * lum->luminance); } } #else - dev_pixel_t *lut; + color_rgb_t *lut; int index; color_rgb_t rgb; /* Check if a color lookup table has been allocated */ - g_devpixel_lut = (dev_pixel_t *) - wld_malloc(sizeof(dev_pixel_t) * (WLD_PIXEL_MAX + 1)); + g_rgb_lut = (color_rgb_t *) + wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX + 1)); - if (!g_devpixel_lut) + if (!g_rgb_lut) { wld_fatal_error("ERROR: Failed to allocate color lookup table\n"); } @@ -229,22 +223,22 @@ void wld_rgblookup_allocate(void) /* Save the color information and color lookup table for use in subsequent * color mapping. */ - lut = g_devpixel_lut; + lut = g_rgb_lut; /* Check if a Pixel-to-RGB color mapping table has been allocated */ - g_devpixel_lut = (color_rgb_t *) + g_rgb_lut = (color_rgb_t *) wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX + 1)); - if (!g_devpixel_lut) + if (!g_rgb_lut) { wld_fatal_error("ERROR: Failed to allocate luminance table\n"); } for (index = 0; index <= WLD_PIXEL_MAX; index++) { - g_devpixel_lut[index].red - = g_devpixel_lut[index].green = g_devpixel_lut[index].blue = 0; + g_rgb_lut[index].red + = g_rgb_lut[index].green = g_rgb_lut[index].blue = 0; } /* Calculate the cube to trv_pixel_t scale factor. This factor will convert @@ -256,26 +250,19 @@ void wld_rgblookup_allocate(void) /* Allocate each color in the RGB Cube */ for (rgb.red = 0; rgb.red < RGB_CUBE_SIZE; rgb.red++) - for (rgb.green = 0; rgb.green < RGB_CUBE_SIZE; rgb.green++) - for (rgb.blue = 0; rgb.blue < RGB_CUBE_SIZE; rgb.blue++) + { + for (rgb.green = 0; rgb.green < RGB_CUBE_SIZE; rgb.green++) { - color_rgb_t color; - - color.red = (short)(rgb.red * 65535 / (RGB_CUBE_SIZE - 1)); - color.green = (short)(rgb.green * 65535 / (RGB_CUBE_SIZE - 1)); - color.blue = (short)(rgb.blue * 65535 / (RGB_CUBE_SIZE - 1)); - - /* Save the RGB to pixel lookup data */ - - lut[index] = WLD_MKRGB(color.red, color.green, color.blue); - - /* Save the pixel to RGB lookup data */ - - if (color.pixel <= WLD_PIXEL_MAX) + for (rgb.blue = 0; rgb.blue < RGB_CUBE_SIZE; rgb.blue++) { - g_devpixel_lut[color.pixel] = rgb; + /* Save the RGB to pixel lookup data */ + + lut[index].red = (short)(rgb.red * 65535 / (RGB_CUBE_SIZE - 1)); + lut[index].green = (short)(rgb.green * 65535 / (RGB_CUBE_SIZE - 1)); + lut[index].blue = (short)(rgb.blue * 65535 / (RGB_CUBE_SIZE - 1)); } } + } #endif } @@ -291,16 +278,16 @@ void wld_rgblookup_allocate(void) void wld_color_endmapping(void) { #if RGB_CUBE_SIZE < MIN_LUM_LEVELS - if (g_pixel2um_lut) + if (g_lum_lut) { - wld_free(g_pixel2um_lut); - g_pixel2um_lut = NULL; + wld_free(g_lum_lut); + g_lum_lut = NULL; } #else - if (g_devpixel_lut) + if (g_rgb_lut) { - wld_free(g_devpixel_lut); - g_devpixel_lut = NULL; + wld_free(g_rgb_lut); + g_rgb_lut = NULL; } #endif } @@ -315,9 +302,9 @@ void wld_color_endmapping(void) void wld_rgblookup_free(void) { - if (g_devpixel_lut) + if (g_rgb_lut) { - wld_free(g_devpixel_lut); - g_devpixel_lut = NULL; + wld_free(g_rgb_lut); + g_rgb_lut = NULL; } } diff --git a/graphics/traveler/tools/libwld/wld_saveplanes.c b/graphics/traveler/tools/libwld/wld_saveplanes.c index 5b4becafd..8e10a0878 100644 --- a/graphics/traveler/tools/libwld/wld_saveplanes.c +++ b/graphics/traveler/tools/libwld/wld_saveplanes.c @@ -40,7 +40,6 @@ *************************************************************************/ #include -#include "trv_types.h" #include "wld_plane.h" /************************************************************************* diff --git a/graphics/traveler/tools/libwld/wld_utils.h b/graphics/traveler/tools/libwld/wld_utils.h index 2aa062c5e..6d3a3a2ee 100644 --- a/graphics/traveler/tools/libwld/wld_utils.h +++ b/graphics/traveler/tools/libwld/wld_utils.h @@ -41,7 +41,6 @@ *************************************************************************/ #include -#include "trv_types.h" /************************************************************************* * Global Function Prototypes