sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx | 44 +++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-)
New commits: commit b7a63d26466bac7eb7b25233a5a53788bed88c81 Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sun Feb 18 22:00:37 2024 +0000 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Feb 29 08:23:28 2024 +0100 tdf#113050 sdext.pdfimport: Flip bitmap We need to flip the bitmap between the wrapper and LO, but there's no easy way to do this in a Poly image fill in LO, so do it as a simple bitmap flip in the wrapper. Change-Id: Ifd84d37926c21edf30654d3884be975849a6dca3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163563 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx index 57eb30092141..ec2632b74899 100644 --- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx @@ -432,8 +432,6 @@ static void writeImage_( OutputBuffer& o_rOutputBuf, } // forwarders - - static void writeImageLF( OutputBuffer& o_rOutputBuf, Stream* str, int width, @@ -445,6 +443,45 @@ static void writeMaskLF( OutputBuffer& o_rOutputBuf, int height, bool bInvert ) { writeMask_(o_rOutputBuf,str,width,height,bInvert); } +// Vertically flip the bitmap +static void flipSplashBitmap(SplashBitmap *pBitmap) +{ + if (pBitmap->getRowSize() <= 0) + return; + + auto nBitmapHeight = static_cast<size_t>(pBitmap->getHeight()); + auto nRowSize = static_cast<size_t>(pBitmap->getRowSize()); + auto nAlphaRowSize = static_cast<size_t>(pBitmap->getAlphaRowSize()); + + auto aTmpRow = new unsigned char[nRowSize]; + auto aTmpAlphaRow = new unsigned char[nAlphaRowSize]; + + auto pBitmapData = pBitmap->getDataPtr(); + auto pAlphaData = pBitmap->getAlphaPtr(); + + // Set up pairs of pointers working from each end of the bitmap + auto pCurRowA = pBitmapData; + auto pCurAlphaA = pAlphaData; + auto pCurRowB = pBitmapData+nRowSize*(nBitmapHeight-1); + auto pCurAlphaB = pAlphaData+nAlphaRowSize*(nBitmapHeight-1); + + for (size_t nCur = 0; + nCur < nBitmapHeight/2; + nCur++, pCurRowA+=nRowSize, pCurRowB-=nRowSize, + pCurAlphaA+=nAlphaRowSize, pCurAlphaB-=nAlphaRowSize) + { + memcpy(aTmpRow, pCurRowA, nRowSize); + memcpy(pCurRowA, pCurRowB, nRowSize); + memcpy(pCurRowB, aTmpRow, nRowSize); + + memcpy(aTmpAlphaRow, pCurAlphaA, nAlphaRowSize); + memcpy(pCurAlphaA, pCurAlphaB, nAlphaRowSize); + memcpy(pCurAlphaB, aTmpAlphaRow, nAlphaRowSize); + } + delete[] aTmpRow; + delete[] aTmpAlphaRow; +} + int PDFOutDev::parseFont( long long nNewId, GfxFont* gfxFont, const GfxState* state ) const { FontAttributes aNewFont; @@ -1236,6 +1273,9 @@ poppler_bool PDFOutDev::tilingPatternFill(GfxState *state, Gfx *, Catalog *, delete pSplashGfx; delete pSplashOut; + // Add a vertical flip, we can't do this in LO for an image filled poly + flipSplashBitmap(pSplashBitmap); + auto nBitmapWidth = static_cast<size_t>(pSplashBitmap->getWidth()); auto nBitmapHeight = static_cast<size_t>(pSplashBitmap->getHeight());