[Libreoffice-commits] core.git: vcl/source
Caolán McNamara
caolanm at redhat.com
Thu Oct 13 19:46:08 UTC 2016
vcl/source/gdi/pdfwriter_impl.cxx | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
New commits:
commit 1c9096dad7dc2ee25d9ebe16ab02d5caba5f8a79
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Oct 13 20:14:03 2016 +0100
Resolves: tdf#103051 pdf export assumed 1bit bitmaps were N1BitMsbPal
Change-Id: I2268d8b74f187d07f161f42cc9530be3ebbc86d0
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 0d886e0..f5919ee 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -11066,6 +11066,36 @@ void PDFWriterImpl::writeJPG( JPGEmit& rObject )
}
}
+namespace
+{
+ unsigned char reverseByte(unsigned char b)
+ {
+ b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
+ b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
+ b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
+ return b;
+ }
+
+ //tdf#103051 convert any N1BitLsbPal to N1BitMsbPal
+ Bitmap getExportBitmap(const Bitmap &rBitmap)
+ {
+ Bitmap::ScopedReadAccess pAccess(const_cast<Bitmap&>(rBitmap));
+ const ScanlineFormat eFormat = pAccess->GetScanlineFormat();
+ if (eFormat != ScanlineFormat::N1BitLsbPal)
+ return rBitmap;
+ Bitmap aNewBmp(rBitmap);
+ Bitmap::ScopedWriteAccess xWriteAcc(aNewBmp);
+ const int nScanLineBytes = (pAccess->Width() + 7U) / 8U;
+ for (long nY = 0L; nY < xWriteAcc->Height(); ++nY)
+ {
+ Scanline pBitSwap = xWriteAcc->GetScanline(nY);
+ for (int x = 0; x < nScanLineBytes; ++x)
+ pBitSwap[x] = reverseByte(pBitSwap[x]);
+ }
+ return aNewBmp;
+ }
+}
+
bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
{
CHECK_RETURN( updateObject( rObject.m_nObject ) );
@@ -11075,7 +11105,7 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
bool bWriteMask = false;
if( ! bMask )
{
- aBitmap = rObject.m_aBitmap.GetBitmap();
+ aBitmap = getExportBitmap(rObject.m_aBitmap.GetBitmap());
if( rObject.m_aBitmap.IsAlpha() )
{
if( m_aContext.Version >= PDFWriter::PDF_1_4 )
@@ -11101,13 +11131,13 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
{
if( m_aContext.Version < PDFWriter::PDF_1_4 || ! rObject.m_aBitmap.IsAlpha() )
{
- aBitmap = rObject.m_aBitmap.GetMask();
+ aBitmap = getExportBitmap(rObject.m_aBitmap.GetMask());
aBitmap.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
SAL_WARN_IF( aBitmap.GetBitCount() != 1, "vcl", "mask conversion failed" );
}
else if( aBitmap.GetBitCount() != 8 )
{
- aBitmap = rObject.m_aBitmap.GetAlpha().GetBitmap();
+ aBitmap = getExportBitmap(rObject.m_aBitmap.GetAlpha().GetBitmap());
aBitmap.Convert( BMP_CONVERSION_8BIT_GREYS );
SAL_WARN_IF( aBitmap.GetBitCount() != 8, "vcl", "alpha mask conversion failed" );
}
More information about the Libreoffice-commits
mailing list