]> granicus.if.org Git - libjpeg-turbo/commitdiff
Use 8-bit write to avoid potential pointer aliasing issues (also, at least on x86...
authorDRC <dcommander@users.sourceforge.net>
Fri, 9 Sep 2011 18:15:53 +0000 (18:15 +0000)
committerDRC <dcommander@users.sourceforge.net>
Fri, 9 Sep 2011 18:15:53 +0000 (18:15 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@700 632fc199-4ca6-4c93-a231-07263d6284db

jdcolext.c
jdcolor.c

index af7ea7e81fc7afaa151e4a20e91d626427d114c4..07da949fae02d7f61de293ab8c9816372023a685 100644 (file)
@@ -54,16 +54,17 @@ ycc_rgb_convert_internal (j_decompress_ptr cinfo,
       y  = GETJSAMPLE(inptr0[col]);
       cb = GETJSAMPLE(inptr1[col]);
       cr = GETJSAMPLE(inptr2[col]);
-      /* Initialize 4-byte pixels so the alpha channel will be opaque */
-#if RGB_PIXELSIZE == 4
-      *(unsigned int *)outptr = 0xFFFFFFFF;
-#endif
       /* Range-limiting is essential due to noise introduced by DCT losses. */
       outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
       outptr[RGB_GREEN] = range_limit[y +
                              ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
                                                 SCALEBITS))];
       outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
+      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
+      /* alpha channel value */
+#ifdef RGB_ALPHA
+      outptr[RGB_ALPHA] = 0xFF;
+#endif
       outptr += RGB_PIXELSIZE;
     }
   }
@@ -90,12 +91,13 @@ gray_rgb_convert_internal (j_decompress_ptr cinfo,
     inptr = input_buf[0][input_row++];
     outptr = *output_buf++;
     for (col = 0; col < num_cols; col++) {
-      /* Initialize 4-byte pixels so the alpha channel will be opaque */
-#if RGB_PIXELSIZE == 4
-      *(unsigned int *)outptr = 0xFFFFFFFF;
-#endif
       /* We can dispense with GETJSAMPLE() here */
       outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
+      /* Set unused byte to 0xFF so it can be interpreted as an opaque */
+      /* alpha channel value */
+#ifdef RGB_ALPHA
+      outptr[RGB_ALPHA] = 0xFF;
+#endif
       outptr += RGB_PIXELSIZE;
     }
   }
index d6e5a10a2a2dcd8c77928db5363103afe0b4efbe..05d389a587ff205e1618d97075f7da58b21c31e8 100644 (file)
--- a/jdcolor.c
+++ b/jdcolor.c
@@ -90,6 +90,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #define RGB_RED EXT_RGBX_RED
 #define RGB_GREEN EXT_RGBX_GREEN
 #define RGB_BLUE EXT_RGBX_BLUE
+#define RGB_ALPHA 3
 #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
 #define ycc_rgb_convert_internal ycc_extrgbx_convert_internal
 #define gray_rgb_convert_internal gray_extrgbx_convert_internal
@@ -97,6 +98,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #undef RGB_RED
 #undef RGB_GREEN
 #undef RGB_BLUE
+#undef RGB_ALPHA
 #undef RGB_PIXELSIZE
 #undef ycc_rgb_convert_internal
 #undef gray_rgb_convert_internal
@@ -118,6 +120,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #define RGB_RED EXT_BGRX_RED
 #define RGB_GREEN EXT_BGRX_GREEN
 #define RGB_BLUE EXT_BGRX_BLUE
+#define RGB_ALPHA 3
 #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
 #define ycc_rgb_convert_internal ycc_extbgrx_convert_internal
 #define gray_rgb_convert_internal gray_extbgrx_convert_internal
@@ -125,6 +128,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #undef RGB_RED
 #undef RGB_GREEN
 #undef RGB_BLUE
+#undef RGB_ALPHA
 #undef RGB_PIXELSIZE
 #undef ycc_rgb_convert_internal
 #undef gray_rgb_convert_internal
@@ -132,6 +136,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #define RGB_RED EXT_XBGR_RED
 #define RGB_GREEN EXT_XBGR_GREEN
 #define RGB_BLUE EXT_XBGR_BLUE
+#define RGB_ALPHA 0
 #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
 #define ycc_rgb_convert_internal ycc_extxbgr_convert_internal
 #define gray_rgb_convert_internal gray_extxbgr_convert_internal
@@ -139,6 +144,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #undef RGB_RED
 #undef RGB_GREEN
 #undef RGB_BLUE
+#undef RGB_ALPHA
 #undef RGB_PIXELSIZE
 #undef ycc_rgb_convert_internal
 #undef gray_rgb_convert_internal
@@ -146,6 +152,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #define RGB_RED EXT_XRGB_RED
 #define RGB_GREEN EXT_XRGB_GREEN
 #define RGB_BLUE EXT_XRGB_BLUE
+#define RGB_ALPHA 0
 #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
 #define ycc_rgb_convert_internal ycc_extxrgb_convert_internal
 #define gray_rgb_convert_internal gray_extxrgb_convert_internal
@@ -153,6 +160,7 @@ typedef my_color_deconverter * my_cconvert_ptr;
 #undef RGB_RED
 #undef RGB_GREEN
 #undef RGB_BLUE
+#undef RGB_ALPHA
 #undef RGB_PIXELSIZE
 #undef ycc_rgb_convert_internal
 #undef gray_rgb_convert_internal