[Libreoffice-commits] core.git: include/vcl vcl/qa vcl/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Jun 5 17:55:45 UTC 2018
include/vcl/graphicfilter.hxx | 4 ++++
vcl/qa/cppunit/jpeg/JpegReaderTest.cxx | 31 +++++++++++++++++++++++++------
vcl/source/filter/graphicfilter2.cxx | 2 ++
vcl/source/gdi/pdfextoutdevdata.cxx | 9 +++++++++
4 files changed, 40 insertions(+), 6 deletions(-)
New commits:
commit 70537c8295f1b0a0c58b061dfca6cbc9def0d65b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Jun 5 17:43:33 2018 +0200
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.
Change-Id: I76b44b910948467aeb1f15e5ae765201d183c99d
Reviewed-on: https://gerrit.libreoffice.org/55343
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx
index adf308914837..2f24cf10e085 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -144,6 +144,7 @@ class VCL_DLLPUBLIC GraphicDescriptor final
sal_uInt16 nPlanes;
GraphicFileFormat nFormat;
bool bOwnStream;
+ sal_uInt8 mnNumberOfImageComponents;
void ImpConstruct();
@@ -210,6 +211,9 @@ public:
/** @return bits/pixel or 0 **/
sal_uInt16 GetBitsPerPixel() const { return nBitsPerPixel; }
+ /** @return number of color channels */
+ sal_uInt8 GetNumberOfImageComponents() const { return mnNumberOfImageComponents; }
+
/** @return filter number that is needed by the GraphFilter to read this format */
static OUString GetImportFormatShortName( GraphicFileFormat nFormat );
};
diff --git a/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
index 4cae79645bd6..f9a780187d51 100644
--- a/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
+++ b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
@@ -23,7 +23,7 @@ class JpegReaderTest : public test::BootstrapFixtureBase
return m_directories.getURLFromSrc(maDataUrl) + sFileName;
}
- Bitmap loadJPG(const OUString& aURL);
+ Graphic loadJPG(const OUString& aURL);
public:
JpegReaderTest() :
@@ -92,19 +92,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.GetGfxLink();
+ 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());
@@ -114,11 +125,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());
@@ -130,11 +144,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());
@@ -144,6 +161,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 4439c2ab8b50..d0bf0517cd8c 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 aa9ee14466c1..7e0f06c8deb9 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>
@@ -839,6 +840,14 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
if (rGraphic.GetGfxLink().GetDataSize() == 0)
return false;
+ GfxLink aLink = rGraphic.GetGfxLink();
+ 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
More information about the Libreoffice-commits
mailing list