From 8afabd394214bb7c772c88b08ec3cadb56771cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolnai=20Tam=C3=A1s?= Date: Fri, 18 Apr 2014 15:24:25 +0200 Subject: [PATCH] Extract code of BitmapEx -> RGBA buffer conversion to OpenGLHelper Needed by gltf rendering. Change-Id: I1aa974f3c515c5fb19a07b54ff655331138553cb --- chart2/source/view/main/OpenGLRender.cxx | 21 +----------------- include/vcl/opengl/OpenGLHelper.hxx | 2 ++ vcl/source/opengl/OpenGLHelper.cxx | 28 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 8ab05b7d136f..79e408cf26dc 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -900,26 +900,7 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point& long bmpWidth = rBitmapEx.GetSizePixel().Width(); long bmpHeight = rBitmapEx.GetSizePixel().Height(); - - Bitmap aBitmap (rBitmapEx.GetBitmap()); - AlphaMask aAlpha (rBitmapEx.GetAlpha()); - boost::scoped_array bitmapBuf(new sal_uInt8[4* bmpWidth * bmpHeight ]); - Bitmap::ScopedReadAccess pReadAccces( aBitmap ); - AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha ); - - size_t i = 0; - for (long ny = 0; ny < bmpHeight; ny++) - { - Scanline pAScan = pAlphaReadAccess->GetScanline(ny); - for(long nx = 0; nx < bmpWidth; nx++) - { - BitmapColor aCol = pReadAccces->GetColor( ny, nx ); - bitmapBuf[i++] = aCol.GetRed(); - bitmapBuf[i++] = aCol.GetGreen(); - bitmapBuf[i++] = aCol.GetBlue(); - bitmapBuf[i++] = 255 - *pAScan++; - } - } + boost::scoped_array bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx)); TextInfo aTextInfo; aTextInfo.rotation = -(double)rotation / 360.0 * 2* GL_PI; diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx index 77d1b2840c45..5cb1078fbb2d 100644 --- a/include/vcl/opengl/OpenGLHelper.hxx +++ b/include/vcl/opengl/OpenGLHelper.hxx @@ -12,6 +12,7 @@ #include #include +#include #include @@ -20,6 +21,7 @@ class VCLOPENGL_DLLPUBLIC OpenGLHelper public: static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName); + static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx); }; #endif diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index 0042231779d8..35760f2de72c 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include @@ -140,4 +142,30 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString return ProgramID; } +sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx) +{ + long nBmpWidth = rBitmapEx.GetSizePixel().Width(); + long nBmpHeight = rBitmapEx.GetSizePixel().Height(); + + Bitmap aBitmap (rBitmapEx.GetBitmap()); + AlphaMask aAlpha (rBitmapEx.GetAlpha()); + sal_uInt8* pBitmapBuf(new sal_uInt8[4* nBmpWidth * nBmpHeight ]); + Bitmap::ScopedReadAccess pReadAccces( aBitmap ); + AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha ); + size_t i = 0; + for (long ny = 0; ny < nBmpHeight; ny++) + { + Scanline pAScan = pAlphaReadAccess ? pAlphaReadAccess->GetScanline(ny) : 0; + for(long nx = 0; nx < nBmpWidth; nx++) + { + BitmapColor aCol = pReadAccces->GetColor( ny, nx ); + pBitmapBuf[i++] = aCol.GetRed(); + pBitmapBuf[i++] = aCol.GetGreen(); + pBitmapBuf[i++] = aCol.GetBlue(); + pBitmapBuf[i++] = pAScan ? 255 - *pAScan++ : 255; + } + } + return pBitmapBuf; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */