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 2c9ad85b96a0..d84ae3f0a9fa 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -142,6 +142,7 @@ class VCL_DLLPUBLIC GraphicDescriptor final
sal_uInt16 nPlanes;
GraphicFileFormat nFormat;
bool bOwnStream;
+ sal_uInt8 mnNumberOfImageComponents;
void ImpConstruct();
@@ -208,6 +209,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 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