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

Chris Sherlock chris.sherlock79 at gmail.com
Fri Mar 16 08:52:01 UTC 2018


 vcl/opengl/salbmp.cxx         |   19 +++++++------------
 vcl/qa/cppunit/BitmapTest.cxx |   27 +++------------------------
 vcl/quartz/salbmp.cxx         |   15 +++------------
 3 files changed, 13 insertions(+), 48 deletions(-)

New commits:
commit 460f39e687393b3a8906d2adc3e8f7a0c749851a
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Wed Mar 14 01:07:07 2018 +1100

    tdf#116213 OS X and OpenGL bitmap scaline sizes are not 32-bit aligned
    
    Change-Id: I92b43ae2f034bf63cc3f212ec8728c5c6b5e8934
    Reviewed-on: https://gerrit.libreoffice.org/51222
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 4127c46a509b..fab0f6d724d4 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -81,18 +81,13 @@ inline bool isValidBitCount( sal_uInt16 nBitCount )
 
 sal_uInt16 lclBytesPerRow(sal_uInt16 nBits, int nWidth)
 {
-    switch(nBits)
-    {
-    case 1:  return (nWidth + 7) >> 3;
-    case 4:  return (nWidth + 1) >> 1;
-    case 8:  return  nWidth;
-    case 16: return  nWidth * 2;
-    case 24: return  nWidth * 3;
-    case 32: return  nWidth * 4;
-    default:
-        OSL_FAIL("vcl::OpenGLSalBitmap::AllocateUserData(), illegal bitcount!");
-    }
-    return 0;
+    assert ((nBits == 1 || nBits == 4 || nBits == 8 || nBits == 16 || nBits == 24 || nBits == 32)
+            && "vcl::OpenGLSalBitmap::AllocateUserData(), illegal bitcount!");
+
+    if (!isValidBitCount(nBits))
+        return 0;
+
+    return AlignedWidth4Bytes(nBits * nWidth);
 }
 
 typedef std::vector<std::unique_ptr< FixedTextureAtlasManager > > TextureAtlasVector;
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index f835c7b78bc3..0bbe6d294882 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -342,15 +342,8 @@ void BitmapTest::testConvert()
     {
         Bitmap::ScopedReadAccess pReadAccess(aBitmap);
         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(8), pReadAccess->GetBitCount());
-#if defined MACOSX || defined IOS
-        //it would be nice to find and change the stride for quartz to be the same as everyone else
-        CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(10), pReadAccess->GetScanlineSize());
-#else
-#if HAVE_FEATURE_OPENGL
-        if (!OpenGLHelper::isVCLOpenGLEnabled())
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(12), pReadAccess->GetScanlineSize());
-#endif
-#endif
+        // scanline should pad to 32-bit multiples
+        CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(12), pReadAccess->GetScanlineSize());
         CPPUNIT_ASSERT(pReadAccess->HasPalette());
         const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(1, 1));
         CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed()));
@@ -365,22 +358,8 @@ void BitmapTest::testConvert()
         Bitmap::ScopedReadAccess pReadAccess(aBitmap);
         // 24 bit Bitmap on SVP backend can now use 24bit RGB everywhere.
         CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), pReadAccess->GetBitCount());
-
-#if defined LINUX || defined FREEBSD
+        // scanline should pad to 32-bit multiples
         CPPUNIT_ASSERT_EQUAL(sal_uLong(32), pReadAccess->GetScanlineSize());
-#else
-#if defined(_WIN32)
-        if (!OpenGLHelper::isVCLOpenGLEnabled())
-        {
-            // GDI Scanlines padded to DWORD multiples, it seems
-            CPPUNIT_ASSERT_EQUAL(sal_uLong(32), pReadAccess->GetScanlineSize());
-        }
-        else
-#endif
-        {
-            CPPUNIT_ASSERT_EQUAL(sal_uLong(30), pReadAccess->GetScanlineSize());
-        }
-#endif
 
         CPPUNIT_ASSERT(!pReadAccess->HasPalette());
         Color aColor = pReadAccess->GetPixel(0, 0).GetColor();
diff --git a/vcl/quartz/salbmp.cxx b/vcl/quartz/salbmp.cxx
index f9a10a44020b..04fb820b08a3 100644
--- a/vcl/quartz/salbmp.cxx
+++ b/vcl/quartz/salbmp.cxx
@@ -310,19 +310,10 @@ bool QuartzSalBitmap::AllocateUserData()
 
     if( mnWidth && mnHeight )
     {
-        mnBytesPerRow =  0;
+        assert((mnBits == 1 || mnBits == 4 || mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
+                && "vcl::QuartzSalBitmap::AllocateUserData(), illegal bitcount!");
 
-        switch( mnBits )
-        {
-        case 1:     mnBytesPerRow = (mnWidth + 7) >> 3; break;
-        case 4:     mnBytesPerRow = (mnWidth + 1) >> 1; break;
-        case 8:     mnBytesPerRow = mnWidth; break;
-        case 16:    mnBytesPerRow = mnWidth << 1; break;
-        case 24:    mnBytesPerRow = (mnWidth << 1) + mnWidth; break;
-        case 32:    mnBytesPerRow = mnWidth << 2; break;
-        default:
-            OSL_FAIL("vcl::QuartzSalBitmap::AllocateUserData(), illegal bitcount!");
-        }
+        mnBytesPerRow = AlignedWidth4Bytes(mnBits * mnWidth);
     }
 
     bool alloc = false;


More information about the Libreoffice-commits mailing list