diff options
author | sj <sj@openoffice.org> | 2009-12-21 17:44:36 +0100 |
---|---|---|
committer | sj <sj@openoffice.org> | 2009-12-21 17:44:36 +0100 |
commit | 45e8e0fbee40f9a8d91f4c559c8bbb16dd7b3f36 (patch) | |
tree | 3bcdd59908e6f149975d4c20fe4984da7278275a /svtools | |
parent | 8939f29a75911f10371ba1d8bc70cc88e418e5bd (diff) |
impress181: #i87410#: now writing greyscale jpgs if possible
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/filter.vcl/jpeg/jpeg.cxx | 39 | ||||
-rw-r--r-- | svtools/source/filter.vcl/jpeg/jpeg.h | 2 | ||||
-rw-r--r-- | svtools/source/filter.vcl/jpeg/jpegc.c | 14 |
3 files changed, 47 insertions, 8 deletions
diff --git a/svtools/source/filter.vcl/jpeg/jpeg.cxx b/svtools/source/filter.vcl/jpeg/jpeg.cxx index 81d07ccd5e79..ee2b2baebee0 100644 --- a/svtools/source/filter.vcl/jpeg/jpeg.cxx +++ b/svtools/source/filter.vcl/jpeg/jpeg.cxx @@ -656,10 +656,14 @@ void* JPEGWriter::GetScanline( long nY ) aColor = pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ); #ifndef SYSTEM_JPEG *pTmp++ = aColor.GetBlue(); + if ( bGreys ) + continue; *pTmp++ = aColor.GetGreen(); *pTmp++ = aColor.GetRed(); #else *pTmp++ = aColor.GetRed(); + if ( bGreys ) + continue; *pTmp++ = aColor.GetGreen(); *pTmp++ = aColor.GetBlue(); #endif @@ -672,10 +676,14 @@ void* JPEGWriter::GetScanline( long nY ) aColor = pAcc->GetPixel( nY, nX ); #ifndef SYSTEM_JPEG *pTmp++ = aColor.GetBlue(); + if ( bGreys ) + continue; *pTmp++ = aColor.GetGreen(); *pTmp++ = aColor.GetRed(); #else *pTmp++ = aColor.GetRed(); + if ( bGreys ) + continue; *pTmp++ = aColor.GetGreen(); *pTmp++ = aColor.GetBlue(); #endif @@ -711,20 +719,43 @@ BOOL JPEGWriter::Write( const Graphic& rGraphic ) pAcc = aGraphicBmp.AcquireReadAccess(); + if ( !bGreys ) // bitmap was not explicitely converted into greyscale, + { // check if source is greyscale only + + sal_Bool bIsGrey = sal_True; + + long nWidth = pAcc->Width(); + for ( long nY = 0; bIsGrey && ( nY < pAcc->Height() ); nY++ ) + { + BitmapColor aColor; + for( long nX = 0L; bIsGrey && ( nX < nWidth ); nX++ ) + { + aColor = pAcc->HasPalette() ? pAcc->GetPaletteColor( (BYTE) pAcc->GetPixel( nY, nX ) ) + : pAcc->GetPixel( nY, nX ); + bIsGrey = ( aColor.GetRed() == aColor.GetGreen() ) && ( aColor.GetRed() == aColor.GetBlue() ); + } + } + if ( bIsGrey ) + bGreys = sal_True; + } + if( pAcc ) { + if ( bGreys ) + bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL ); + else #ifndef SYSTEM_JPEG - bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR ); + bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR ); #else - bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB ); + bNative = ( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB ); #endif if( !bNative ) - pBuffer = new BYTE[ AlignedWidth4Bytes( pAcc->Width() * 24L ) ]; + pBuffer = new BYTE[ AlignedWidth4Bytes( bGreys ? pAcc->Width() * 8L : pAcc->Width() * 24L ) ]; JPEGCallbackStruct aCallbackData; aCallbackData.xStatusIndicator = xStatusIndicator; - bRet = (BOOL) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), nQuality, &aCallbackData ); + bRet = (BOOL) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), bGreys, nQuality, &aCallbackData ); delete[] pBuffer; pBuffer = NULL; diff --git a/svtools/source/filter.vcl/jpeg/jpeg.h b/svtools/source/filter.vcl/jpeg/jpeg.h index eaeaa503b5e9..4d5aafe413bb 100644 --- a/svtools/source/filter.vcl/jpeg/jpeg.h +++ b/svtools/source/filter.vcl/jpeg/jpeg.h @@ -64,7 +64,7 @@ void* JPEGMalloc( size_t size ); void JPEGFree( void *ptr ); long JPEGCallback( void* pCallbackData, long nPercent ); -long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, +long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, long bGreyScale, long nQualityPercent, void* pCallbackData ); void* GetScanline( void* pJPEGWriter, long nY ); diff --git a/svtools/source/filter.vcl/jpeg/jpegc.c b/svtools/source/filter.vcl/jpeg/jpegc.c index 84394d945f79..0525877f2614 100644 --- a/svtools/source/filter.vcl/jpeg/jpegc.c +++ b/svtools/source/filter.vcl/jpeg/jpegc.c @@ -182,7 +182,7 @@ Exit: } long WriteJPEG( void* pJPEGWriter, void* pOStm, - long nWidth, long nHeight, + long nWidth, long nHeight, long bGreys, long nQualityPercent, void* pCallbackData ) { struct jpeg_compress_struct cinfo; @@ -208,8 +208,16 @@ long WriteJPEG( void* pJPEGWriter, void* pOStm, cinfo.image_width = (JDIMENSION) nWidth; cinfo.image_height = (JDIMENSION) nHeight; - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; + if ( bGreys ) + { + cinfo.input_components = 1; + cinfo.in_color_space = JCS_GRAYSCALE; + } + else + { + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + } jpeg_set_defaults( &cinfo ); jpeg_set_quality( &cinfo, (int) nQualityPercent, FALSE ); |