summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-06-05 17:43:33 +0200
committerAndras Timar <andras.timar@collabora.com>2018-06-27 06:40:25 +0200
commitbc639b009c5f967eaf4ff8d142db95ccf76c4821 (patch)
tree0b787d2b6e025ad868b753bb87bd40e86c62dbfe /vcl
parent566296904f547ae51fdf6148cd3861a918ecd9fe (diff)
tdf#102928 PDF export: do recompress CMYK images
The export filter writes /DeviceRGB unconditionally, so for now don't optimize CMYK image handling here. Though the added GraphicDescriptor API allows supporting this natively in the export filter in the future. (cherry picked from commit 70537c8295f1b0a0c58b061dfca6cbc9def0d65b) Change-Id: I76b44b910948467aeb1f15e5ae765201d183c99d Reviewed-on: https://gerrit.libreoffice.org/55378 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 4aaf958cdad2a19be49dbd5f9ca661753f8a94ab)
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/jpeg/JpegReaderTest.cxx31
-rw-r--r--vcl/source/filter/graphicfilter2.cxx2
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx9
3 files changed, 36 insertions, 6 deletions
diff --git a/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
index 024316c9e739..3d427da1c323 100644
--- a/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
+++ b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
@@ -22,7 +22,7 @@ class JpegReaderTest : public test::BootstrapFixtureBase
return m_directories.getURLFromSrc(maDataUrl) + sFileName;
}
- Bitmap loadJPG(const OUString& aURL);
+ Graphic loadJPG(const OUString& aURL);
public:
JpegReaderTest() :
@@ -91,19 +91,30 @@ bool checkRect(Bitmap& rBitmap, int aLayerNumber, long nAreaHeight, long nAreaWi
return true;
}
-Bitmap JpegReaderTest::loadJPG(const OUString& aURL)
+int getNumberOfImageComponents(const Graphic& rGraphic)
+{
+ GfxLink aLink = rGraphic.GetLink();
+ SvMemoryStream aMemoryStream(const_cast<sal_uInt8*>(aLink.GetData()), aLink.GetDataSize(),
+ StreamMode::READ | StreamMode::WRITE);
+ GraphicDescriptor aDescriptor(aMemoryStream, nullptr);
+ CPPUNIT_ASSERT(aDescriptor.Detect(true));
+ return aDescriptor.GetNumberOfImageComponents();
+}
+
+Graphic JpegReaderTest::loadJPG(const OUString& aURL)
{
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
Graphic aGraphic;
SvFileStream aFileStream(aURL, StreamMode::READ);
ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
- return aGraphic.GetBitmapEx().GetBitmap();
+ return aGraphic;
}
void JpegReaderTest::testReadRGB()
{
- Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestRGB.jpeg"));
+ Graphic aGraphic = loadJPG(getFullUrl("JPEGTestRGB.jpeg"));
+ Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
Size aSize = aBitmap.GetSizePixel();
CPPUNIT_ASSERT_EQUAL(12L, aSize.Width());
CPPUNIT_ASSERT_EQUAL(12L, aSize.Height());
@@ -113,11 +124,14 @@ void JpegReaderTest::testReadRGB()
CPPUNIT_ASSERT(checkRect(aBitmap, 1, 8, 8, Color(0xff, 0x00, 0x00), nMaxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 2, 8, 8, Color(0x00, 0xff, 0x00), nMaxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 3, 8, 8, Color(0x00, 0x00, 0xff), nMaxDelta));
+
+ CPPUNIT_ASSERT_EQUAL(3, getNumberOfImageComponents(aGraphic));
}
void JpegReaderTest::testReadGray()
{
- Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestGray.jpeg"));
+ Graphic aGraphic = loadJPG(getFullUrl("JPEGTestGray.jpeg"));
+ Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
Size aSize = aBitmap.GetSizePixel();
CPPUNIT_ASSERT_EQUAL(12L, aSize.Width());
CPPUNIT_ASSERT_EQUAL(12L, aSize.Height());
@@ -129,11 +143,14 @@ void JpegReaderTest::testReadGray()
CPPUNIT_ASSERT(checkRect(aBitmap, 1, 8, 8, Color(0x36, 0x36, 0x36), nMaxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 2, 8, 8, Color(0xb6, 0xb6, 0xb6), nMaxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 3, 8, 8, Color(0x12, 0x12, 0x12), nMaxDelta));
+
+ CPPUNIT_ASSERT_EQUAL(1, getNumberOfImageComponents(aGraphic));
}
void JpegReaderTest::testReadCMYK()
{
- Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestCMYK.jpeg"));
+ Graphic aGraphic = loadJPG(getFullUrl("JPEGTestCMYK.jpeg"));
+ Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
Size aSize = aBitmap.GetSizePixel();
CPPUNIT_ASSERT_EQUAL(12L, aSize.Width());
CPPUNIT_ASSERT_EQUAL(12L, aSize.Height());
@@ -143,6 +160,8 @@ void JpegReaderTest::testReadCMYK()
CPPUNIT_ASSERT(checkRect(aBitmap, 1, 8, 8, Color(0xff, 0x00, 0x00), maxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 2, 8, 8, Color(0x00, 0xff, 0x00), maxDelta));
CPPUNIT_ASSERT(checkRect(aBitmap, 3, 8, 8, Color(0x00, 0x00, 0xff), maxDelta));
+
+ CPPUNIT_ASSERT_EQUAL(4, getNumberOfImageComponents(aGraphic));
}
CPPUNIT_TEST_SUITE_REGISTRATION(JpegReaderTest);
diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx
index ae181f4269b6..a5635563c4e4 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -96,6 +96,7 @@ void GraphicDescriptor::ImpConstruct()
nFormat = GraphicFileFormat::NOT;
nBitsPerPixel = 0;
nPlanes = 0;
+ mnNumberOfImageComponents = 0;
}
bool GraphicDescriptor::ImpDetectBMP( SvStream& rStm, bool bExtendedInfo )
@@ -371,6 +372,7 @@ bool GraphicDescriptor::ImpDetectJPG( SvStream& rStm, bool bExtendedInfo )
.ReadUChar( nComponentsIdentifier )
.ReadUChar( nSamplingFactor )
.ReadUChar( nQuantizationTableDestinationSelector );
+ mnNumberOfImageComponents = nNumberOfImageComponents;
// nSamplingFactor (lower nibble: vertical,
// upper nibble: horizontal) is unused
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 8543da75db9a..d74996ce2403 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -23,6 +23,7 @@
#include <vcl/gfxlink.hxx>
#include <vcl/dllapi.h>
#include <vcl/metaact.hxx>
+#include <vcl/graphicfilter.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
@@ -837,6 +838,14 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
if (rGraphic.GetLink().GetDataSize() == 0)
return false;
+ GfxLink aLink = rGraphic.GetLink();
+ SvMemoryStream aMemoryStream(const_cast<sal_uInt8*>(aLink.GetData()), aLink.GetDataSize(),
+ StreamMode::READ | StreamMode::WRITE);
+ GraphicDescriptor aDescriptor(aMemoryStream, nullptr);
+ if (aDescriptor.Detect(true) && aDescriptor.GetNumberOfImageComponents() == 4)
+ // 4 means CMYK, which is not handled.
+ return false;
+
Size aSize = rGraphic.GetSizePixel();
// small items better off as PNG anyway