summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2013-12-31 00:02:25 +0000
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-01-29 08:09:23 +0100
commitfeade6799392fa390b79b9c4a3df51fb0054899c (patch)
tree71da974b671ca678d2eb22c0b49c8e147d6cabf1 /chart2
parent594554feabd89545c7833aaf524e48c10515aae6 (diff)
Fix a number of issues converting GL to BitmapEx.
Change-Id: Ic6f0d4859f82d5afa4608a37697d2d10cc3f0cef
Diffstat (limited to 'chart2')
-rwxr-xr-x[-rw-r--r--]chart2/source/view/main/OpenGLRender.cxx115
-rwxr-xr-x[-rw-r--r--]chart2/source/view/main/OpenGLRender.hxx1
2 files changed, 55 insertions, 61 deletions
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index c54ef8c26df1..1d3a9f415a66 100644..100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -14,6 +14,7 @@
#include <vcl/bitmapex.hxx>
#include <vcl/bmpacc.hxx>
#include <vcl/graph.hxx>
+#include <vcl/pngwrite.hxx>
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
@@ -430,6 +431,55 @@ int OpenGLRender::RenderModelf(float *vertexArray, unsigned int vertexArraySize,
#endif
return 0;
}
+
+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_RGBA, 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);
+
+#if 0 // debug PNG writing
+ static int nIdx = 0;
+ OUString aName = OUString( "file://c/temp/image" ) + OUString::number( nIdx++ ) + ".png";
+ try {
+ vcl::PNGWriter aWriter( aBmp );
+ SvFileStream sOutput( aName, STREAM_WRITE );
+ aWriter.Write( sOutput );
+ sOutput.Close();
+ } catch (...) {
+ SAL_INFO("slideshow.opengl", "Error writing png to " << aName);
+ }
+#endif
+
+ return aBmp;
+}
+
int OpenGLRender::RenderModelf2FBO(float *vertexArray, unsigned int vertexArraySize, float *colorArray, unsigned int colorArraySize)
{
char fileName[256] = {0};
@@ -507,37 +557,10 @@ int OpenGLRender::RenderModelf2FBO(float *vertexArray, unsigned int vertexArrayS
fclose(pfile);
#else
- boost::scoped_array<sal_uInt8> buf(new sal_uInt8[m_iWidth * m_iHeight * 4]);
- glReadPixels(0, 0, m_iWidth, m_iHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf.get());
- BitmapEx aBmp;
- aBmp.SetSizePixel(Size(m_iWidth, m_iHeight));
-
- Bitmap aBitmap( aBmp.GetBitmap() );
- Bitmap aAlpha( aBmp.GetAlpha().GetBitmap() );
-
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- Bitmap::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++] );
- }
- }
-
- aBmp = BitmapEx(aBitmap, aAlpha);
+ fprintf( stderr, "this RGBA guy ...\n");
+ BitmapEx aBmp = GetAsBitmap(); // unclear why we create then do nothing with this.
#endif
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
RenderTexture(m_TextureObj[0]);
#if 0
@@ -649,37 +672,7 @@ int OpenGLRender::RenderLine2FBO(int wholeFlag)
free(buf);
fclose(pfile);
#else
- boost::scoped_array<sal_uInt8> buf(new sal_uInt8[m_iWidth * m_iHeight * 4]);
- glReadPixels(0, 0, m_iWidth, m_iHeight, GL_BGR, GL_UNSIGNED_BYTE, buf.get());
- BitmapEx aBmp;
- aBmp.SetSizePixel(Size(m_iWidth, m_iHeight));
-
- Bitmap aBitmap( Size( m_iWidth, m_iHeight), 24 );
- Bitmap aAlpha( Size( m_iWidth, m_iHeight), 24 );
-
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- Bitmap::ScopedWriteAccess pAlphaWriteAccess( aAlpha );
-
- size_t nCurPos = 0;
- for( size_t y = 0; y < size_t(m_iHeight); ++y)
- {
- Scanline pScan = pWriteAccess->GetScanline(y);
- Scanline pAlphaScan = pAlphaWriteAccess->GetScanline(y);
-
- for( size_t x = 0; x < size_t(m_iWidth); ++x )
- {
- *pScan++ = buf[nCurPos];
- *pScan++ = buf[nCurPos+1];
- *pScan++ = buf[nCurPos+2];
-
- nCurPos += 3;
-
- *pAlphaScan++ = static_cast<sal_uInt8>( 255 - buf[nCurPos++] );
- }
- }
-
- aBmp = BitmapEx(aBitmap, aAlpha);
- Graphic aGraphic(aBmp);
+ Graphic aGraphic( GetAsBitmap() );
uno::Reference< awt::XBitmap> xBmp( aGraphic.GetXGraphic(), uno::UNO_QUERY );
uno::Reference < beans::XPropertySet > xPropSet ( mxRenderTarget, uno::UNO_QUERY );
xPropSet->setPropertyValue("Graphic", uno::makeAny(aGraphic.GetXGraphic()));
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 8ce8fab13eee..fa446d312e56 100644..100755
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -123,6 +123,7 @@ public:
int SetLine2DShapePoint(float x, float y, int listLength);
void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b);
void SetLine2DWidth(int width);
+ BitmapEx GetAsBitmap();
private:
GLint LoadShaders(const char *vertexShader,const char *fragmentShader);
int CreateTextureObj(int width, int height);