vcl/qa/cppunit/BmpFilterTest.cxx  |   13 +++++++++++++
 vcl/qa/cppunit/data/tdf169871.bmp |binary
 vcl/source/bitmap/dibtools.cxx    |    6 +++---
 3 files changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 0428fbee5db4e8164df05d675cc68694ac340379
Author:     Andras Timar <[email protected]>
AuthorDate: Sun Dec 7 22:03:08 2025 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Dec 9 13:52:39 2025 +0100

    tdf#169871 fix wrong application of color mask
    
    nV5RedMask, nV5GreenMask and nV5BlueMask are valid only
    when used with 16-bpp or 32-bpp bitmap and the bitmap is
    not compressed.
    
    Change-Id: Ic6ca1364a12f9bc11d789e317428cd9c3e144873
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195209
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <[email protected]>
    (cherry picked from commit 66e99dae35e8564c8325508f084f501dfff97213)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195248
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/vcl/qa/cppunit/BmpFilterTest.cxx b/vcl/qa/cppunit/BmpFilterTest.cxx
index f591c39d93a9..12460de9339b 100644
--- a/vcl/qa/cppunit/BmpFilterTest.cxx
+++ b/vcl/qa/cppunit/BmpFilterTest.cxx
@@ -216,4 +216,17 @@ CPPUNIT_TEST_FIXTURE(BmpFilterTest, testTdf73523)
     CPPUNIT_ASSERT_EQUAL(COL_RED, aBitmap.GetPixelColor(0, 0));
 }
 
+CPPUNIT_TEST_FIXTURE(BmpFilterTest, testTdf169871)
+{
+    SvFileStream aFileStream(getFullUrl(u"tdf169871.bmp"), StreamMode::READ);
+    Graphic aGraphic;
+    CPPUNIT_ASSERT(BmpReader(aFileStream, aGraphic));
+    auto aBitmap = aGraphic.GetBitmapEx();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: rgba[800000ff]
+    // - Actual  : rgba[000080ff]
+    // i.e. the pixel is red not blue
+    CPPUNIT_ASSERT_EQUAL(COL_RED, aBitmap.GetPixelColor(0, 0));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/tdf169871.bmp 
b/vcl/qa/cppunit/data/tdf169871.bmp
new file mode 100644
index 000000000000..85684813f024
Binary files /dev/null and b/vcl/qa/cppunit/data/tdf169871.bmp differ
diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx
index c8159604560f..4c36a72a9034 100644
--- a/vcl/source/bitmap/dibtools.cxx
+++ b/vcl/source/bitmap/dibtools.cxx
@@ -521,12 +521,12 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& 
rHeader, BitmapWriteAccess& r
     }
     else
     {
-        if (rHeader.nV5RedMask > 0)
+        if (bTCMask && BITFIELDS == rHeader.nCompression)
+        {
             nRMask = rHeader.nV5RedMask;
-        if (rHeader.nV5GreenMask > 0)
             nGMask = rHeader.nV5GreenMask;
-        if (rHeader.nV5BlueMask > 0)
             nBMask = rHeader.nV5BlueMask;
+        }
 
         const tools::Long nWidth(rHeader.nWidth);
         const tools::Long nHeight(rHeader.nHeight);

Reply via email to