summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-04-27 20:25:52 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-04-27 20:27:59 +0200
commit99a034f91471b410d2437b6651be7ef10091549b (patch)
tree7bf5218311aa2f95762ccf32cf2f8536150770af /vcl
parent825265f093a844f952d0dd64e5b4de9a1aba3185 (diff)
OpenGLHelper: extract BGRA buffer -> BitmepEx conversion
Change-Id: I71edb2768d24f0c6686a9c94333447a5acc498b4
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx28
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx29
2 files changed, 31 insertions, 26 deletions
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index b8c963ba1fb6..07b38d2d60bd 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -8,6 +8,7 @@
*/
#include <vcl/opengl/OpenGLContext.hxx>
+#include <vcl/opengl/OpenGLHelper.hxx>
#include <vcl/syschild.hxx>
#include <vcl/sysdata.hxx>
@@ -15,7 +16,6 @@
#include <vcl/pngwrite.hxx>
#include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx>
-#include <vcl/bitmapex.hxx>
using namespace com::sun::star;
@@ -522,31 +522,7 @@ void OpenGLContext::renderToFile()
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]);
glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
- Bitmap aBitmap( Size(iWidth, iHeight), 24 );
- AlphaMask aAlpha( Size(iWidth, iHeight) );
-
- {
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha );
-
- size_t nCurPos = 0;
- for( int y = 0; y < iHeight; ++y)
- {
- Scanline pScan = pWriteAccess->GetScanline(y);
- Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y);
- for( int x = 0; x < iWidth; ++x )
- {
- *pScan++ = buf[nCurPos];
- *pScan++ = buf[nCurPos+1];
- *pScan++ = buf[nCurPos+2];
-
- nCurPos += 3;
- *pAlphaScan++ = static_cast<sal_uInt8>( 255 - buf[nCurPos++] );
- }
- }
- }
-
- BitmapEx aBmp(aBitmap, aAlpha);
+ BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight);
static int nIdx = 0;
OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png";
try {
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 35760f2de72c..82b4a9affc03 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -168,4 +168,33 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx)
return pBitmapBuf;
}
+BitmapEx OpenGLHelper::ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight)
+{
+ assert(pBuffer);
+ Bitmap aBitmap( Size(nWidth, nHeight), 24 );
+ AlphaMask aAlpha( Size(nWidth, nHeight) );
+
+ {
+ Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
+ AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha );
+
+ size_t nCurPos = 0;
+ for( int y = 0; y < nHeight; ++y)
+ {
+ Scanline pScan = pWriteAccess->GetScanline(y);
+ Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y);
+ for( int x = 0; x < nWidth; ++x )
+ {
+ *pScan++ = pBuffer[nCurPos];
+ *pScan++ = pBuffer[nCurPos+1];
+ *pScan++ = pBuffer[nCurPos+2];
+
+ nCurPos += 3;
+ *pAlphaScan++ = static_cast<sal_uInt8>( 255 - pBuffer[nCurPos++] );
+ }
+ }
+ }
+ return BitmapEx(aBitmap, aAlpha);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */