[AD] Patches for converting 6-bit to 8-bit colour components.

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Following on from the discussion on the [AL] list in the following thread: http://sourceforge.net/mailarchive/forum.php?thread_id=9484132&forum_id=34599 I have submitted a patch for graphics.c that uses more evenly distributed conversion tables for _rgb_scale_6[] and _rgb_scale_5[] . Also, I have submitted a patch for color.c that modifies create_blender_table() so that instead of using x * 256 / 63 to convert a 6-bit value to an 8-bit value, it uses (x << 2) | ((x & 0x30) >> 4). This not only creates a more evenly distributed distribution of the lower 2 bits, but it's faster as well. Although I'm not 100% sure if the extra '& 0x30' is needed, I decided to include it anyway because _set_colorconv_palette() in colconv.c uses it. Maybe it has something to do with the C standard not guaranteeing if the shift will be arithmetical or logical, but as we're dealing with unsigned chars, I'm not sure if that's an issue.

My fix for create_blender_table() is currently untested. I used some code to generate the new values for _rgb_scale_6[] and _rgb_scale_5[]. Anyway, I hope I've got the line-endings right with these patches.


AE.

--- color.c.old	2006-01-25 00:42:07.219712000 +0100
+++ color.c	2006-01-25 00:49:00.994691200 +0100
@@ -848,8 +848,8 @@ void create_color_table(COLOR_MAP *table
 
 
 /* create_blender_table:
- *  Fills the specified color mapping table with lookup data for doing a 
- *  paletted equivalent of whatever truecolor blender mode is currently 
+ *  Fills the specified color mapping table with lookup data for doing a
+ *  paletted equivalent of whatever truecolor blender mode is currently
  *  selected.
  */
 void create_blender_table(COLOR_MAP *table, AL_CONST PALETTE pal, void (*callback)(int pos))
@@ -863,13 +863,13 @@ void create_blender_table(COLOR_MAP *tab
 
    for (x=0; x<PAL_SIZE; x++) {
       for (y=0; y<PAL_SIZE; y++) {
-	 r1 = pal[x].r * 255 / 63;
-	 g1 = pal[x].g * 255 / 63;
-	 b1 = pal[x].b * 255 / 63;
-
-	 r2 = pal[y].r * 255 / 63;
-	 g2 = pal[y].g * 255 / 63;
-	 b2 = pal[y].b * 255 / 63;
+	 r1 = (pal[x].r << 2) | ((pal[x].r & 0x30) >> 4);
+	 g1 = (pal[x].g << 2) | ((pal[x].g & 0x30) >> 4);
+	 b1 = (pal[x].b << 2) | ((pal[x].b & 0x30) >> 4);
+
+	 r2 = (pal[y].r << 2) | ((pal[y].r & 0x30) >> 4);
+	 g2 = (pal[y].g << 2) | ((pal[y].g & 0x30) >> 4);
+	 b2 = (pal[y].b << 2) | ((pal[y].b & 0x30) >> 4);
 
 	 c = _blender_func24(makecol24(r1, g1, b1), makecol24(r2, g2, b2), _blender_alpha);
 
--- graphics.c.old	2005-12-24 17:57:10.755188800 +0100
+++ graphics.c	2006-01-25 00:09:37.746507200 +0100
@@ -96,10 +96,10 @@ int _rgb_a_shift_32 = DEFAULT_RGB_A_SHIF
 /* lookup table for scaling 5 bit colors up to 8 bits */
 int _rgb_scale_5[32] =
 {
-   0,   8,   16,  24,  32,  41,  49,  57,
-   65,  74,  82,  90,  98,  106, 115, 123,
-   131, 139, 148, 156, 164, 172, 180, 189,
-   197, 205, 213, 222, 230, 238, 246, 255
+   0,   8,   16,  24,  33,  41,  49,  57,
+   66,  74,  82,  90,  99,  107, 115, 123,
+   132, 140, 148, 156, 165, 173, 181, 189,
+   198, 206, 214, 222, 231, 239, 247, 255
 };
 
 
@@ -108,12 +108,12 @@ int _rgb_scale_6[64] =
 {
    0,   4,   8,   12,  16,  20,  24,  28,
    32,  36,  40,  44,  48,  52,  56,  60,
-   64,  68,  72,  76,  80,  85,  89,  93,
+   65,  69,  73,  77,  81,  85,  89,  93,
    97,  101, 105, 109, 113, 117, 121, 125,
-   129, 133, 137, 141, 145, 149, 153, 157,
-   161, 165, 170, 174, 178, 182, 186, 190,
-   194, 198, 202, 206, 210, 214, 218, 222,
-   226, 230, 234, 238, 242, 246, 250, 255
+   130, 134, 138, 142, 146, 150, 154, 158,
+   162, 166, 170, 174, 178, 182, 186, 190,
+   195, 199, 203, 207, 211, 215, 219, 223,
+   227, 231, 235, 239, 243, 247, 251, 255
 };
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/