diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-04-09 22:16:05 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-05-22 12:17:13 +0200 |
commit | 5ca54d5fa9fec264431d5d1f712b351b4b199fd6 (patch) | |
tree | 3471480e4a541a900449d431d3432451a576b7b6 | |
parent | e84047e4ebce65ae7b7fc3ebf1f6897aaa332650 (diff) |
svx: import PDF images as BGRA
This makes it trivial to support all sort of
odd bit-format and 8-bit paletted images.
Change-Id: I4555794eccd0ee2906f9a39bd93957ad3775432c
-rw-r--r-- | external/pdfium/edit.patch.1 | 45 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 4 |
2 files changed, 47 insertions, 2 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1 index b7cd86e5ff2d..da72f96f46fc 100644 --- a/external/pdfium/edit.patch.1 +++ b/external/pdfium/edit.patch.1 @@ -34,6 +34,37 @@ index 0a01ae0..fad2920 100644 if (bPattern) { DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size, &text_matrix, bFill, bStroke); +diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp +index 0d7ba56..37bdf99 100644 +--- a/fpdfsdk/fpdfeditimg.cpp ++++ b/fpdfsdk/fpdfeditimg.cpp +@@ -167,6 +167,26 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) { + return pBitmap.Leak(); + } + ++FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV ++FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object) { ++ CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object); ++ if (!pObj || !pObj->IsImage()) ++ return nullptr; ++ ++ RetainPtr<CPDF_Image> pImg = pObj->AsImage()->GetImage(); ++ if (!pImg) ++ return nullptr; ++ ++ RetainPtr<CFX_DIBSource> pSource = pImg->LoadDIBSource(); ++ if (!pSource) ++ return nullptr; ++ ++ RetainPtr<CFX_DIBitmap> pBitmap; ++ pBitmap = pSource->CloneConvert(FXDIB_Argb); ++ ++ return pBitmap.Leak(); ++} ++ + FPDF_EXPORT unsigned long FPDF_CALLCONV + FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, + void* buffer, diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index ca2cf3f..ac36788 100644 --- a/fpdfsdk/fpdfeditpage.cpp @@ -283,3 +314,17 @@ index 043dc16..fe3b971 100644 // Function: FPDFLink_LoadWebLinks // Prepare information about weblinks in a page. // Parameters: +diff --git a/public/fpdfview.h b/public/fpdfview.h +index 35e87ae..80ab0ad 100644 +--- a/public/fpdfview.h ++++ b/public/fpdfview.h +@@ -908,6 +908,9 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width, + // function; see the list of such formats above. + FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap); + ++FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV ++FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object); ++ + // Function: FPDFBitmap_FillRect + // Fill a rectangle in a bitmap. + // Parameters: diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 9bbaf90e8861..98bb79d3dd54 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -1156,7 +1156,7 @@ void ImpSdrPdfImport::MapScaling() void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject) { SAL_WARN("sd.filter", "Got page object IMAGE"); - std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmap(pPageObject)); + std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject)); if (!bitmap) { SAL_WARN("sd.filter", "Failed to get IMAGE"); @@ -1194,7 +1194,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject) SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight << ", stride: " << nStride << ", format: BGRx"); - ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight, nStride); + ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcRgba, nHeight, nStride); break; case FPDFBitmap_BGRA: SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth << ", height: " << nHeight |