Kaydet (Commit) 7ffd1af7 authored tarafından Markus Mohrhard's avatar Markus Mohrhard Kaydeden (comit) Markus Mohrhard

move the renderToFile function to the helper to avoid the context

Change-Id: I5493126047179d67b2f2ed0d3d5d936ebbaf4810
üst 6470b42c
......@@ -23,6 +23,7 @@ public:
static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx);
static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
static void renderToFile(long nWidth, long nHeight, const OUString& rFileName);
static const char* GLErrorString(GLenum errorCode);
};
......
......@@ -558,20 +558,9 @@ void OpenGLContext::renderToFile()
{
int iWidth = m_aGLWin.Width;
int iHeight = m_aGLWin.Height;
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[iWidth * iHeight * 4]);
glReadPixels(0, 0, iWidth, iHeight, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
BitmapEx aBmp = OpenGLHelper::ConvertBGRABufferToBitmapEx(buf.get(), iWidth, iHeight);
static int nIdx = 0;
OUString aName = OUString( "file:///home/moggi/Documents/work/output" ) + OUString::number( nIdx++ ) + ".png";
try {
vcl::PNGWriter aWriter( aBmp );
SvFileStream sOutput( aName, STREAM_WRITE );
aWriter.Write( sOutput );
sOutput.Close();
} catch (...) {
SAL_WARN("vcl.opengl", "Error writing png to " << aName);
}
OpenGLHelper::renderToFile(iWidth, iHeight, aName);
}
#if defined( WNT )
......
......@@ -14,6 +14,9 @@
#include <config_folders.h>
#include <vcl/salbtype.hxx>
#include <vcl/bmpacc.hxx>
#include <boost/scoped_array.hpp>
#include <vcl/pngwrite.hxx>
#include <vcl/graph.hxx>
#include <vector>
......@@ -168,6 +171,21 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx)
return pBitmapBuf;
}
void OpenGLHelper::renderToFile(long nWidth, long nHeight, const OUString& rFileName)
{
boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nWidth*nHeight*4]);
glReadPixels(0, 0, nWidth, nHeight, GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.get());
BitmapEx aBitmap = ConvertBGRABufferToBitmapEx(pBuffer.get(), nWidth, nHeight);
try {
vcl::PNGWriter aWriter( aBitmap );
SvFileStream sOutput( rFileName, STREAM_WRITE );
aWriter.Write( sOutput );
sOutput.Close();
} catch (...) {
SAL_WARN("vcl.opengl", "Error writing png to " << rFileName);
}
}
BitmapEx OpenGLHelper::ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight)
{
assert(pBuffer);
......
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