vcl/source/gdi/pdfwriter_impl.cxx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
New commits: commit f42d1a7788dc8f6e80c9c0a8e7ac8b04001dc941 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Nov 16 12:36:02 2017 +0200 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. (cherry picked from commit ab99d4611cde968d02b97af63b74b80a427399a9) Change-Id: I72173c7398db7f0e93c19679e3e392949bf1f4d2 Reviewed-on: https://gerrit.libreoffice.org/44812 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Michael Stahl <mst...@redhat.com> diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index cdbabb4ffd92..025adf8afd6d 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -11452,10 +11452,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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits