[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - vcl/source

Tor Lillqvist tml at collabora.com
Thu Nov 16 13:12:58 UTC 2017


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

New commits:
commit 552cac2571b6860603d5678b033337f4eac67b9e
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Nov 16 13:48:35 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
    Reviewed-on: https://gerrit.libreoffice.org/44815
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index e138f3869965..d1ce1e0b28d5 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -11291,10 +11291,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 ) ) );
-                DBG_ASSERT( nBlackIndex == 0 || nBlackIndex == 1, "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