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

New commits:
commit b12309df2dd529b1d23af4bcd10ed4421fcf92be
Author: Tomaž Vajngerl <tomaz.vajng...@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.me...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@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
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to