diff options
author | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-04-27 14:17:05 +0200 |
---|---|---|
committer | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-04-27 20:27:59 +0200 |
commit | f0bd1c6980e52f212ed95820420acfd0bcdf3cca (patch) | |
tree | 16699c3d20031023c649ba1535dfb1d54c3d0116 | |
parent | 99a034f91471b410d2437b6651be7ef10091549b (diff) |
OGFrameGrabber: use a BGRA buffer
Change-Id: Ie827ba98a6ff65d63eb61df1d90e18919de86395
-rw-r--r-- | avmedia/source/opengl/oglframegrabber.cxx | 27 | ||||
-rw-r--r-- | external/libgltf/UnpackedTarball_libgltf.mk | 1 | ||||
-rw-r--r-- | external/libgltf/patches/format_parameter_for_bitmap.patch | 68 |
3 files changed, 76 insertions, 20 deletions
diff --git a/avmedia/source/opengl/oglframegrabber.cxx b/avmedia/source/opengl/oglframegrabber.cxx index b2dcdc80f8e2..8b061e7ab57c 100644 --- a/avmedia/source/opengl/oglframegrabber.cxx +++ b/avmedia/source/opengl/oglframegrabber.cxx @@ -15,6 +15,10 @@ #include <vcl/salbtype.hxx> #include <vcl/bmpacc.hxx> +#include <vcl/opengl/OpenGLHelper.hxx> + +#include <boost/scoped_array.hpp> + using namespace com::sun::star; namespace avmedia { namespace ogl { @@ -32,26 +36,9 @@ OGLFrameGrabber::~OGLFrameGrabber() uno::Reference< css::graphic::XGraphic > SAL_CALL OGLFrameGrabber::grabFrame( double fMediaTime ) throw ( uno::RuntimeException, std::exception ) { - // TODO: libgltf should provide an RGBA buffer, not just an RGB one. See: OpenGLRender::GetAsBitmap(). - char* pBuffer = new char[m_pHandle->viewport.width * m_pHandle->viewport.height * 3]; - gltf_renderer_get_bitmap(m_pHandle, fMediaTime, pBuffer, m_pHandle->viewport.width, m_pHandle->viewport.height); - Bitmap aBitmap( Size(m_pHandle->viewport.width, m_pHandle->viewport.height), 24 ); - { - Bitmap::ScopedWriteAccess pWriteAccess( aBitmap ); - size_t nCurPos = 0; - for( int y = 0; y < m_pHandle->viewport.height; ++y) - { - Scanline pScan = pWriteAccess->GetScanline(y); - for( int x = 0; x < m_pHandle->viewport.width; ++x ) - { - *pScan++ = pBuffer[nCurPos]; - *pScan++ = pBuffer[nCurPos+1]; - *pScan++ = pBuffer[nCurPos+2]; - nCurPos += 3; - } - } - } - delete [] pBuffer; + boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[m_pHandle->viewport.width * m_pHandle->viewport.height * 4]); + gltf_renderer_get_bitmap(m_pHandle, fMediaTime, (char*)pBuffer.get(), m_pHandle->viewport.width, m_pHandle->viewport.height, GL_BGRA); + BitmapEx aBitmap = OpenGLHelper::ConvertBGRABufferToBitmapEx(pBuffer.get(), m_pHandle->viewport.width, m_pHandle->viewport.height); return Graphic( aBitmap ).GetXGraphic(); } diff --git a/external/libgltf/UnpackedTarball_libgltf.mk b/external/libgltf/UnpackedTarball_libgltf.mk index dd28b67422fc..6e6157dbc939 100644 --- a/external/libgltf/UnpackedTarball_libgltf.mk +++ b/external/libgltf/UnpackedTarball_libgltf.mk @@ -26,6 +26,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,libgltf,\ external/libgltf/patches/avoid_c++11.patch \ external/libgltf/patches/json_charbuffer_used_as_cstring.patch \ external/libgltf/patches/shader_charbuffer_used_as_cstring.patch \ + external/libgltf/patches/format_parameter_for_bitmap.patch \ )) # vim: set noet sw=4 ts=4: diff --git a/external/libgltf/patches/format_parameter_for_bitmap.patch b/external/libgltf/patches/format_parameter_for_bitmap.patch new file mode 100644 index 000000000000..526e95834cea --- /dev/null +++ b/external/libgltf/patches/format_parameter_for_bitmap.patch @@ -0,0 +1,68 @@ +diff -ur libgltf.org/inc/libgltf.h libgltf/inc/libgltf.h +--- libgltf.org/inc/libgltf.h 2014-04-27 14:10:06.191988313 +0200 ++++ libgltf/inc/libgltf.h 2014-04-27 14:12:03.171983919 +0200 +@@ -47,7 +47,7 @@ + /** Get a bitmap of the screen in the given point in time. */
+ extern "C"
+ void gltf_renderer_get_bitmap(glTFHandle *handle, double time,
+- char* buffer, long width, long height);
++ char* buffer, long width, long height, GLenum format);
+
+ /** Start playing the glTF animation to the current openGLcontext. */
+ extern "C"
+@@ -80,4 +80,4 @@ + /** Query where exactly the animation is, in seconds. */
+ extern "C"
+ double gltf_animation_get_time(glTFHandle *handle);
+-#endif +\ No newline at end of file ++#endif
+diff -ur libgltf.org/src/libgltf.cpp libgltf/src/libgltf.cpp +--- libgltf.org/src/libgltf.cpp 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/libgltf.cpp 2014-04-27 14:12:06.648983788 +0200 +@@ -70,10 +70,10 @@ +
+ extern "C"
+ void gltf_renderer_get_bitmap(glTFHandle *handle, double time,
+- char* buffer, long width, long height)
++ char* buffer, long width, long height, GLenum format)
+ {
+ class RenderScene* renderScene = (RenderScene*)handle->renderer;
+- renderScene->renderToBuffer(&(handle->viewport), (unsigned char*)buffer);
++ renderScene->renderToBuffer(&(handle->viewport), (unsigned char*)buffer, format);
+ return;
+ }
+
+diff -ur libgltf.org/src/RenderScene.cpp libgltf/src/RenderScene.cpp +--- libgltf.org/src/RenderScene.cpp 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/RenderScene.cpp 2014-04-27 14:11:03.199986172 +0200 +@@ -630,7 +630,7 @@ + return pCamera;
+ }
+
+-void RenderScene::renderToBuffer(glTFViewport* pViewport, unsigned char * buffer)
++void RenderScene::renderToBuffer(glTFViewport* pViewport, unsigned char * buffer, GLenum format)
+ {
+ createRenderObj(pViewport->width, pViewport->height);
+ createTextureObj(pViewport->width, pViewport->height);
+@@ -647,7 +647,7 @@ + GLenum fbResult = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if( fbResult != GL_FRAMEBUFFER_COMPLETE )
+ result = false;
+- glReadPixels(0, 0, pViewport->width, pViewport->height, GL_BGR,
++ glReadPixels(0, 0, pViewport->width, pViewport->height, format,
+ GL_UNSIGNED_BYTE, buffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glDeleteFramebuffers(1, &mFBOID);
+diff -ur libgltf.org/src/RenderScene.h libgltf/src/RenderScene.h +--- libgltf.org/src/RenderScene.h 2014-04-27 14:10:06.192988313 +0200 ++++ libgltf/src/RenderScene.h 2014-04-27 14:13:41.291980233 +0200 +@@ -91,7 +91,7 @@ + void render(void* lpParam);
+ void releaseRender(void* lpParam);
+ CPhysicalCamera* getCamera();
+- void renderToBuffer(glTFViewport* pViewpoit, unsigned char * buffer);
++ void renderToBuffer(glTFViewport* pViewpoit, unsigned char * buffer, GLenum format);
+ void renderRotateCamera(double horizontal, double vertical,
+ double planar, double time);
+ void renderMoveCamera(double x, double y, double z, double time);
|