[Libreoffice-commits] core.git: vcl/source

Tor Lillqvist tml at collabora.com
Thu Nov 16 10:53:41 UTC 2017


 vcl/source/gdi/pdfwriter_impl.cxx |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

New commits:
commit ab99d4611cde968d02b97af63b74b80a427399a9
Author: Tor Lillqvist <tml at 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.
    
    Change-Id: I72173c7398db7f0e93c19679e3e392949bf1f4d2

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


More information about the Libreoffice-commits mailing list