summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-07 19:00:32 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-04 12:36:28 -0400
commita60a959a6bd6d0c5a24a055d2e9809db557a675f (patch)
tree4bd4cf58fd8e78ee6c3e67c6818416d031fe20da
parent54c3ff15be8eef2fef8f2c41a397fa9fd3cf109b (diff)
svx: support importing PDF images
(cherry picked from commit 6e00acca4ffe130f41d19313e5b310ae6da6358d) Change-Id: Id4524a30b8f9fa4228c4acb4bf8714700da3017c
-rw-r--r--include/vcl/dibtools.hxx8
-rw-r--r--svx/source/svdraw/svdpdf.cxx83
-rw-r--r--vcl/source/gdi/dibtools.cxx16
3 files changed, 106 insertions, 1 deletions
diff --git a/include/vcl/dibtools.hxx b/include/vcl/dibtools.hxx
index dca6730c88b6..9aa9ac5f4203 100644
--- a/include/vcl/dibtools.hxx
+++ b/include/vcl/dibtools.hxx
@@ -23,6 +23,7 @@
#include <vcl/mapmod.hxx>
#include <vcl/region.hxx>
#include <vcl/alpha.hxx>
+#include <vcl/salbtype.hxx>
// predefines
@@ -55,6 +56,13 @@ bool VCL_DLLPUBLIC ReadDIBV5(
AlphaMask& rTargetAlpha,
SvStream& rIStm);
+bool VCL_DLLPUBLIC ReadRawDIB(
+ Bitmap& rTarget,
+ const unsigned char* pBuf,
+ const ScanlineFormat nFormat,
+ const int nHeight,
+ const int nStride);
+
bool VCL_DLLPUBLIC WriteDIB(
const Bitmap& rSource,
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 265f185c15dc..cd5595104ea8 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -86,9 +86,16 @@
#include <svx/svdogrp.hxx>
#include <vcl/BitmapTools.hxx>
#include <com/sun/star/geometry/Matrix2D.hpp>
+#include <vcl/dibtools.hxx>
+#include <com/sun/star/geometry/Matrix2D.hpp>
using namespace com::sun::star;
+struct FPDFBitmapDeleter
+{
+ inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
+};
+
ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools::Rectangle& rRect,
const std::shared_ptr<uno::Sequence<sal_Int8>>& pPdfData)
: maTmpList()
@@ -213,8 +220,82 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc
SAL_WARN("sd.filter", "Got page object PATH");
break;
case FPDF_PAGEOBJ_IMAGE:
+ {
SAL_WARN("sd.filter", "Got page object IMAGE");
- break;
+ std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter>
+ bitmap(FPDFImageObj_GetBitmap(pPageObject));
+ if (!bitmap)
+ {
+ SAL_WARN("sd.filter", "Failed to get IMAGE");
+ continue;
+ }
+
+ const int format = FPDFBitmap_GetFormat(bitmap.get());
+ if (format == FPDFBitmap_Unknown)
+ {
+ SAL_WARN("sd.filter", "Failed to get IMAGE format");
+ continue;
+ }
+
+ const unsigned char* pBuf
+ = static_cast<const unsigned char*>(FPDFBitmap_GetBuffer(bitmap.get()));
+ const int nWidth = FPDFBitmap_GetWidth(bitmap.get());
+ const int nHeight = FPDFBitmap_GetHeight(bitmap.get());
+ const int nStride = FPDFBitmap_GetStride(bitmap.get());
+ Bitmap aBitmap(Size(nWidth, nHeight), 24);
+
+ switch (format)
+ {
+ case FPDFBitmap_Gray:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
+ << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: Gray");
+ ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N8BitTcMask, nHeight,
+ nStride);
+ break;
+ case FPDFBitmap_BGR:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
+ << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: BGR");
+ ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N24BitTcBgr, nHeight,
+ nStride);
+ break;
+ case FPDFBitmap_BGRx:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
+ << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: BGRx");
+ ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight,
+ nStride);
+ break;
+ case FPDFBitmap_BGRA:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
+ << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: BGRA");
+ ReadRawDIB(aBitmap, pBuf, ScanlineFormat::N32BitTcBgra, nHeight,
+ nStride);
+ break;
+ default:
+ SAL_WARN("sd.filter", "Got IMAGE width: " << nWidth
+ << ", height: " << nHeight
+ << ", stride: " << nStride
+ << ", format: " << format);
+ break;
+ }
+
+ tools::Rectangle aRect(Point(0, 0), Size(nWidth, nHeight));
+ // aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
+ SdrGrafObj* pGraf = new SdrGrafObj(*mpModel, Graphic(aBitmap), aRect);
+
+ // This action is not creating line and fill, set directly, do not use SetAttributes(..)
+ pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
+ pGraf->SetMergedItem(XFillStyleItem(drawing::FillStyle_NONE));
+ InsertObj(pGraf);
+ }
+ break;
case FPDF_PAGEOBJ_SHADING:
SAL_WARN("sd.filter", "Got page object SHADING");
break;
diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index 75f0c08d3bf2..f3a5456d2c93 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -1821,6 +1821,22 @@ bool ReadDIBV5(
return ImplReadDIB(rTarget, &rTargetAlpha, rIStm, true);
}
+bool ReadRawDIB(
+ Bitmap& rTarget,
+ const unsigned char* pBuf,
+ const ScanlineFormat nFormat,
+ const int nHeight,
+ const int nStride)
+{
+ BitmapScopedWriteAccess pWriteAccess(rTarget.AcquireWriteAccess(), rTarget);
+ for (int nRow = 0; nRow < nHeight; ++nRow)
+ {
+ pWriteAccess->CopyScanline(nRow, pBuf + (nStride * nRow), nFormat, nStride);
+ }
+
+ return true;
+}
+
bool WriteDIB(
const Bitmap& rSource,
SvStream& rOStm,