Kaydet (Commit) 99a034f9 authored tarafından Zolnai Tamás's avatar Zolnai Tamás

OpenGLHelper: extract BGRA buffer -> BitmepEx conversion

Change-Id: I71edb2768d24f0c6686a9c94333447a5acc498b4
üst 825265f0
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <vector> #include <vector>
#include "OpenGLRender.hxx" #include "OpenGLRender.hxx"
#include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx> #include <vcl/graph.hxx>
#include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
...@@ -200,31 +199,7 @@ BitmapEx OpenGLRender::GetAsBitmap() ...@@ -200,31 +199,7 @@ BitmapEx OpenGLRender::GetAsBitmap()
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[m_iWidth * m_iHeight * 4]); 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()); glReadPixels(0, 0, m_iWidth, m_iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
Bitmap aBitmap( Size(m_iWidth, m_iHeight), 24 ); BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), m_iWidth, m_iHeight);
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);
#if DEBUG_PNG // debug PNG writing #if DEBUG_PNG // debug PNG writing
static int nIdx = 0; static int nIdx = 0;
......
...@@ -22,6 +22,7 @@ public: ...@@ -22,6 +22,7 @@ public:
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName); static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx); static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx);
static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
}; };
#endif #endif
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <vcl/opengl/OpenGLContext.hxx> #include <vcl/opengl/OpenGLContext.hxx>
#include <vcl/opengl/OpenGLHelper.hxx>
#include <vcl/syschild.hxx> #include <vcl/syschild.hxx>
#include <vcl/sysdata.hxx> #include <vcl/sysdata.hxx>
...@@ -15,7 +16,6 @@ ...@@ -15,7 +16,6 @@
#include <vcl/pngwrite.hxx> #include <vcl/pngwrite.hxx>
#include <vcl/bmpacc.hxx> #include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx> #include <vcl/graph.hxx>
#include <vcl/bitmapex.hxx>
using namespace com::sun::star; using namespace com::sun::star;
...@@ -522,31 +522,7 @@ void OpenGLContext::renderToFile() ...@@ -522,31 +522,7 @@ void OpenGLContext::renderToFile()
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]); boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]);
glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get()); glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
Bitmap aBitmap( Size(iWidth, iHeight), 24 ); BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight);
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);
static int nIdx = 0; static int nIdx = 0;
OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png"; OUString aName = OUString( "file:///home/moggi/Documents/work/text" ) + OUString::number( nIdx++ ) + ".png";
try { try {
......
...@@ -168,4 +168,33 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx) ...@@ -168,4 +168,33 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx)
return pBitmapBuf; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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