Browse Source

Fix plJPEG to work against vanilla libjpeg

Michael Hansen 14 years ago
parent
commit
c744b7d6dc
  1. 43
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp

43
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp

@ -222,7 +222,7 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
#else #else
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
case JCS_YCbCr: case JCS_YCbCr:
cinfo.out_color_space = JCS_RGBA; cinfo.out_color_space = JCS_RGB;
break; break;
#endif #endif
@ -270,11 +270,27 @@ plMipmap *plJPEG::IRead( hsStream *inStream )
if( sLastErrCode != IJL_OK ) if( sLastErrCode != IJL_OK )
throw( false ); throw( false );
#else #else
JSAMPROW jbuffer;
int row_stride = cinfo.output_width * cinfo.output_components;
int out_stride = cinfo.output_width * 4; // Decompress to RGBA
jbuffer = TRACKED_NEW JSAMPLE[row_stride];
UInt8 *destp = (UInt8 *)newMipmap->GetImage();
while( cinfo.output_scanline < cinfo.output_height ) while( cinfo.output_scanline < cinfo.output_height )
{ {
UInt8 *startp = newMipmap->GetAddr8( 0, cinfo.output_scanline ); (void) jpeg_read_scanlines( &cinfo, &jbuffer, 1 );
(void) jpeg_read_scanlines( &cinfo, &startp, 1 ); (void) memset( destp, 0xFF, out_stride );
for( size_t pixel = 0; pixel < cinfo.output_width; ++pixel )
{
(void) memcpy( destp + (pixel * 4),
jbuffer + (pixel * cinfo.output_components),
cinfo.out_color_components );
} }
}
(void) jpeg_finish_decompress(&cinfo);
delete [] jbuffer;
#endif #endif
// Sometimes life just sucks // Sometimes life just sucks
@ -388,8 +404,8 @@ hsBool plJPEG::IWrite( plMipmap *source, hsStream *outStream )
#else #else
cinfo.image_width = source->GetWidth(); cinfo.image_width = source->GetWidth();
cinfo.image_height = source->GetHeight(); cinfo.image_height = source->GetHeight();
cinfo.input_components = 4; cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGBA; cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults( &cinfo ); jpeg_set_defaults( &cinfo );
#endif #endif
@ -421,12 +437,25 @@ hsBool plJPEG::IWrite( plMipmap *source, hsStream *outStream )
if( sLastErrCode != IJL_OK ) if( sLastErrCode != IJL_OK )
throw( false ); throw( false );
#else #else
JSAMPROW jbuffer;
int in_stride = cinfo.image_width * 4; // Input is always RGBA
int row_stride = cinfo.image_width * cinfo.input_components;
jbuffer = TRACKED_NEW JSAMPLE[row_stride];
UInt8 *srcp = (UInt8 *)source->GetImage();
while( cinfo.next_scanline < cinfo.image_height ) while( cinfo.next_scanline < cinfo.image_height )
{ {
UInt8 *startp = source->GetAddr8( 0, cinfo.next_scanline ); for( size_t pixel = 0; pixel < cinfo.image_width; ++pixel )
(void) jpeg_write_scanlines( &cinfo, &startp, 1 ); {
(void) memcpy( jbuffer + (pixel * cinfo.input_components),
srcp + (pixel * 4), cinfo.input_components );
} }
(void) jpeg_write_scanlines( &cinfo, &jbuffer, 1 );
}
jpeg_finish_compress( &cinfo ); jpeg_finish_compress( &cinfo );
delete [] jbuffer;
#endif #endif
#ifdef IJL_SDK_AVAILABLE #ifdef IJL_SDK_AVAILABLE

Loading…
Cancel
Save