summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/graphicfilter.hxx4
-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
4 files changed, 40 insertions, 6 deletions
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 d36ab2844f17..c5345aaec977 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