[Libreoffice-commits] core.git: Branch 'feature/fixes10' - 2 commits - vcl/opengl

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Oct 5 09:28:46 PDT 2015


 vcl/opengl/salbmp.cxx |   64 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 12 deletions(-)

New commits:
commit 594784c5fcd48e9bb8d7f436ef62fe3b97310117
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Oct 5 17:05:45 2015 +0200

    opengl: take row stride into account when reading to 1-bit bitmap
    
    Opengl doesn't support 1-bit bitmaps so we read back the texture
    as RGB bitmap and transform it to 1-bit bitmap. Previously the
    implementation did this but naively by converting the buffer without
    taking row strides into account. Now on row change the writing is
    reset into a new byte.
    
    (cherry picked from commit 11b2e2e8113b67b9c9c8d1076c07d22ac93ada72)
    
    Change-Id: Iaa67b209d5b6ab0d9c567a71dee0684a85f53f6b
    Reviewed-on: https://gerrit.libreoffice.org/19161
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 3ba62fa..cbf60c2 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -513,25 +513,31 @@ bool OpenGLSalBitmap::ReadTexture()
 
         sal_uInt8* pCurrent = pBuffer;
 
-        for (size_t i = 0; i < aBuffer.size(); i += 3)
+        for (int y = 0; y < mnHeight; ++y)
         {
-            sal_uInt8 nR = *pCurrent++;
-            sal_uInt8 nG = *pCurrent++;
-            sal_uInt8 nB = *pCurrent++;
-
-            if (nR > 0 && nG > 0 && nB > 0)
-            {
-                pData[nIndex] |= (1 << nShift);
-            }
-            nShift--;
-            if (nShift < 0)
+            for (int x = 0; x < mnWidth; ++x)
             {
-                nShift = 7;
-                nIndex++;
-                pData[nIndex] = 0;
+                if (nShift < 0)
+                {
+                    nShift = 7;
+                    nIndex++;
+                    pData[nIndex] = 0;
+                }
+
+                sal_uInt8 nR = *pCurrent++;
+                sal_uInt8 nG = *pCurrent++;
+                sal_uInt8 nB = *pCurrent++;
+
+                if (nR > 0 && nG > 0 && nB > 0)
+                {
+                    pData[nIndex] |= (1 << nShift);
+                }
+                nShift--;
             }
+            nShift = 7;
+            nIndex++;
+            pData[nIndex] = 0;
         }
-
         mnBufWidth = mnWidth;
         mnBufHeight = mnHeight;
         return true;
commit f34157ebbd5aca28735e87a55d19ae4f24e215be
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Sep 16 14:02:23 2015 +0200

    opengl: support reading back 1-bit masks from texture
    
    Change-Id: Ibe8d9140f7a54016f2cd684198856ac27d880aa3
    (cherry picked from commit b85d24e430051054e54602aa14bf00b164c3865b)
    Reviewed-on: https://gerrit.libreoffice.org/18622
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index f3f131b..3ba62fa 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -468,8 +468,6 @@ GLuint OpenGLSalBitmap::CreateTexture()
 bool OpenGLSalBitmap::ReadTexture()
 {
     sal_uInt8* pData = maUserBuffer.get();
-    GLenum nFormat = GL_RGBA;
-    GLenum nType = GL_UNSIGNED_BYTE;
 
     SAL_INFO( "vcl.opengl", "::ReadTexture " << mnWidth << "x" << mnHeight );
 
@@ -478,8 +476,8 @@ bool OpenGLSalBitmap::ReadTexture()
 
     if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
     {
-        // no conversion needed for truecolor
-        pData = maUserBuffer.get();
+        GLenum nFormat = GL_RGBA;
+        GLenum nType = GL_UNSIGNED_BYTE;
 
         switch( mnBits )
         {
@@ -496,18 +494,54 @@ bool OpenGLSalBitmap::ReadTexture()
                     nType = GL_UNSIGNED_BYTE;
                     break;
         }
+
+        makeCurrent();
+        maTexture.Read(nFormat, nType, pData);
+        mnBufWidth = mnWidth;
+        mnBufHeight = mnHeight;
+        return true;
     }
-    else
-    {
-        return false;
+    else if (mnBits == 1)
+    {   // convert buffers from 24-bit RGB to 1-bit Mask
+        std::vector<sal_uInt8> aBuffer(mnWidth * mnHeight * 3);
+        makeCurrent();
+        sal_uInt8* pBuffer = aBuffer.data();
+        maTexture.Read(GL_RGB, GL_UNSIGNED_BYTE, pBuffer);
+
+        int nShift = 7;
+        size_t nIndex = 0;
+
+        sal_uInt8* pCurrent = pBuffer;
+
+        for (size_t i = 0; i < aBuffer.size(); i += 3)
+        {
+            sal_uInt8 nR = *pCurrent++;
+            sal_uInt8 nG = *pCurrent++;
+            sal_uInt8 nB = *pCurrent++;
+
+            if (nR > 0 && nG > 0 && nB > 0)
+            {
+                pData[nIndex] |= (1 << nShift);
+            }
+            nShift--;
+            if (nShift < 0)
+            {
+                nShift = 7;
+                nIndex++;
+                pData[nIndex] = 0;
+            }
+        }
+
+        mnBufWidth = mnWidth;
+        mnBufHeight = mnHeight;
+        return true;
     }
 
-    makeCurrent();
-    maTexture.Read( nFormat, nType, pData );
-    mnBufWidth = mnWidth;
-    mnBufHeight = mnHeight;
+    SAL_WARN("vcl.opengl", "::ReadTexture - tx:" << maTexture.Id() << " @ "
+             << mnWidth << "x" << mnHeight << "- unimplemented bit depth: "
+             << mnBits);
+    return false;
 
-    return true;
 }
 
 sal_uInt16 OpenGLSalBitmap::GetBitCount() const


More information about the Libreoffice-commits mailing list