[Libreoffice-commits] core.git: 3 commits - chart2/source include/vcl vcl/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Thu May 8 15:44:05 PDT 2014


 chart2/source/view/main/GL3DRenderer.cxx |   43 ++-----------------------------
 include/vcl/opengl/OpenGLHelper.hxx      |    1 
 vcl/source/opengl/OpenGLContext.cxx      |   13 ---------
 vcl/source/opengl/OpenGLHelper.cxx       |   18 ++++++++++++
 4 files changed, 23 insertions(+), 52 deletions(-)

New commits:
commit 37852a02cdb67b6c5665a794deae3efbed6d244a
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Fri May 9 00:35:33 2014 +0200

    Die, die, die BMP code
    
    This is at least the forth time that I kill this code!
    
    Change-Id: I038a03a8beed6f743ce6ad17a6a6b71085f43890

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 339cc7e..5a961a2 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -22,9 +22,9 @@
 
 #define GL_PI 3.14159f
 #define RGB_WHITE (0xFF | (0xFF << 8) | (0xFF << 16))
-#define BMP_HEADER_LEN 54
 
 #define DEBUG_FBO 0
+
 using namespace com::sun::star;
 
 namespace chart {
@@ -1535,36 +1535,6 @@ void OpenGL3DRenderer::CreateSceneBoxView()
     m_bCameraUpdated = true;
 }
 
-void OpenGL3DRenderer::CreateBMPHeader(sal_uInt8 *bmpHeader, int xsize, int ysize)
-{
-    unsigned char header[BMP_HEADER_LEN] = {
-        0x42, 0x4d, 0, 0, 0, 0, 0, 0, 0, 0,
-        54, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0
-    };
-
-    long file_size = (long)xsize * (long)ysize * 3 + 54;
-    header[2] = (unsigned char)(file_size &0x000000ff);
-    header[3] = (file_size >> 8) & 0x000000ff;
-    header[4] = (file_size >> 16) & 0x000000ff;
-    header[5] = (file_size >> 24) & 0x000000ff;
-
-    long width = xsize;
-    header[18] = width & 0x000000ff;
-    header[19] = (width >> 8) &0x000000ff;
-    header[20] = (width >> 16) &0x000000ff;
-    header[21] = (width >> 24) &0x000000ff;
-
-    long height = -ysize;
-    header[22] = height &0x000000ff;
-    header[23] = (height >> 8) &0x000000ff;
-    header[24] = (height >> 16) &0x000000ff;
-    header[25] = (height >> 24) &0x000000ff;
-    memcpy(bmpHeader, header, BMP_HEADER_LEN);
-}
-
-
 void OpenGL3DRenderer::ProcessUnrenderedShape()
 {
     CreateSceneBoxView();
@@ -1592,15 +1562,8 @@ void OpenGL3DRenderer::ProcessUnrenderedShape()
     glViewport(0, 0, m_iWidth, m_iHeight);
     RenderTexture(m_TextureObj[0]);
 #if DEBUG_FBO
-    char fileName[256] = {0};
-    sprintf(fileName, "D://shaderout_%d_%d.bmp", m_iWidth, m_iHeight);
-    FILE *pfile = fopen(fileName,"wb");
-    sal_uInt8 *Tmp = (sal_uInt8 *)malloc(m_iWidth * m_iHeight * 3 + BMP_HEADER_LEN);
-    CreateBMPHeader(Tmp, m_iWidth, m_iHeight);
-    glReadPixels(0, 0, m_iWidth, m_iHeight, GL_BGR, GL_UNSIGNED_BYTE, Tmp + BMP_HEADER_LEN);
-    fwrite(Tmp, m_iWidth * m_iHeight * 3 + BMP_HEADER_LEN, 1, pfile);
-    fclose(pfile);
-    free(Tmp);
+    OUString aFileName = OUString("D://shaderout_") + OUString::number(m_iWidth) + "_" + OUString::number(m_iHeight) + ".png";
+    OpenGLHelper::renderToFile(m_iWidth, m_iHeight, aFileName);
 #endif
 //    glBindFramebuffer(GL_FRAMEBUFFER, 0);
 }
commit 7ffd1af7228e05d05229ec66923208b6c4fdb845
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Fri May 9 00:31:05 2014 +0200

    move the renderToFile function to the helper to avoid the context
    
    Change-Id: I5493126047179d67b2f2ed0d3d5d936ebbaf4810

diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index 3530b2b..4afeae4 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -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);
 };
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index f79a160..8ad2d7a 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -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 )
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 0ed24d0..4ef2ce0 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -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);
commit 6470b42ce82ddd862c21adf853d27ce0184abc06
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Fri May 9 00:19:31 2014 +0200

    chart2.opengl to vcl.opengl
    
    Change-Id: Idd3b6ddec5ba2fbc56b7b9eb45ff379425104527

diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index 916d208..f79a160 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -570,7 +570,7 @@ void OpenGLContext::renderToFile()
         aWriter.Write( sOutput );
         sOutput.Close();
     } catch (...) {
-        SAL_WARN("chart2.opengl", "Error writing png to " << aName);
+        SAL_WARN("vcl.opengl", "Error writing png to " << aName);
     }
 }
 


More information about the Libreoffice-commits mailing list