summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chart2/source/view/main/OpenGLRender.cxx27
-rw-r--r--include/vcl/opengl/OpenGLHelper.hxx1
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx28
-rw-r--r--vcl/source/opengl/OpenGLHelper.cxx29
4 files changed, 33 insertions, 52 deletions
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 79e408cf26dc..2301768ed07e 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -10,7 +10,6 @@
#include <GL/glew.h>
#include <vector>
#include "OpenGLRender.hxx"
-#include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx>
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -200,31 +199,7 @@ BitmapEx OpenGLRender::GetAsBitmap()
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[m_iWidth * m_iHeight * 4]);
glReadPixels(0, 0, m_iWidth, m_iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
- Bitmap aBitmap( Size(m_iWidth, m_iHeight), 24 );
- AlphaMask aAlpha( Size(m_iWidth, m_iHeight) );
-
- {
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- AlphaMask::ScopedWriteAccess pAlphaWriteAccess( aAlpha );
-
- size_t nCurPos = 0;
- for( int y = 0; y < m_iHeight; ++y)
- {
- Scanline pScan = pWriteAccess->GetScanline(y);
- Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y);
- for( int x = 0; x < m_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(), m_iWidth, m_iHeight);
#if DEBUG_PNG // debug PNG writing
static int nIdx = 0;
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index 5551fc19e1bd..7fa7d840f0e1 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -22,6 +22,7 @@ public:
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx);
+ static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
};
#endif
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: */