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-05-14 08:15:45 -0400
commitbb5f1c3473b14feb59969c11351c4c6e6a44859c (patch)
tree2b7941c5bb8560b67cfce92ac0c968cdcbe552c5
parentb870837ff9cfea5c1cc35e34b53e59ad382e8ae7 (diff)
svx: support importing PDF images
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, 105 insertions, 2 deletions
diff --git a/include/vcl/dibtools.hxx b/include/vcl/dibtools.hxx
index 173d2d65a163..cc1f56ca18fa 100644
--- a/include/vcl/dibtools.hxx
+++ b/include/vcl/dibtools.hxx
@@ -24,6 +24,7 @@
#include <tools/rc.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( // WriteDIB(rBitmap, rOStm, false, true);
const Bitmap& rSource,
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 678518724353..39a42c7007ee 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -77,7 +77,6 @@
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xfltrit.hxx>
-#include <vcl/bitmapaccess.hxx>
#include <svx/xflbmtit.hxx>
#include <svx/xflbstit.hxx>
#include <svx/svdpntv.hxx>
@@ -85,8 +84,14 @@
#include <svx/svditer.hxx>
#include <svx/svdogrp.hxx>
#include <vcl/BitmapTools.hxx>
+#include <vcl/dibtools.hxx>
#include <com/sun/star/geometry/Matrix2D.hpp>
+struct FPDFBitmapDeleter
+{
+ inline void operator()(FPDF_BITMAP bitmap) { FPDFBitmap_Destroy(bitmap); }
+};
+
using namespace com::sun::star;
ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const Rectangle& rRect,
@@ -210,8 +215,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<void, 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;
+ }
+
+ Rectangle aRect(Point(0, 0), Size(nWidth, nHeight));
+ // aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
+ SdrGrafObj* pGraf = new SdrGrafObj(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 0791e40c864b..be1759f97c1d 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -1795,6 +1795,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)
+{
+ Bitmap::ScopedWriteAccess 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,