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

Tor Lillqvist tml at collabora.com
Mon Nov 20 14:07:20 UTC 2017


 vcl/source/gdi/pngread.cxx |   31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

New commits:
commit 8d4a25920ab02a12bd96105e7dd428231882b9b3
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 20 14:23:17 2017 +0200

    tdf#113918: Workaround: Read 1bpp indexed PNG images into 8bpp indexed Bitmaps
    
    The alternative, fixing the X11 disaster area, seemed more difficult.
    Somebody else with more time, feel free to revert and do that instead.
    
    Change-Id: I068ea27224ba98be25e01671546137ddd70691a7
    Reviewed-on: https://gerrit.libreoffice.org/44969
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/vcl/source/gdi/pngread.cxx b/vcl/source/gdi/pngread.cxx
index e6c9abea5e1c..8100d7116ee3 100644
--- a/vcl/source/gdi/pngread.cxx
+++ b/vcl/source/gdi/pngread.cxx
@@ -548,10 +548,19 @@ bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint )
         {
             switch ( mnPngDepth )
             {
+                case 1 :
+#if defined(UNX) && !defined(MAXOSX)
+                    // 1bpp indexed images are so badly mishandled by rest of LO on X11 that we
+                    // don't even bother, and turn them into 8bpp indexed ones with just two palette
+                    // entries instead.
+                    mnTargetDepth = 8;  // we have to expand the bitmap
+#endif
+                    mbPalette = false;
+                    break;
                 case 2 :
                     mnTargetDepth = 4;  // we have to expand the bitmap
-                    SAL_FALLTHROUGH;
-                case 1 :
+                    mbPalette = false;
+                    break;
                 case 4 :
                 case 8 :
                     mbPalette = false;
@@ -1330,7 +1339,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
                 }
                 else // neither alpha nor transparency
                 {
-                    if ( mnPngDepth == 8 )  // maybe the source is a 16 bit grayscale
+                    if ( mnPngDepth == 8 )  // maybe the source is a 16 bit grayscale or 1 bit indexed
                     {
                         if( nXAdd == 1 && mnPreviewShift == 0 )  // copy raw line data if possible
                         {
@@ -1345,6 +1354,22 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
                                 ImplSetPixel( nY, nX, *pTmp++ );
                         }
                     }
+                    else if (mnPngDepth == 1 )
+                    {
+                        for ( long nX = nXStart, nShift = 0; nX < maOrigSize.Width(); nX += nXAdd )
+                        {
+                            nShift = (nShift - 1) & 7;
+
+                            sal_uInt8 nCol;
+                            if ( nShift == 0 )
+                                nCol = *(pTmp++);
+                            else
+                                nCol = static_cast<sal_uInt8>( *pTmp >> nShift );
+                            nCol &= 1;
+
+                            ImplSetPixel( nY, nX, nCol );
+                        }
+                    }
                     else
                     {
                         for ( long nX = nXStart; nX < maOrigSize.Width(); nX += nXAdd, pTmp += 2 )


More information about the Libreoffice-commits mailing list