summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-03-29 18:04:54 +0100
committerTomaž Vajngerl <quikee@gmail.com>2013-03-31 13:53:01 +0200
commitdc10b3d739ed3a8b6a2a6b54f748f2bac0edf205 (patch)
treefc8f46cebe8d4f4a96f01772661499a2a1aa7aee
parent47ebfd8381a11b8d544193783702d057a33a8c52 (diff)
Add Chroma subsampling options to jpeg writer.
Change-Id: I247a261bb96b0c437a43922070777892cdcbc1f6
-rw-r--r--vcl/source/filter/jpeg/jpeg.cxx3
-rw-r--r--vcl/source/filter/jpeg/jpeg.h2
-rw-r--r--vcl/source/filter/jpeg/jpeg.hxx5
-rw-r--r--vcl/source/filter/jpeg/jpegc.c20
4 files changed, 24 insertions, 6 deletions
diff --git a/vcl/source/filter/jpeg/jpeg.cxx b/vcl/source/filter/jpeg/jpeg.cxx
index 206c92d67392..837e7c5c6cb7 100644
--- a/vcl/source/filter/jpeg/jpeg.cxx
+++ b/vcl/source/filter/jpeg/jpeg.cxx
@@ -562,6 +562,7 @@ JPEGWriter::JPEGWriter( SvStream& rStm, const uno::Sequence< beans::PropertyValu
FilterConfigItem aConfigItem( (uno::Sequence< beans::PropertyValue >*)pFilterData );
bGreys = aConfigItem.ReadInt32( "ColorMode", 0 ) != 0;
nQuality = aConfigItem.ReadInt32( "Quality", 75 );
+ aChromaSubsampling = aConfigItem.ReadInt32( "ChromaSubsamplingMode", 0 );
if ( pFilterData )
{
@@ -676,7 +677,7 @@ sal_Bool JPEGWriter::Write( const Graphic& rGraphic )
JPEGCallbackStruct aCallbackData;
aCallbackData.xStatusIndicator = xStatusIndicator;
- bRet = (sal_Bool) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), bGreys, nQuality, &aCallbackData );
+ bRet = (sal_Bool) WriteJPEG( this, &rOStm, pAcc->Width(), pAcc->Height(), bGreys, nQuality, aChromaSubsampling, &aCallbackData );
delete[] pBuffer;
pBuffer = NULL;
diff --git a/vcl/source/filter/jpeg/jpeg.h b/vcl/source/filter/jpeg/jpeg.h
index a6b5f0f24c06..cebf81c85f7e 100644
--- a/vcl/source/filter/jpeg/jpeg.h
+++ b/vcl/source/filter/jpeg/jpeg.h
@@ -49,7 +49,7 @@ void JPEGFree( void *ptr );
long JPEGCallback( void* pCallbackData, long nPercent );
long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, long bGreyScale,
- long nQualityPercent, void* pCallbackData );
+ long nQualityPercent, long aChromaSubsampling, void* pCallbackData );
void* GetScanline( void* pJPEGWriter, long nY );
void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines );
diff --git a/vcl/source/filter/jpeg/jpeg.hxx b/vcl/source/filter/jpeg/jpeg.hxx
index bd1adae90957..b77f6c39ac9b 100644
--- a/vcl/source/filter/jpeg/jpeg.hxx
+++ b/vcl/source/filter/jpeg/jpeg.hxx
@@ -71,11 +71,12 @@ class JPEGWriter
SvStream& rOStm;
Bitmap aBmp;
BitmapReadAccess* pAcc;
- sal_uInt8* pBuffer;
- sal_Bool bNative;
+ sal_uInt8* pBuffer;
+ sal_Bool bNative;
sal_Bool bGreys;
sal_Int32 nQuality;
+ sal_Int32 aChromaSubsampling;
bool* pExpWasGrey;
diff --git a/vcl/source/filter/jpeg/jpegc.c b/vcl/source/filter/jpeg/jpegc.c
index 16711d934710..929c2161ed4b 100644
--- a/vcl/source/filter/jpeg/jpegc.c
+++ b/vcl/source/filter/jpeg/jpegc.c
@@ -91,7 +91,7 @@ void ReadJPEG( void* pJPEGReader, void* pIStm, long* pLines )
jpeg_create_decompress( &cinfo );
bDecompCreated = 1;
- jpeg_svstream_src( &cinfo, pIStm );
+ jpeg_svstream_src( &cinfo, pIStm );
jpeg_read_header( &cinfo, sal_True );
cinfo.scale_num = 1;
@@ -215,7 +215,7 @@ Exit:
long WriteJPEG( void* pJPEGWriter, void* pOStm,
long nWidth, long nHeight, long bGreys,
- long nQualityPercent, void* pCallbackData )
+ long nQualityPercent, long aChromaSubsampling, void* pCallbackData )
{
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
@@ -257,6 +257,22 @@ long WriteJPEG( void* pJPEGWriter, void* pOStm,
if ( ( nWidth > 128 ) || ( nHeight > 128 ) )
jpeg_simple_progression( &cinfo );
+ if (aChromaSubsampling == 1) // YUV 4:4:4
+ {
+ cinfo.comp_info[0].h_samp_factor = 1;
+ cinfo.comp_info[0].v_samp_factor = 1;
+ }
+ else if (aChromaSubsampling == 2) // YUV 4:2:2
+ {
+ cinfo.comp_info[0].h_samp_factor = 2;
+ cinfo.comp_info[0].v_samp_factor = 1;
+ }
+ else if (aChromaSubsampling == 3) // YUV 4:2:0
+ {
+ cinfo.comp_info[0].h_samp_factor = 2;
+ cinfo.comp_info[0].v_samp_factor = 2;
+ }
+
jpeg_start_compress( &cinfo, sal_True );
for( nY = 0; nY < nHeight; nY++ )