some versions of jpeglib don't support color conversion. release-0-1-2
authorkramm <kramm>
Wed, 21 Nov 2001 17:21:04 +0000 (17:21 +0000)
committerkramm <kramm>
Wed, 21 Nov 2001 17:21:04 +0000 (17:21 +0000)
in this case, the conversion is now done here.

lib/modules/swfbits.c

index d6e59fc..1b311f8 100644 (file)
@@ -124,18 +124,33 @@ int swf_SetJPEGBits(TAG * t,char * fname,int quality)
 
   jpeg_stdio_src(&cinfo,f);
   jpeg_read_header(&cinfo, TRUE);
 
   jpeg_stdio_src(&cinfo,f);
   jpeg_read_header(&cinfo, TRUE);
-  cinfo.out_color_space = JCS_RGB; //automatically convert grayscale images
+  if(JPEG_LIB_VERSION>=62) /* jpeglib Version 6b is required for grayscale-> color conversion */
+    cinfo.out_color_space = JCS_RGB; //automatically convert grayscale images
   jpeg_start_decompress(&cinfo);
 
   out = swf_SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality);
   scanline = (U8*)malloc(4*cinfo.output_width);
   
   jpeg_start_decompress(&cinfo);
 
   out = swf_SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality);
   scanline = (U8*)malloc(4*cinfo.output_width);
   
-  if (scanline)
+  if (scanline) 
   { int y;
     U8 * js = scanline;
   { int y;
     U8 * js = scanline;
-    for (y=0;y<cinfo.output_height;y++)
-    { jpeg_read_scanlines(&cinfo,&js,1);
-      swf_SetJPEGBitsLines(out,(U8**)&js,1);
+    if(cinfo.out_color_space == JCS_GRAYSCALE) {
+       /* happens only if JPEG_LIB_VERSION above
+          was too small - let's do the conversion ourselves */
+       for (y=0;y<cinfo.output_height;y++)
+       { int x;
+         jpeg_read_scanlines(&cinfo,&js,1);
+         for(x=cinfo.output_width-1;x>=0;x--) {
+             js[x*3] = js[x*3+1] = js[x*3+2] = js[x];
+         }
+         swf_SetJPEGBitsLines(out,(U8**)&js,1);
+       }
+    }
+    else {
+       for (y=0;y<cinfo.output_height;y++)
+       { jpeg_read_scanlines(&cinfo,&js,1);
+         swf_SetJPEGBitsLines(out,(U8**)&js,1);
+       }
     }
   }
 
     }
   }