[Bf-blender-cvs] [7455298] decklink: BGE: Image source refresh() accepts pixel format argument.

Benoit Bolsee noreply at git.blender.org
Tue Oct 20 00:35:17 CEST 2015


Commit: 7455298f8c6b21535f5b7cc2f158792b868b80b4
Author: Benoit Bolsee
Date:   Tue Oct 20 00:23:23 2015 +0200
Branches: decklink
https://developer.blender.org/rB7455298f8c6b21535f5b7cc2f158792b868b80b4

BGE: Image source refresh() accepts pixel format argument.

All image source objects now accept a pixel format argument in addition to
the buffer argument in the refresh() method. This can be used to change the
format of the image copied in the buffer. The only allowed values are "RGBA"
and "BGRA". This is useful when transferring images to external application
that do not support the RGBA format.
Ex:
   im = bge.texture.ImageRender(...)
   im.refresh(buffer, "BGRA")

Note: the transfer is optimal (i.e. no intermediate copy) for ImageRender and
ImageViewport objects when no processing of the image is needed in VideoTexture.
This is the case if no filter is set and the attributes are set as follow:
flip=False, alpha=True, scale=False, depth=False, zbuff=False.

===================================================================

M	doc/python_api/rst/bge.texture.rst
M	source/gameengine/VideoTexture/Exception.cpp
M	source/gameengine/VideoTexture/Exception.h
M	source/gameengine/VideoTexture/FilterBase.h
M	source/gameengine/VideoTexture/FilterSource.h
M	source/gameengine/VideoTexture/ImageBase.cpp
M	source/gameengine/VideoTexture/ImageBase.h
M	source/gameengine/VideoTexture/ImageRender.cpp
M	source/gameengine/VideoTexture/ImageRender.h
M	source/gameengine/VideoTexture/ImageViewport.cpp
M	source/gameengine/VideoTexture/ImageViewport.h
M	source/gameengine/VideoTexture/VideoBase.cpp

===================================================================

diff --git a/doc/python_api/rst/bge.texture.rst b/doc/python_api/rst/bge.texture.rst
index 167f2a4..bb30551 100644
--- a/doc/python_api/rst/bge.texture.rst
+++ b/doc/python_api/rst/bge.texture.rst
@@ -173,12 +173,17 @@ Video classes
       :return: Whether the video was playing.
       :rtype: bool
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA", ts=-1.0)
 
-      Refresh video - get its status.
-      
-      :value: see `FFmpeg Video and Image Status`_.
+      Refresh video - get its status and optionally copy the frame to an external buffer.
 
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is copied to the buffer, which must be big enough or an exception is thrown.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
+      :arg ts: An optional timestamp (in seconds from the start of the movie) of the frame to be copied to the buffer.
+      :type ts: float
+      :return: see `FFmpeg Video and Image Status`_.
       :rtype: int
 
 *************
@@ -244,12 +249,15 @@ Image classes
          * :class:`FilterRGB24`
          * :class:`FilterRGBA32`
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA")
 
-      Refresh image, i.e. load it.
+      Refresh image, get its status and optionally copy the frame to an external buffer.
       
-      :value: see `FFmpeg Video and Image Status`_.
-
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is copied to the buffer, which must be big enough or an exception is thrown.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
+      :return: see `FFmpeg Video and Image Status`_.
       :rtype: int
 
    .. method:: reload(newname=None)
@@ -411,9 +419,14 @@ Image classes
       
       :type: :class:`~bgl.Buffer` or None
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA")
 
-      Refresh image - invalidate its current content.
+      Refresh image - render and copy the image to an external buffer (optional) then invalidate its current content.
+
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is rendered and copied to the buffer, which must be big enough or an exception is thrown.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
 
    .. attribute:: scale
 
@@ -498,9 +511,14 @@ Image classes
       
       :type: :class:`~bgl.Buffer` or None
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA")
+
+      Refresh image - calculate and copy the image to an external buffer (optional) then invalidate its current content.
 
-      Refresh image - invalidate its current content.
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is calculated and copied to the buffer, which must be big enough or an exception is thrown.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
 
    .. attribute:: scale
 
@@ -602,9 +620,14 @@ Image classes
       
       :type: :class:`~bgl.Buffer` or None
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA")
 
-      Refresh image - invalidate its current content.
+      Refresh video - render and copy the image to an external buffer (optional) then invalidate its current content.
+
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is copied to the buffer, which must be big enough or an exception is thrown. The transfer to the buffer is optimal if no processing of the image is needed. This is the case if flip=False, alpha=True, scale=False, whole=True, depth=False, zbuff=False and no filter is set.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
 
    .. attribute:: scale
 
@@ -692,9 +715,14 @@ Image classes
       
       :type: sequence of two ints
 
-   .. method:: refresh()
+   .. method:: refresh(buffer=None, format="RGBA")
+
+      Refresh video - copy the viewport to an external buffer (optional) then invalidate its current content.
 
-      Refresh image - invalidate its current content.
+      :arg buffer: An optional object that implements the buffer protocol. If specified, the image is copied to the buffer, which must be big enough or an exception is thrown. The transfer to the buffer is optimal if no processing of the image is needed. This is the case if flip=False, alpha=True, scale=False, whole=True, depth=False, zbuff=False and no filter is set.
+      :type buffer: any buffer type
+      :arg format: An optional image format specifier for the image that will be copied to the buffer. Only valid values are "RGBA" or "BGRA"
+      :type format: str
 
    .. attribute:: scale
 
diff --git a/source/gameengine/VideoTexture/Exception.cpp b/source/gameengine/VideoTexture/Exception.cpp
index 08616e0..eccb7f7 100644
--- a/source/gameengine/VideoTexture/Exception.cpp
+++ b/source/gameengine/VideoTexture/Exception.cpp
@@ -213,6 +213,7 @@ void registerAllExceptions(void)
 	ImageSizesNotMatchDesc.registerDesc();
 	ImageHasExportsDesc.registerDesc();
 	InvalidColorChannelDesc.registerDesc();
+	InvalidImageModeDesc.registerDesc();
 	SceneInvalidDesc.registerDesc();
 	CameraInvalidDesc.registerDesc();
 	ObserverInvalidDesc.registerDesc();
@@ -223,4 +224,16 @@ void registerAllExceptions(void)
 	MirrorTooSmallDesc.registerDesc();
 	SourceVideoEmptyDesc.registerDesc();
 	SourceVideoCreationDesc.registerDesc();
+	OffScreenInvalidDesc.registerDesc();
+	DeckLinkBadDisplayModeDesc.registerDesc();
+	DeckLinkBadPixelFormatDesc.registerDesc();
+	AutoDetectionNotAvailDesc.registerDesc();
+	DeckLinkOpenCardDesc.registerDesc();
+	DeckLinkBadFormatDesc.registerDesc();
+	DeckLinkInternalErrorDesc.registerDesc();
+	SourceVideoOnlyCaptureDesc.registerDesc();
+	VideoDeckLinkBadFormatDesc.registerDesc();
+	VideoDeckLinkOpenCardDesc.registerDesc();
+	VideoDeckLinkDvpInternalErrorDesc.registerDesc();
+	VideoDeckLinkPinMemoryErrorDesc.registerDesc();
 }
diff --git a/source/gameengine/VideoTexture/Exception.h b/source/gameengine/VideoTexture/Exception.h
index 2060f87..c4de85f 100644
--- a/source/gameengine/VideoTexture/Exception.h
+++ b/source/gameengine/VideoTexture/Exception.h
@@ -209,9 +209,11 @@ extern ExpDesc MaterialNotAvailDesc;
 extern ExpDesc ImageSizesNotMatchDesc;
 extern ExpDesc ImageHasExportsDesc;
 extern ExpDesc InvalidColorChannelDesc;
+extern ExpDesc InvalidImageModeDesc;
 extern ExpDesc SceneInvalidDesc;
 extern ExpDesc CameraInvalidDesc;
 extern ExpDesc ObserverInvalidDesc;
+extern ExpDesc OffScreenInvalidDesc;
 extern ExpDesc MirrorInvalidDesc;
 extern ExpDesc MirrorSizeInvalidDesc;
 extern ExpDesc MirrorNormalInvalidDesc;
@@ -219,7 +221,19 @@ extern ExpDesc MirrorHorizontalDesc;
 extern ExpDesc MirrorTooSmallDesc;
 extern ExpDesc SourceVideoEmptyDesc;
 extern ExpDesc SourceVideoCreationDesc;
-
+extern ExpDesc DeckLinkBadDisplayModeDesc;
+extern ExpDesc DeckLinkBadPixelFormatDesc;
+extern ExpDesc AutoDetectionNotAvailDesc;
+extern ExpDesc DeckLinkOpenCardDesc;
+extern ExpDesc DeckLinkBadFormatDesc;
+extern ExpDesc DeckLinkInternalErrorDesc;
+extern ExpDesc SourceVideoOnlyCaptureDesc;
+extern ExpDesc VideoDeckLinkBadFormatDesc;
+extern ExpDesc VideoDeckLinkOpenCardDesc;
+extern ExpDesc VideoDeckLinkDvpInternalErrorDesc;
+extern ExpDesc VideoDeckLinkPinMemoryErrorDesc;
+
+extern ExceptionID InvalidImageMode;
 
 void registerAllExceptions(void);
 #endif
diff --git a/source/gameengine/VideoTexture/FilterBase.h b/source/gameengine/VideoTexture/FilterBase.h
index 498917e..915ebe9 100644
--- a/source/gameengine/VideoTexture/FilterBase.h
+++ b/source/gameengine/VideoTexture/FilterBase.h
@@ -44,6 +44,13 @@
 #define VT_A(v)	((unsigned char*)&v)[3]
 #define VT_RGBA(v,r,g,b,a)	VT_R(v)=(unsigned char)r, VT_G(v)=(unsigned char)g, VT_B(v)=(unsigned char)b, VT_A(v)=(unsigned char)a
 
+#ifdef __BIG_ENDIAN__
+#define VT_SWAPBR(i)	((((i)>>16)&0xFF00)+(((i)&0xFF00)<<16)+((i)&0xFF00FF))
+#else
+#define VT_SWAPBR(i)	((((i)&0xFF)<<16)+(((i)>>16)&0xFF)+((i)&0xFF00FF00))
+#endif
+
+
 // forward declaration
 class FilterBase;
 
diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h
index bc80b2b..dc46b5c 100644
--- a/source/gameengine/VideoTexture/FilterSource.h
+++ b/source/gameengine/VideoTexture/FilterSource.h
@@ -81,6 +81,29 @@ protected:
 	}
 };
 
+/// class for BGRA32 conversion
+class FilterBGRA32 : public FilterBase
+{
+public:
+	/// constructor
+	FilterBGRA32 (void) {}
+	/// destructor
+	virtual ~FilterBGRA32 (void) {}
+
+	/// get source pixel size
+	virtual unsigned int getPixelSize (void) { return 4; }
+
+protected:
+	/// filter pixel, source byte buffer
+	virtual unsigned int filter (unsigned char *src, short x, short y,
+		short * size, unsigned int pixSize, unsigned int val)
+	{
+		VT_RGBA(val,src[2],src[1],src[0],src[3]);
+		return val;
+	}
+};
+
+
 /// class for BGR24 conversion
 class FilterBGR24 : public FilterBase
 {
diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp
index ce67c9c..704b5e3 100644
--- a/source/gameengine/VideoTexture/ImageBase.cpp
+++ b/source/gameengine/VideoTexture/ImageBase.cpp
@@ -32,7 +32,6 @@
 extern "C" {
 #include "bgl.h"
 }
-#include "glew-mx.h"
 
 #include <vector>
 #include <string.h>
@@ -50,6 +49,14 @@ extern "C" {
 
 // ImageBase class implementation
 
+ExceptionID ImageHasExports;
+ExceptionID InvalidColorChannel;
+Excepti

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list