[Libreoffice-commits] core.git: vcl/opengl vcl/qa

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 28 14:43:03 UTC 2019


 vcl/opengl/salbmp.cxx                            |   10 ++++--
 vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx |   36 +++++++++++++++++++++++
 vcl/qa/cppunit/bitmaprender/data/tdf116888.gif   |binary
 3 files changed, 43 insertions(+), 3 deletions(-)

New commits:
commit df82c812e6dbb08837816ef9868bf24b3767ca1a
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Mar 26 13:48:47 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Mar 28 15:42:33 2019 +0100

    make ReadTexture() also handle 8-bit non-grayscale images (tdf#116888)
    
    The missing case caused BitmapReadAccess to work with random data
    (together with a follow-up bug that didn't deallocate data properly
    after ReadTexture() failed).
    
    Change-Id: I4546ee4ca85d6a0b01cc41636c257008c9f19587
    Reviewed-on: https://gerrit.libreoffice.org/69745
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index dc7418799e34..d8a8454ca4e7 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -598,8 +598,8 @@ bool OpenGLSalBitmap::ReadTexture()
 #endif
         return true;
     }
-    else if (mnBits == 1 || mnBits == 4)
-    {   // convert buffers from 24-bit RGB to 1 or 4-bit buffer
+    else if (mnBits == 1 || mnBits == 4 || mnBits == 8)
+    {   // convert buffers from 24-bit RGB to 1,4 or 8-bit buffer
         std::vector<sal_uInt8> aBuffer(mnWidth * mnHeight * 3);
 
         sal_uInt8* pBuffer = aBuffer.data();
@@ -614,9 +614,13 @@ bool OpenGLSalBitmap::ReadTexture()
                 pWriter.reset(new ScanlineWriter(maPalette, 8));
                 break;
             case 4:
-            default:
                 pWriter.reset(new ScanlineWriter(maPalette, 2));
                 break;
+            case 8:
+                pWriter.reset(new ScanlineWriter(maPalette, 1));
+                break;
+            default:
+                abort();
         }
 
         for (int y = 0; y < mnHeight; ++y)
diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
index eba78e717e24..531494205c14 100644
--- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
+++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
@@ -39,11 +39,13 @@ public:
     void testTdf104141();
     void testTdf113918();
     void testDrawBitmap32();
+    void testTdf116888();
 
     CPPUNIT_TEST_SUITE(BitmapRenderTest);
     CPPUNIT_TEST(testTdf104141);
     CPPUNIT_TEST(testTdf113918);
     CPPUNIT_TEST(testDrawBitmap32);
+    CPPUNIT_TEST(testTdf116888);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -126,6 +128,40 @@ void BitmapRenderTest::testDrawBitmap32()
 #endif
 }
 
+void BitmapRenderTest::testTdf116888()
+{
+    // The image is a 8bit image with a non-grayscale palette. In OpenGL mode
+    // pdf export of the image was broken, because OpenGLSalBitmap::ReadTexture()
+    // didn't handle 8bit non-grayscale and moreover OpenGLSalBitmap::AcquireBuffer()
+    // didn't properly release mpUserBuffer after ReadTexture() failure.
+    GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+    Graphic aGraphic;
+    const OUString aURL(getFullUrl("tdf116888.gif"));
+    SvFileStream aFileStream(aURL, StreamMode::READ);
+    ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
+    CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+    Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
+    CPPUNIT_ASSERT(!aBitmap.IsEmpty());
+    aBitmap.Scale(0.8, 0.8); // This scaling discards mpUserData,
+    Bitmap::ScopedReadAccess pAccess(aBitmap); // forcing ReadTexture() here.
+    // Check that there is mpUserBuffer content.
+    CPPUNIT_ASSERT(pAccess);
+    const ScanlineFormat eFormat = pAccess->GetScanlineFormat();
+    CPPUNIT_ASSERT_EQUAL(ScanlineFormat::N8BitPal, eFormat);
+    CPPUNIT_ASSERT(!aBitmap.HasGreyPalette());
+    // HACK: Some rendering backends change white to #FEFEFE while scaling for some reason.
+    // That is pretty much white too in practice, so adjust for that.
+    BitmapColor white(COL_WHITE);
+    if (pAccess->GetColor(0, 0) == Color(0xfe, 0xfe, 0xfe))
+        white = Color(0xfe, 0xfe, 0xfe);
+    // Check that the image contents are also valid.
+    CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(0, 0));
+    CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(0, pAccess->Width() - 1));
+    CPPUNIT_ASSERT_EQUAL(white, pAccess->GetColor(pAccess->Height() - 1, 0));
+    CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK),
+                         pAccess->GetColor(pAccess->Height() - 1, pAccess->Width() - 1));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(BitmapRenderTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/qa/cppunit/bitmaprender/data/tdf116888.gif b/vcl/qa/cppunit/bitmaprender/data/tdf116888.gif
new file mode 100644
index 000000000000..2953109491c4
Binary files /dev/null and b/vcl/qa/cppunit/bitmaprender/data/tdf116888.gif differ


More information about the Libreoffice-commits mailing list