summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-09 22:16:05 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-04 12:36:28 -0400
commitc7b6966a4006af40042383ae3241f3bc8f9c5af5 (patch)
tree3b256070539076ea78739ac2efbfcf6d83dfed4e
parentbc4f79efb550b9941af8852f869899a4639dd294 (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 (cherry picked from commit 5ca54d5fa9fec264431d5d1f712b351b4b199fd6)
-rw-r--r--external/pdfium/edit.patch.145
-rw-r--r--svx/source/svdraw/svdpdf.cxx7
2 files changed, 48 insertions, 4 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 713e80efb0be..111fc6461094 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1032,7 +1032,7 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject)
SAL_WARN("sd.filter", "Got TEXT bounds left: " << left << ", right: " << right
<< ", top: " << top << ", bottom: " << bottom);
- Rectangle aRect = PointsToLogic(left, right, top, bottom);
+ tools::Rectangle aRect = PointsToLogic(left, right, top, bottom);
double dFontScale = 1.0;
geometry::Matrix2D aMatrix;
@@ -1163,8 +1163,7 @@ void ImpSdrPdfImport::MapScaling()
void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject)
{
SAL_WARN("sd.filter", "Got page object IMAGE");
- std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter> bitmap(
- FPDFImageObj_GetBitmap(pPageObject));
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap(FPDFImageObj_GetBitmapBgra(pPageObject));
if (!bitmap)
{
SAL_WARN("sd.filter", "Failed to get IMAGE");
@@ -1202,7 +1201,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