summaryrefslogtreecommitdiff
path: root/vcl/opengl/salbmp.cxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-09-23 18:29:26 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-11-27 09:55:06 +0100
commit17e61ec9620bdb52232428d8a94d0731d2c4a4fa (patch)
tree0d2cafe62785550ba1f1aaed374fb71268d52a5c /vcl/opengl/salbmp.cxx
parent39621789d09b20859811d622e5d0a899ea493f26 (diff)
move opengl's code for converting 1,2,4bpp to 24bpp
To be reused by the Skia code. Change-Id: If3befdbd86d98a2d931c7a366c47be57a0ae6c59
Diffstat (limited to 'vcl/opengl/salbmp.cxx')
-rw-r--r--vcl/opengl/salbmp.cxx138
1 files changed, 3 insertions, 135 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 36c34a2b3b92..f3147cdcc101 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -307,103 +307,6 @@ void OpenGLSalBitmap::DeallocateUserData()
namespace {
-class ImplPixelFormat
-{
-protected:
- sal_uInt8* mpData;
-public:
- static ImplPixelFormat* GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette );
-
- virtual void StartLine( sal_uInt8* pLine ) { mpData = pLine; }
- virtual const BitmapColor& ReadPixel() = 0;
- virtual ~ImplPixelFormat() { }
-};
-
-class ImplPixelFormat8 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
-
-public:
- explicit ImplPixelFormat8( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- {
- }
- virtual const BitmapColor& ReadPixel() override
- {
- assert( mrPalette.GetEntryCount() > *mpData );
- return mrPalette[ *mpData++ ];
- }
-};
-
-class ImplPixelFormat4 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
- sal_uInt32 mnShift;
-
-public:
- explicit ImplPixelFormat4( const BitmapPalette& rPalette )
- : mrPalette( rPalette )
- , mnX(0)
- , mnShift(4)
- {
- }
- virtual void StartLine( sal_uInt8* pLine ) override
- {
- mpData = pLine;
- mnX = 0;
- mnShift = 4;
- }
- virtual const BitmapColor& ReadPixel() override
- {
- sal_uInt32 nIdx = ( mpData[mnX >> 1] >> mnShift) & 0x0f;
- assert( mrPalette.GetEntryCount() > nIdx );
- const BitmapColor& rColor = mrPalette[nIdx];
- mnX++;
- mnShift ^= 4;
- return rColor;
- }
-};
-
-class ImplPixelFormat1 : public ImplPixelFormat
-{
-private:
- const BitmapPalette& mrPalette;
- sal_uInt32 mnX;
-
-public:
- explicit ImplPixelFormat1( const BitmapPalette& rPalette )
- : mrPalette(rPalette)
- , mnX(0)
- {
- }
- virtual void StartLine( sal_uInt8* pLine ) override
- {
- mpData = pLine;
- mnX = 0;
- }
- virtual const BitmapColor& ReadPixel() override
- {
- const BitmapColor& rColor = mrPalette[ (mpData[mnX >> 3 ] >> ( 7 - ( mnX & 7 ) )) & 1];
- mnX++;
- return rColor;
- }
-};
-
-ImplPixelFormat* ImplPixelFormat::GetFormat( sal_uInt16 nBits, const BitmapPalette& rPalette )
-{
- switch( nBits )
- {
- case 1: return new ImplPixelFormat1( rPalette );
- case 4: return new ImplPixelFormat4( rPalette );
- case 8: return new ImplPixelFormat8( rPalette );
- }
-
- return nullptr;
-}
-
void lclInstantiateTexture(OpenGLTexture& rTexture, const int nWidth, const int nHeight,
const GLenum nFormat, const GLenum nType, sal_uInt8 const * pData)
{
@@ -498,46 +401,11 @@ GLuint OpenGLSalBitmap::CreateTexture()
else
{
VCL_GL_INFO( "::CreateTexture - convert from " << mnBits << " to 24 bits" );
-
// convert to 24 bits RGB using palette
- pData = new sal_uInt8[mnHeight * mnWidth * 3];
- bAllocated = true;
determineTextureFormat(24, nFormat, nType);
-
- std::unique_ptr<ImplPixelFormat> pSrcFormat(ImplPixelFormat::GetFormat(mnBits, maPalette));
-
- sal_uInt8* pSrcData = mpUserBuffer.get();
- sal_uInt8* pDstData = pData;
-
- sal_uInt32 nY = mnHeight;
- while( nY-- )
- {
- pSrcFormat->StartLine( pSrcData );
-
- sal_uInt32 nX = mnWidth;
- if (nFormat == GL_BGR)
- {
- while( nX-- )
- {
- const BitmapColor& c = pSrcFormat->ReadPixel();
- *pDstData++ = c.GetBlue();
- *pDstData++ = c.GetGreen();
- *pDstData++ = c.GetRed();
- }
- }
- else // RGB
- {
- while( nX-- )
- {
- const BitmapColor& c = pSrcFormat->ReadPixel();
- *pDstData++ = c.GetRed();
- *pDstData++ = c.GetGreen();
- *pDstData++ = c.GetBlue();
- }
- }
-
- pSrcData += mnBytesPerRow;
- }
+ pData = convertDataTo24Bpp( mpUserBuffer.get(), mnWidth, mnHeight,
+ mnBits, mnBytesPerRow, maPalette, nFormat == GL_BGR ).release();
+ bAllocated = true;
}
}