diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-12-02 09:08:49 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-12-02 10:14:27 +0100 |
commit | d8fe51f9a4d1669578c162d87a6e65125096d720 (patch) | |
tree | 108dba7e03750313851dcbb771ec94178b7d35c5 | |
parent | ea9863c0104bfa74e7542f850768c2c0ee63a577 (diff) |
pdfium: add width/height/format wrappers for bitmap
Change-Id: Ic8c85c4224b89d1e7bb8ded1a11c5fd8139f5701
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107044
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | include/vcl/filter/PDFiumLibrary.hxx | 4 | ||||
-rw-r--r-- | include/vcl/pdf/PDFBitmapType.hxx | 26 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 21 | ||||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 12 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 20 |
5 files changed, 66 insertions, 17 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 497ef3e2d47e..6e952d4fc17b 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -32,6 +32,7 @@ #include <vcl/pdf/PDFAnnotationSubType.hxx> #include <vcl/pdf/PDFPageObjectType.hxx> #include <vcl/pdf/PDFSegmentType.hxx> +#include <vcl/pdf/PDFBitmapType.hxx> #include <fpdf_doc.h> @@ -85,6 +86,9 @@ public: void renderPageBitmap(PDFiumPage* pPage, int nStartX, int nStartY, int nSizeX, int nSizeY); ConstScanline getBuffer(); int getStride(); + int getWidth(); + int getHeight(); + PDFBitmapType getFormat(); }; class VCL_DLLPUBLIC PDFiumAnnotation final diff --git a/include/vcl/pdf/PDFBitmapType.hxx b/include/vcl/pdf/PDFBitmapType.hxx new file mode 100644 index 000000000000..fe5921276e87 --- /dev/null +++ b/include/vcl/pdf/PDFBitmapType.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +namespace vcl::pdf +{ +enum class PDFBitmapType +{ + Unknown = 0, + Gray = 1, + BGR = 2, + BGRx = 3, + BGRA = 4, +}; + +} // namespace vcl::pdf + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 47ea46c62801..6f2f1de42f72 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -883,35 +883,34 @@ void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> co return; } - const int format = FPDFBitmap_GetFormat(bitmap->getPointer()); - if (format == FPDFBitmap_Unknown) + const vcl::pdf::PDFBitmapType format = bitmap->getFormat(); + if (format == vcl::pdf::PDFBitmapType::Unknown) { SAL_WARN("sd.filter", "Failed to get IMAGE format"); return; } - const unsigned char* pBuf - = static_cast<const unsigned char*>(FPDFBitmap_GetBuffer(bitmap->getPointer())); - const int nWidth = FPDFBitmap_GetWidth(bitmap->getPointer()); - const int nHeight = FPDFBitmap_GetHeight(bitmap->getPointer()); - const int nStride = FPDFBitmap_GetStride(bitmap->getPointer()); + const unsigned char* pBuf = bitmap->getBuffer(); + const int nWidth = bitmap->getWidth(); + const int nHeight = bitmap->getHeight(); + const int nStride = bitmap->getStride(); BitmapEx aBitmap(Size(nWidth, nHeight), 24); switch (format) { - case FPDFBitmap_BGR: + case vcl::pdf::PDFBitmapType::BGR: ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight, nStride); break; - case FPDFBitmap_BGRx: + case vcl::pdf::PDFBitmapType::BGRx: ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcRgba, nHeight, nStride); break; - case FPDFBitmap_BGRA: + case vcl::pdf::PDFBitmapType::BGRA: ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight, nStride); break; default: SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight << ", stride: " << nStride - << ", format: " << format); + << ", format: " << static_cast<int>(format)); break; } diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index eaf905986928..7af85573be40 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -1503,8 +1503,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf128630) std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap(); CPPUNIT_ASSERT(pBitmap); - int nWidth = FPDFBitmap_GetWidth(pBitmap->getPointer()); - int nHeight = FPDFBitmap_GetHeight(pBitmap->getPointer()); + int nWidth = pBitmap->getWidth(); + int nHeight = pBitmap->getHeight(); // Without the accompanying fix in place, this test would have failed with: // assertion failed // - Expression: nWidth != nHeight @@ -1845,8 +1845,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceSmallImage) // Make sure we don't scale down a tiny bitmap. std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap(); CPPUNIT_ASSERT(pBitmap); - int nWidth = FPDFBitmap_GetWidth(pBitmap->getPointer()); - int nHeight = FPDFBitmap_GetHeight(pBitmap->getPointer()); + int nWidth = pBitmap->getWidth(); + int nHeight = pBitmap->getHeight(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 16 // - Actual : 6 @@ -1900,8 +1900,8 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testReduceImage) // Make sure we don't scale down a bitmap. std::unique_ptr<vcl::pdf::PDFiumBitmap> pBitmap = pPageObject->getImageBitmap(); CPPUNIT_ASSERT(pBitmap); - int nWidth = FPDFBitmap_GetWidth(pBitmap->getPointer()); - int nHeight = FPDFBitmap_GetHeight(pBitmap->getPointer()); + int nWidth = pBitmap->getWidth(); + int nHeight = pBitmap->getHeight(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 160 // - Actual : 6 diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 0952c9a5d3e8..00a3167bfa36 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -51,6 +51,17 @@ static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Bezierto) == FPDF_SEGME static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Moveto) == FPDF_SEGMENT_MOVETO, "PDFSegmentType::Moveto value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFBitmapType::Unknown) == FPDFBitmap_Unknown, + "PDFBitmapType::Unknown value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFBitmapType::Gray) == FPDFBitmap_Gray, + "PDFBitmapType::Gray value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFBitmapType::BGR) == FPDFBitmap_BGR, + "PDFBitmapType::BGR value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFBitmapType::BGRx) == FPDFBitmap_BGRx, + "PDFBitmapType::BGRx value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFBitmapType::BGRA) == FPDFBitmap_BGRA, + "PDFBitmapType::BGRA value mismatch"); + namespace { /// Callback class to be used with FPDF_SaveWithVersion(). @@ -650,6 +661,15 @@ ConstScanline PDFiumBitmap::getBuffer() int PDFiumBitmap::getStride() { return FPDFBitmap_GetStride(mpBitmap); } +int PDFiumBitmap::getWidth() { return FPDFBitmap_GetWidth(mpBitmap); } + +int PDFiumBitmap::getHeight() { return FPDFBitmap_GetHeight(mpBitmap); } + +PDFBitmapType PDFiumBitmap::getFormat() +{ + return static_cast<PDFBitmapType>(FPDFBitmap_GetFormat(mpBitmap)); +} + PDFiumAnnotation::PDFiumAnnotation(FPDF_ANNOTATION pAnnotation) : mpAnnotation(pAnnotation) { |