sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf |binary sd/qa/unit/export-tests.cxx | 36 +++++++++++++++ svx/source/svdraw/svdpdf.cxx | 12 ++++- 3 files changed, 47 insertions(+), 1 deletion(-)
New commits: commit cd9d62d3c90ef28112eca71c5d8c51c0adefc5d7 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Oct 1 12:00:14 2025 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Oct 3 08:18:42 2025 +0200 support 8 bit grayscale pdf images too resolves mystery black rectangle in source pdf Change-Id: I9abd0c1698b54133cefc710a18197ace1ba6436a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191721 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf b/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf new file mode 100644 index 000000000000..acaf227710c0 Binary files /dev/null and b/sd/qa/unit/data/pdf/GrayscaleImageUnderInvisibleTest.pdf differ diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 2440e427c4e5..cf6a2a27ab0b 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -1127,6 +1127,42 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfHindi) "style:text-properties[@fo:font-family='AcademyEngravedLetPlain']"); } +CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfGrayscaleImageUnderInvisibleTest) +{ + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); + if (!pPdfium) + return; + UsePdfium aGuard; + + loadFromFile(u"pdf/GrayscaleImageUnderInvisibleTest.pdf"); + + setFilterOptions("{\"DecomposePDF\":{\"type\":\"boolean\",\"value\":\"true\"}}"); + saveAndReload(u"OpenDocument Drawing Flat XML"_ustr); + + uno::Reference<drawing::XShapes> xGroupShape(getShapeFromPage(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xGroupShape.is()); + + // first shape in the group is the picture + uno::Reference<beans::XPropertySet> xShape(xGroupShape->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShape.is()); + + uno::Reference<graphic::XGraphic> xGraphic; + xShape->getPropertyValue(u"Graphic"_ustr) >>= xGraphic; + CPPUNIT_ASSERT(xGraphic.is()); + + Graphic aGraphic(xGraphic); + BitmapEx aBitmap(aGraphic.GetBitmapEx()); + CPPUNIT_ASSERT_EQUAL(tools::Long(2582), aBitmap.GetSizePixel().Width()); + CPPUNIT_ASSERT_EQUAL(tools::Long(3325), aBitmap.GetSizePixel().Height()); + + Color aExpectedColor(ColorAlphaTag::ColorAlpha, 0xFFFFFFFF); + + // Without the fix in place, this test would have failed with + // - Expected: rgba[ffffffff] + // - Actual : rgba[000000ff] + CPPUNIT_ASSERT_EQUAL(aExpectedColor, aBitmap.GetPixelColor(5, 5)); +} + CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedText) { createSdDrawDoc("objectwithtext.fodg"); diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 4be6019f1e26..1ce55a13969f 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -1834,6 +1834,13 @@ void ImpSdrPdfImport::MapScaling() mnMapScalingOfs = nCount; } +static BitmapEx createBitmap(const Size& rSize, bool bGrayScale) +{ + if (bGrayScale) + return BitmapEx(Bitmap(rSize, vcl::PixelFormat::N8_BPP, &Bitmap::GetGreyPalette(256))); + return BitmapEx(rSize, vcl::PixelFormat::N24_BPP); +} + void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, int /*nPageObjectIndex*/) { @@ -1855,10 +1862,13 @@ void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> co const int nWidth = bitmap->getWidth(); const int nHeight = bitmap->getHeight(); const int nStride = bitmap->getStride(); - BitmapEx aBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + BitmapEx aBitmap(createBitmap(Size(nWidth, nHeight), format == vcl::pdf::PDFBitmapType::Gray)); switch (format) { + case vcl::pdf::PDFBitmapType::Gray: + ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N8BitPal, nHeight, nStride); + break; case vcl::pdf::PDFBitmapType::BGR: ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight, nStride); break;
