[Libreoffice-commits] core.git: Branch 'feature/chart_opengl_window' - 2 commits - avmedia/source chart2/source include/vcl vcl/source
Zolnai Tamás
tamas.zolnai at collabora.com
Mon Aug 11 01:32:53 PDT 2014
avmedia/source/opengl/oglplayer.cxx | 4 ++--
chart2/source/view/main/OpenGLRender.cxx | 4 +++-
include/vcl/opengl/OpenGLHelper.hxx | 8 +++++++-
vcl/source/opengl/OpenGLHelper.cxx | 14 ++++++--------
4 files changed, 18 insertions(+), 12 deletions(-)
New commits:
commit 69031bd0fa8e821f653b9a8722c63e076748dab0
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Mon Aug 11 10:18:04 2014 +0200
Mirror vertically the texture bitmaps for OpenGL
In case of glTF models it saves a Mirror() call.
In case of OpenGL charts it avoid flipped texts.
Change-Id: I1ac980e16bcb5ba6a9a025b638aaac3b08b4aab3
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index 5b2c634..03079b4 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -102,9 +102,8 @@ bool OGLPlayer::create( const OUString& rURL )
return false;
}
BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
- aBitmapEx.Mirror(BMP_MIRROR_VERT);
rFile.buffer = new char[4 * aBitmapEx.GetSizePixel().Width() * aBitmapEx.GetSizePixel().Height()];
- OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx, reinterpret_cast<sal_uInt8*>(rFile.buffer));
+ OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(aBitmapEx, reinterpret_cast<sal_uInt8*>(rFile.buffer));
rFile.imagewidth = aBitmapEx.GetSizePixel().Width();
rFile.imageheight = aBitmapEx.GetSizePixel().Height();
}
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 42b21cf..1075b86 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -699,7 +699,7 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point&
boost::shared_array<sal_uInt8> bitmapBuf(new sal_uInt8[4 * rBitmapEx.GetSizePixel().Width() * rBitmapEx.GetSizePixel().Height()]);
- OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx, bitmapBuf.get());
+ OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(rBitmapEx, bitmapBuf.get());
return CreateTextTexture(bitmapBuf, rBitmapEx.GetSizePixel(),
awt::Point(), aSize, rotation, rTrans);
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index 5cfaff0..c925409 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -22,10 +22,12 @@ public:
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
/**
- * Note: The caller is responsible for allocate the memory for the RGBA buffer, before call
- * this method. RGBA buffer size is assumed to be 4*width*height
+ * The caller is responsible for allocate the memory for the RGBA buffer, before call
+ * this method. RGBA buffer size is assumed to be 4*width*height.
+ * Since OpenGL uses textures flipped relative to BitmapEx storage this method
+ * also mirrors the bitmap vertically.
**/
- static void ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer);
+ static void ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer);
static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
static void renderToFile(long nWidth, long nHeight, const OUString& rFileName);
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 4917bdd..6dfb83f 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -146,7 +146,7 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString
return ProgramID;
}
-void OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer)
+void OpenGLHelper::ConvertBitmapExToRGBATextureBuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer)
{
long nBmpWidth = rBitmapEx.GetSizePixel().Width();
long nBmpHeight = rBitmapEx.GetSizePixel().Height();
@@ -156,7 +156,7 @@ void OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx, sal_uI
Bitmap::ScopedReadAccess pReadAccces( aBitmap );
AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha );
size_t i = 0;
- for (long ny = 0; ny < nBmpHeight; ny++)
+ for (long ny = nBmpHeight - 1; ny >= 0; ny--)
{
Scanline pAScan = pAlphaReadAccess ? pAlphaReadAccess->GetScanline(ny) : 0;
for(long nx = 0; nx < nBmpWidth; nx++)
commit 5c1298f702a162cb01c945775931a7cd033c755e
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Mon Aug 4 12:04:10 2014 +0200
It seems better if the caller allocates the memory for the RGBA buffer.
For example it allows to use std::vector<> and call the method
Change-Id: Id4b8e33838d358dd242d0176e42558505fa8d4a3
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index 431bdb8..5b2c634 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -103,7 +103,8 @@ bool OGLPlayer::create( const OUString& rURL )
}
BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
aBitmapEx.Mirror(BMP_MIRROR_VERT);
- rFile.buffer = (char*)OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx);
+ rFile.buffer = new char[4 * aBitmapEx.GetSizePixel().Width() * aBitmapEx.GetSizePixel().Height()];
+ OpenGLHelper::ConvertBitmapExToRGBABuffer(aBitmapEx, reinterpret_cast<sal_uInt8*>(rFile.buffer));
rFile.imagewidth = aBitmapEx.GetSizePixel().Width();
rFile.imageheight = aBitmapEx.GetSizePixel().Height();
}
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 2c93d36..42b21cf 100644
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -697,7 +697,9 @@ int OpenGLRender::CreateTextTexture(const BitmapEx& rBitmapEx, const awt::Point&
}
#endif
- boost::shared_array<sal_uInt8> bitmapBuf(OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx));
+ boost::shared_array<sal_uInt8> bitmapBuf(new sal_uInt8[4 * rBitmapEx.GetSizePixel().Width() * rBitmapEx.GetSizePixel().Height()]);
+
+ OpenGLHelper::ConvertBitmapExToRGBABuffer(rBitmapEx, bitmapBuf.get());
return CreateTextTexture(bitmapBuf, rBitmapEx.GetSizePixel(),
awt::Point(), aSize, rotation, rTrans);
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index f80d34b..5cfaff0 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -21,7 +21,11 @@ class VCLOPENGL_DLLPUBLIC OpenGLHelper
public:
static GLint LoadShaders(const OUString& rVertexShaderName, const OUString& rFragmentShaderName);
- static sal_uInt8* ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx);
+ /**
+ * Note: The caller is responsible for allocate the memory for the RGBA buffer, before call
+ * this method. RGBA buffer size is assumed to be 4*width*height
+ **/
+ static void ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer);
static BitmapEx ConvertBGRABufferToBitmapEx(const sal_uInt8* const pBuffer, long nWidth, long nHeight);
static void renderToFile(long nWidth, long nHeight, const OUString& rFileName);
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 84a1399..4917bdd 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -146,14 +146,13 @@ GLint OpenGLHelper::LoadShaders(const OUString& rVertexShaderName,const OUString
return ProgramID;
}
-sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx)
+void OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx, sal_uInt8* o_pRGBABuffer)
{
long nBmpWidth = rBitmapEx.GetSizePixel().Width();
long nBmpHeight = rBitmapEx.GetSizePixel().Height();
Bitmap aBitmap (rBitmapEx.GetBitmap());
AlphaMask aAlpha (rBitmapEx.GetAlpha());
- sal_uInt8* pBitmapBuf(new sal_uInt8[4* nBmpWidth * nBmpHeight ]);
Bitmap::ScopedReadAccess pReadAccces( aBitmap );
AlphaMask::ScopedReadAccess pAlphaReadAccess( aAlpha );
size_t i = 0;
@@ -163,13 +162,12 @@ sal_uInt8* OpenGLHelper::ConvertBitmapExToRGBABuffer(const BitmapEx& rBitmapEx)
for(long nx = 0; nx < nBmpWidth; nx++)
{
BitmapColor aCol = pReadAccces->GetColor( ny, nx );
- pBitmapBuf[i++] = aCol.GetRed();
- pBitmapBuf[i++] = aCol.GetGreen();
- pBitmapBuf[i++] = aCol.GetBlue();
- pBitmapBuf[i++] = pAScan ? 255 - *pAScan++ : 255;
+ o_pRGBABuffer[i++] = aCol.GetRed();
+ o_pRGBABuffer[i++] = aCol.GetGreen();
+ o_pRGBABuffer[i++] = aCol.GetBlue();
+ o_pRGBABuffer[i++] = pAScan ? 255 - *pAScan++ : 255;
}
}
- return pBitmapBuf;
}
void OpenGLHelper::renderToFile(long nWidth, long nHeight, const OUString& rFileName)
More information about the Libreoffice-commits
mailing list