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

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