Blame SOURCES/0001-Correctly-read-PNG-into-bitmaps-N32BitTcA.-formats-w.patch

8228c6
From 41594786266265c1b7d5116ab85b38af0cd1fd59 Mon Sep 17 00:00:00 2001
8228c6
From: Stephan Bergmann <sbergman@redhat.com>
8228c6
Date: Wed, 23 Sep 2020 12:01:35 +0200
8228c6
Subject: [PATCH] Correctly read PNG into bitmaps N32BitTcA... formats (where
8228c6
 alpha comes first)
8228c6
8228c6
This appears to be a regression introduced with
8228c6
86ea64f216819696cd86d1926aff0a138ace2baf "Support for native 32bit Bitmap in VCL
8228c6
and SVP (cairo) backend".  It caused CppunitTest_vcl_png_test to fail on
8228c6
(big-endian) Linux s390x with
8228c6
8228c6
> vcl/qa/cppunit/png/PngFilterTest.cxx:176:PngFilterTest::testPng
8228c6
> equality assertion failed
8228c6
> - Expected: c[ff000040]
8228c6
> - Actual  : c[0000ff40]
8228c6
8228c6
where eFormat happens to be ScanlineFormat::N32BitTcArgb, vs.
8228c6
ScanlineFormat::N32BitTcBgra on e.g. Linux x86-64 (and which thus didn't notice
8228c6
the lack of support for N32BitTcA... formats where alpha goes first instead of
8228c6
last).
8228c6
8228c6
Change-Id: Id6030468718f6ef831b42f2b5ad7ba2c4c46a805
8228c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103240
8228c6
Tested-by: Jenkins
8228c6
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
8228c6
(cherry picked from commit 0387077e6647d7a30fd36d4ec41dfc559afe45c3)
8228c6
---
8228c6
 vcl/source/filter/png/PngImageReader.cxx | 11 ++++++++++-
8228c6
 1 file changed, 10 insertions(+), 1 deletion(-)
8228c6
8228c6
diff --git a/vcl/source/filter/png/PngImageReader.cxx b/vcl/source/filter/png/PngImageReader.cxx
8228c6
index 958cae34eb46..6e9f3825face 100644
8228c6
--- a/vcl/source/filter/png/PngImageReader.cxx
8228c6
+++ b/vcl/source/filter/png/PngImageReader.cxx
8228c6
@@ -188,6 +188,8 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool bUseBitmap32)
8228c6
                     for (auto& rRow : aRows)
8228c6
                         rRow.resize(aRowSizeBytes, 0);
8228c6
 
8228c6
+                    auto const alphaFirst = (eFormat == ScanlineFormat::N32BitTcAbgr
8228c6
+                                             || eFormat == ScanlineFormat::N32BitTcArgb);
8228c6
                     for (int pass = 0; pass < nNumberOfPasses; pass++)
8228c6
                     {
8228c6
                         for (png_uint_32 y = 0; y < height; y++)
8228c6
@@ -199,10 +201,17 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool bUseBitmap32)
8228c6
                             for (size_t i = 0; i < aRowSizeBytes; i += 4)
8228c6
                             {
8228c6
                                 sal_Int8 alpha = pRow[i + 3];
8228c6
+                                if (alphaFirst)
8228c6
+                                {
8228c6
+                                    pScanline[iColor++] = alpha;
8228c6
+                                }
8228c6
                                 pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 0], alpha);
8228c6
                                 pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 1], alpha);
8228c6
                                 pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 2], alpha);
8228c6
-                                pScanline[iColor++] = alpha;
8228c6
+                                if (!alphaFirst)
8228c6
+                                {
8228c6
+                                    pScanline[iColor++] = alpha;
8228c6
+                                }
8228c6
                             }
8228c6
                         }
8228c6
                     }
8228c6
-- 
8228c6
2.33.1
8228c6