Kaydet (Commit) f1d6f202 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#106270 vcl PDF import: use BitmapWriteAccess::CopyScanline()

This requires one function call / row only, cross-platform and works
with OpenGL enabled as well.

Change-Id: I12fd0f52a1a7e8e683b50071ded95f63fecc4d40
Reviewed-on: https://gerrit.libreoffice.org/34774Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 1c29456c
......@@ -73,34 +73,19 @@ bool generatePreview(SvStream& rStream, Graphic& rGraphic)
FPDF_RenderPageBitmap(pPdfBitmap, pPdfPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, /*rotate=*/0, /*flags=*/0);
// Save the buffer as a bitmap.
Bitmap aBitmap(Size(nPageWidth, nPageHeight), 32);
Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24);
{
Bitmap::ScopedWriteAccess pWriteAccess(aBitmap);
auto pPdfBuffer = static_cast<const char*>(FPDFBitmap_GetBuffer(pPdfBitmap));
#ifndef MACOSX
std::memcpy(pWriteAccess->GetBuffer(), pPdfBuffer, nPageWidth * nPageHeight * 4);
#else
// ARGB -> BGRA
auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap));
for (size_t nRow = 0; nRow < nPageHeight; ++nRow)
{
int nStride = FPDFBitmap_GetStride(pPdfBitmap);
const char* pPdfLine = pPdfBuffer + (nStride * nRow);
Scanline pRow = pWriteAccess->GetBuffer() + (nPageWidth * nRow * 4);
for (size_t nCol = 0; nCol < nPageWidth; ++nCol)
{
pRow[nCol * 4] = pPdfLine[(nCol * 4) + 3];
pRow[(nCol * 4) + 1] = pPdfLine[(nCol * 4) + 2];
pRow[(nCol * 4) + 2] = pPdfLine[(nCol * 4) + 1];
pRow[(nCol * 4) + 3] = pPdfLine[nCol * 4];
}
ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow);
// pdfium byte order is BGRA.
pWriteAccess->CopyScanline(nRow, pPdfLine, ScanlineFormat::N32BitTcBgra, nStride);
}
#endif
}
BitmapEx aBitmapEx(aBitmap);
#if defined(WNT) || defined(MACOSX)
aBitmapEx.Mirror(BmpMirrorFlags::Vertical);
#endif
rGraphic = aBitmapEx;
rGraphic = aBitmap;
FPDFBitmap_Destroy(pPdfBitmap);
FPDF_ClosePage(pPdfPage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment