summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2017-11-16 12:36:02 +0200
committerTor Lillqvist <tml@collabora.com>2017-11-16 12:49:22 +0200
commitab99d4611cde968d02b97af63b74b80a427399a9 (patch)
treeda5f8bcc9f330746748b33b0f86cf16c7872faa4 /vcl/source
parent0845ef8cdbd00474575885a71a409f3a86cfabc5 (diff)
tdf#113875: Properly export 1bpp greylevel (but not B&W) PNG images to PDF
No idea whether 1bpp non-greylevel (i.e. with two palette entries that aren't shades of grey) PNG images are mishandled. Change-Id: I72173c7398db7f0e93c19679e3e392949bf1f4d2
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx27
1 files changed, 23 insertions, 4 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 2fdd577f2e9b..e95502a2d053 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9529,10 +9529,29 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
if( aBitmap.GetBitCount() == 1 )
{
// #i47395# 1 bit bitmaps occasionally have an inverted grey palette
- sal_Int32 nBlackIndex = pAccess->GetBestPaletteIndex( BitmapColor( Color( COL_BLACK ) ) );
- SAL_WARN_IF( nBlackIndex != 0 && nBlackIndex != 1, "vcl.pdfwriter", "wrong black index" );
- if( nBlackIndex == 1 )
- aLine.append( "/Decode[1 0]\n" );
+ sal_uInt16 nBlackIndex = pAccess->GetBestPaletteIndex( BitmapColor( Color( COL_BLACK ) ) );
+ assert( nBlackIndex == 0 || nBlackIndex == 1);
+ sal_uInt16 nWhiteIndex = pAccess->GetBestPaletteIndex( BitmapColor( Color( COL_WHITE ) ) );
+ if( pAccess->GetPalette()[nBlackIndex] == BitmapColor( Color( COL_BLACK ) ) &&
+ pAccess->GetPalette()[nWhiteIndex] == BitmapColor( Color( COL_WHITE ) ) )
+ {
+ // It is black and white
+ if( nBlackIndex == 1 )
+ aLine.append( "/Decode[1 0]\n" );
+ }
+ else
+ {
+ // It is two levels of grey
+ aLine.append( "/Decode[" );
+ assert( pAccess->GetPalette()[0].GetRed() == pAccess->GetPalette()[0].GetGreen() &&
+ pAccess->GetPalette()[0].GetRed() == pAccess->GetPalette()[0].GetBlue() &&
+ pAccess->GetPalette()[1].GetRed() == pAccess->GetPalette()[1].GetGreen() &&
+ pAccess->GetPalette()[1].GetRed() == pAccess->GetPalette()[1].GetBlue() );
+ aLine.append( pAccess->GetPalette()[0].GetRed() / 255.0 );
+ aLine.append( " " );
+ aLine.append( pAccess->GetPalette()[1].GetRed() / 255.0 );
+ aLine.append( "]\n" );
+ }
}
}
else