filter/source/pdf/pdfdecomposer.cxx | 6 +++--- include/vcl/dibtools.hxx | 6 ++++++ include/vcl/filter/PDFiumLibrary.hxx | 6 +++--- include/vcl/pdfread.hxx | 6 +++--- vcl/qa/cppunit/PDFiumLibraryTest.cxx | 4 ++-- vcl/source/bitmap/dibtools.cxx | 14 ++++++++++++++ vcl/source/filter/ipdf/pdfread.cxx | 8 ++++---- vcl/source/gdi/vectorgraphicdata.cxx | 6 +++--- vcl/source/pdf/PDFiumLibrary.cxx | 31 ++++++++++--------------------- 9 files changed, 48 insertions(+), 39 deletions(-)
New commits: commit bc49192b20a04c2695c5277eeb14d288e6542b48 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jul 31 19:47:24 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 1 09:32:03 2025 +0200 BitmapEx->Bitmap in PDFium now that Bitmap can handle transparency Change-Id: Ia2a9d42d195fd9344aa7b8e36da5cc938d8206c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188707 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/filter/source/pdf/pdfdecomposer.cxx b/filter/source/pdf/pdfdecomposer.cxx index 894d0fc89e08..b9de5d4fc940 100644 --- a/filter/source/pdf/pdfdecomposer.cxx +++ b/filter/source/pdf/pdfdecomposer.cxx @@ -72,13 +72,13 @@ XPdfDecomposer::getDecomposition(const uno::Reference<util::XBinaryDataContainer BinaryDataContainer aDataContainer = vcl::convertUnoBinaryDataContainer(xDataContainer); - std::vector<BitmapEx> aBitmaps; + std::vector<Bitmap> aBitmaps; int rv = vcl::RenderPDFBitmaps(aDataContainer.getData(), aDataContainer.getSize(), aBitmaps, nPageIndex, 1); if (rv == 0) return {}; // happens if we do not have PDFium - BitmapEx aReplacement(aBitmaps[0]); + Bitmap aReplacement(aBitmaps[0]); // short form for scale and translate transformation const Size aBitmapSize(aReplacement.GetSizePixel()); @@ -90,7 +90,7 @@ XPdfDecomposer::getDecomposition(const uno::Reference<util::XBinaryDataContainer // create primitive return drawinglayer::primitive2d::Primitive2DContainer{ - new drawinglayer::primitive2d::BitmapPrimitive2D(aReplacement, aBitmapTransform) + new drawinglayer::primitive2d::BitmapPrimitive2D(BitmapEx(aReplacement), aBitmapTransform) } .toSequence(); } diff --git a/include/vcl/dibtools.hxx b/include/vcl/dibtools.hxx index 3e45b206c1c5..e3d6b89ec29b 100644 --- a/include/vcl/dibtools.hxx +++ b/include/vcl/dibtools.hxx @@ -66,6 +66,12 @@ bool VCL_DLLPUBLIC ReadRawDIB( const ScanlineFormat nFormat, const int nHeight, const int nStride); +bool VCL_DLLPUBLIC ReadRawDIB( + Bitmap& rTarget, + const unsigned char* pBuf, + const ScanlineFormat nFormat, + const int nHeight, + const int nStride); bool VCL_DLLPUBLIC WriteDIB( diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index efa4cd516674..073cf88b42d3 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -37,7 +37,7 @@ #include <vcl/pdf/PDFAnnotAActionType.hxx> class SvMemoryStream; -class BitmapEx; +class Bitmap; namespace vcl::pdf { @@ -83,8 +83,8 @@ public: virtual int getWidth() = 0; virtual int getHeight() = 0; virtual PDFBitmapType getFormat() = 0; - /// Convert the bitmap buffer to a BitmapEx - virtual BitmapEx createBitmapFromBuffer() = 0; + /// Convert the bitmap buffer to a Bitmap + virtual Bitmap createBitmapFromBuffer() = 0; }; class VCL_DLLPUBLIC PDFiumAnnotation diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index 73bb0a8a05a4..390ab675c065 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -25,9 +25,9 @@ namespace vcl { /// Fills the rBitmaps vector with rendered pages. -VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, - std::vector<BitmapEx>& rBitmaps, size_t nFirstPage = 0, - int nPages = 1, const basegfx::B2DTuple* pSizeHint = nullptr); +VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBitmaps, + size_t nFirstPage = 0, int nPages = 1, + const basegfx::B2DTuple* pSizeHint = nullptr); VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex, diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index c1ace4a1568c..50f47695c3b7 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -283,13 +283,13 @@ CPPUNIT_TEST_FIXTURE(PDFiumLibraryTest, testFormFields) aMemory.Seek(0); // When rendering its first (and only) page to a bitmap: - std::vector<BitmapEx> aBitmaps; + std::vector<Bitmap> aBitmaps; int nRet = vcl::RenderPDFBitmaps(aMemory.GetData(), aMemory.GetSize(), aBitmaps); CPPUNIT_ASSERT(nRet); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aBitmaps.size()); // Then make sure the bitmap contains that text: - Bitmap aBitmap = aBitmaps[0].GetBitmap(); + Bitmap aBitmap = aBitmaps[0]; BitmapReadAccess aAccess(aBitmap); Size aSize = aBitmap.GetSizePixel(); std::set<sal_uInt32> aColors; diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx index ee23e47b7a39..8e8093473fa6 100644 --- a/vcl/source/bitmap/dibtools.cxx +++ b/vcl/source/bitmap/dibtools.cxx @@ -1781,6 +1781,20 @@ bool ReadRawDIB( return true; } +bool ReadRawDIB( + Bitmap& rTarget, + const unsigned char* pBuf, + const ScanlineFormat nFormat, + const int nHeight, + const int nStride) +{ + BitmapEx aTmp; + bool bRet = ReadRawDIB(aTmp, pBuf, nFormat, nHeight, nStride); + if (bRet) + rTarget = Bitmap(aTmp); + return bRet; +} + bool WriteDIB( const Bitmap& rSource, SvStream& rOStm, diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 74df41923217..10a46e70228e 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -24,7 +24,7 @@ using namespace com::sun::star; namespace vcl { -size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<BitmapEx>& rBitmaps, +size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBitmaps, const size_t nFirstPage, int nPages, const basegfx::B2DTuple* pSizeHint) { auto pPdfium = vcl::pdf::PDFiumLibrary::get(); @@ -86,15 +86,15 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<BitmapEx>& r pPdfBitmap->fillRect(0, 0, nPageWidth, nPageHeight, nColor); pPdfBitmap->renderPageBitmap(pPdfDocument.get(), pPdfPage.get(), /*nStartX=*/0, /*nStartY=*/0, nPageWidth, nPageHeight); - BitmapEx aBitmapEx = pPdfBitmap->createBitmapFromBuffer(); + Bitmap aBitmap = pPdfBitmap->createBitmapFromBuffer(); if (bTransparent) { - rBitmaps.emplace_back(std::move(aBitmapEx)); + rBitmaps.emplace_back(std::move(aBitmap)); } else { - rBitmaps.emplace_back(aBitmapEx.GetBitmap()); + rBitmaps.emplace_back(BitmapEx(aBitmap).GetBitmap()); } } diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index 68245fe25acd..9388049e8e98 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -151,7 +151,7 @@ void VectorGraphicData::ensurePdfReplacement() return; // nothing to do // use PDFium directly - std::vector<BitmapEx> aBitmaps; + std::vector<Bitmap> aBitmaps; sal_Int32 nUsePageIndex = 0; if (mnPageIndex >= 0) nUsePageIndex = mnPageIndex; @@ -196,11 +196,11 @@ BitmapEx VectorGraphicData::getBitmap(const Size& pixelSize) const basegfx::B2DTuple sizeMM100( o3tl::convert(pixelSize.Width() / dpi / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR, o3tl::Length::in, o3tl::Length::mm100), o3tl::convert(pixelSize.Height() / dpi / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR, o3tl::Length::in, o3tl::Length::mm100)); - std::vector<BitmapEx> aBitmaps; + std::vector<Bitmap> aBitmaps; vcl::RenderPDFBitmaps(maDataContainer.getData(), maDataContainer.getSize(), aBitmaps, nUsePageIndex, 1, &sizeMM100); if (!aBitmaps.empty()) - return aBitmaps[0]; + return BitmapEx(aBitmaps[0]); } if (getPrimitive2DSequence().empty()) diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 4ca6fb3c1bd6..04359dd1cad5 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -279,7 +279,7 @@ public: int getWidth() override; int getHeight() override; PDFBitmapType getFormat() override; - BitmapEx createBitmapFromBuffer() override; + Bitmap createBitmapFromBuffer() override; }; class PDFiumPathSegmentImpl final : public PDFiumPathSegment @@ -1317,13 +1317,13 @@ PDFBitmapType PDFiumBitmapImpl::getFormat() return static_cast<PDFBitmapType>(FPDFBitmap_GetFormat(mpBitmap)); } -BitmapEx PDFiumBitmapImpl::createBitmapFromBuffer() +Bitmap PDFiumBitmapImpl::createBitmapFromBuffer() { - BitmapEx aBitmapEx; + Bitmap aBitmap; const vcl::pdf::PDFBitmapType eFormat = getFormat(); if (eFormat == vcl::pdf::PDFBitmapType::Unknown) - return aBitmapEx; + return aBitmap; const int nWidth = getWidth(); const int nHeight = getHeight(); @@ -1333,41 +1333,30 @@ BitmapEx PDFiumBitmapImpl::createBitmapFromBuffer() { case vcl::pdf::PDFBitmapType::BGR: { - aBitmapEx = BitmapEx(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); - ReadRawDIB(aBitmapEx, getBuffer(), ScanlineFormat::N24BitTcBgr, nHeight, nStride); + aBitmap = Bitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + ReadRawDIB(aBitmap, getBuffer(), ScanlineFormat::N24BitTcBgr, nHeight, nStride); } break; case vcl::pdf::PDFBitmapType::BGRx: { - aBitmapEx = BitmapEx(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); - ReadRawDIB(aBitmapEx, getBuffer(), ScanlineFormat::N32BitTcRgba, nHeight, nStride); + aBitmap = Bitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + ReadRawDIB(aBitmap, getBuffer(), ScanlineFormat::N32BitTcRgbx, nHeight, nStride); } break; case vcl::pdf::PDFBitmapType::BGRA: { - Bitmap aBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); - AlphaMask aMask(Size(nWidth, nHeight)); + aBitmap = Bitmap(Size(nWidth, nHeight), vcl::PixelFormat::N32_BPP); { BitmapScopedWriteAccess pWriteAccess(aBitmap); - BitmapScopedWriteAccess pMaskAccess(aMask); ConstScanline pBuffer = getBuffer(); - std::vector<sal_uInt8> aScanlineAlpha(nWidth); for (int nRow = 0; nRow < nHeight; ++nRow) { ConstScanline pLine = pBuffer + (nStride * nRow); pWriteAccess->CopyScanline(nRow, pLine, ScanlineFormat::N32BitTcBgra, nStride); - for (int nCol = 0; nCol < nWidth; ++nCol) - { - aScanlineAlpha[nCol] = pLine[3]; - pLine += 4; - } - pMaskAccess->CopyScanline(nRow, aScanlineAlpha.data(), ScanlineFormat::N8BitPal, - nWidth); } } - aBitmapEx = BitmapEx(aBitmap, aMask); } break; @@ -1375,7 +1364,7 @@ BitmapEx PDFiumBitmapImpl::createBitmapFromBuffer() break; } - return aBitmapEx; + return aBitmap; } PDFiumAnnotationImpl::PDFiumAnnotationImpl(FPDF_ANNOTATION pAnnotation)