diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-08-10 08:52:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-08-24 19:08:09 +0900 |
commit | 652e3d2dbdd2d6f43953da3ae37cfc98d350328d (patch) | |
tree | 95a6a9f0c49e1c3145ce89583d72ad2f0c24357c /vcl/opengl | |
parent | 8657e3795d2e0ef0653835e2d56c53512dd43aea (diff) |
save texture to file as a PNG image
Change-Id: I5605b80f95d89599efe58cf65e1ce3f3581d401f
Diffstat (limited to 'vcl/opengl')
-rw-r--r-- | vcl/opengl/texture.cxx | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx index 2aa99a7f3ecc..a527ceb98dd3 100644 --- a/vcl/opengl/texture.cxx +++ b/vcl/opengl/texture.cxx @@ -23,7 +23,8 @@ #include "svdata.hxx" -#include "vcl/salbtype.hxx" +#include <vcl/salbtype.hxx> +#include <vcl/pngwrite.hxx> #include "opengl/framebuffer.hxx" #include "opengl/texture.hxx" @@ -262,6 +263,26 @@ void OpenGLTexture::Unbind() CHECK_GL_ERROR(); } +void OpenGLTexture::SaveToFile(const OUString& rFileName) +{ + std::vector<sal_uInt8> pBuffer(GetWidth() * GetHeight() * 4); + Read(GL_BGRA, GL_UNSIGNED_BYTE, pBuffer.data()); + BitmapEx aBitmap = OpenGLHelper::ConvertBGRABufferToBitmapEx(pBuffer.data(), GetWidth(), GetHeight()); + try + { + vcl::PNGWriter aWriter(aBitmap); + SvFileStream sOutput(rFileName, StreamMode::WRITE); + aWriter.Write(sOutput); + sOutput.Close(); + } + catch (...) + { + SAL_WARN("vcl.opengl", "Error writing png to " << rFileName); + } + + CHECK_GL_ERROR(); +} + void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ) { if( mpImpl == NULL ) |