Kaydet (Commit) b12309df authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Jan Holesovsky

opengl: support reading back 1-bit masks from texture

Change-Id: Ibe8d9140f7a54016f2cd684198856ac27d880aa3
(cherry picked from commit b85d24e4)
Reviewed-on: https://gerrit.libreoffice.org/18622Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 915d3ba9
...@@ -468,8 +468,6 @@ GLuint OpenGLSalBitmap::CreateTexture() ...@@ -468,8 +468,6 @@ GLuint OpenGLSalBitmap::CreateTexture()
bool OpenGLSalBitmap::ReadTexture() bool OpenGLSalBitmap::ReadTexture()
{ {
sal_uInt8* pData = maUserBuffer.get(); sal_uInt8* pData = maUserBuffer.get();
GLenum nFormat = GL_RGBA;
GLenum nType = GL_UNSIGNED_BYTE;
SAL_INFO( "vcl.opengl", "::ReadTexture " << mnWidth << "x" << mnHeight ); SAL_INFO( "vcl.opengl", "::ReadTexture " << mnWidth << "x" << mnHeight );
...@@ -478,8 +476,8 @@ bool OpenGLSalBitmap::ReadTexture() ...@@ -478,8 +476,8 @@ bool OpenGLSalBitmap::ReadTexture()
if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32) if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
{ {
// no conversion needed for truecolor GLenum nFormat = GL_RGBA;
pData = maUserBuffer.get(); GLenum nType = GL_UNSIGNED_BYTE;
switch( mnBits ) switch( mnBits )
{ {
...@@ -496,18 +494,54 @@ bool OpenGLSalBitmap::ReadTexture() ...@@ -496,18 +494,54 @@ bool OpenGLSalBitmap::ReadTexture()
nType = GL_UNSIGNED_BYTE; nType = GL_UNSIGNED_BYTE;
break; break;
} }
makeCurrent();
maTexture.Read(nFormat, nType, pData);
mnBufWidth = mnWidth;
mnBufHeight = mnHeight;
return true;
} }
else 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)
{ {
return false; 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;
}
} }
makeCurrent();
maTexture.Read( nFormat, nType, pData );
mnBufWidth = mnWidth; mnBufWidth = mnWidth;
mnBufHeight = mnHeight; mnBufHeight = mnHeight;
return true; return true;
}
SAL_WARN("vcl.opengl", "::ReadTexture - tx:" << maTexture.Id() << " @ "
<< mnWidth << "x" << mnHeight << "- unimplemented bit depth: "
<< mnBits);
return false;
} }
sal_uInt16 OpenGLSalBitmap::GetBitCount() const sal_uInt16 OpenGLSalBitmap::GetBitCount() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment