1 --- svtools/source/filter.vcl/jpeg/jpegc.c.orig 2006-09-08 10:25:21.000000000 +0200
2 +++ svtools/source/filter.vcl/jpeg/jpegc.c 2007-11-02 17:40:10.000000000 +0100
8 +#include "rtl/alloc.h"
9 +#include "osl/diagnose.h"
13 @@ -86,6 +87,9 @@ void ReadJPEG( void* pJPEGReader, void*
17 + JSAMPLE * range_limit;
18 + HPBYTE pScanLineBuffer = NULL;
19 + long nScanLineBufferComponents = 0;
20 // declare bDecompCreated volatile because of gcc
21 // warning: variable 'bDecompCreated' might be clobbered by `longjmp' or `vfork'
22 volatile long bDecompCreated = 0;
23 @@ -111,8 +115,12 @@ void ReadJPEG( void* pJPEGReader, void*
24 cinfo.output_gamma = 1.0;
25 cinfo.raw_data_out = FALSE;
26 cinfo.quantize_colors = FALSE;
27 - if ( cinfo.jpeg_color_space != JCS_GRAYSCALE )
28 - cinfo.out_color_space = JCS_RGB;
29 + if ( cinfo.jpeg_color_space == JCS_YCbCr )
30 + cinfo.out_color_space = JCS_RGB;
31 + else if ( cinfo.jpeg_color_space == JCS_YCCK )
32 + cinfo.out_color_space = JCS_CMYK;
34 + OSL_ASSERT(cinfo.out_color_space == JCS_CMYK || cinfo.out_color_space == JCS_GRAYSCALE || cinfo.out_color_space == JCS_RGB);
36 /* change scale for preview import */
37 if( nPreviewWidth || nPreviewHeight )
38 @@ -156,6 +164,14 @@ void ReadJPEG( void* pJPEGReader, void*
39 aCreateBitmapParam.bGray = cinfo.output_components == 1;
40 pDIB = CreateBitmap( pJPEGReader, &aCreateBitmapParam );
41 nAlignedWidth = aCreateBitmapParam.nAlignedWidth;
42 + range_limit=cinfo.sample_range_limit;
44 + if ( cinfo.out_color_space == JCS_CMYK )
46 + nScanLineBufferComponents = cinfo.output_width * 4;
47 + pScanLineBuffer = rtl_allocateMemory( nScanLineBufferComponents );
52 if( aCreateBitmapParam.bTopDown )
53 @@ -168,17 +184,37 @@ void ReadJPEG( void* pJPEGReader, void*
55 for ( *pLines = 0; *pLines < nHeight; (*pLines)++ )
57 + if (pScanLineBuffer!=NULL) { // in other words cinfo.out_color_space == JCS_CMYK
60 + jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pScanLineBuffer, 1 );
61 + // convert CMYK to RGB
62 + for( i=0, j=0; i < nScanLineBufferComponents; i+=4, j+=3 )
64 + int c_=255-pScanLineBuffer[i+0];
65 + int m_=255-pScanLineBuffer[i+1];
66 + int y_=255-pScanLineBuffer[i+2];
67 + int k_=255-pScanLineBuffer[i+3];
68 + pTmp[j+0]=range_limit[ 255L - ( c_ + k_ ) ];
69 + pTmp[j+1]=range_limit[ 255L - ( m_ + k_ ) ];
70 + pTmp[j+2]=range_limit[ 255L - ( y_ + k_ ) ];
73 jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &pTmp, 1 );
76 - if ( cinfo.err->msg_code == 113 )
79 - pTmp += nAlignedWidth;
82 + if ( cinfo.err->msg_code == 113 )
85 + pTmp += nAlignedWidth;
89 jpeg_finish_decompress( &cinfo );
90 + if (pScanLineBuffer!=NULL) {
91 + rtl_freeMemory( pScanLineBuffer );
92 + pScanLineBuffer=NULL;