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

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