From: Jochen Sprickerhof <jochen@sprickerhof.de>
Date: Tue, 6 Nov 2012 20:43:44 +0100
Subject: Add and enable (uncompressed) Bayer modes

taken from https://kforge.ros.org/openni/drivers
---
 Source/XnDeviceSensorV2/XnHostProtocol.h        |    4 +--
 Source/XnDeviceSensorV2/XnSensorDepthStream.h   |    6 ++---
 Source/XnDeviceSensorV2/XnSensorImageStream.cpp |   33 ++++++++++++++++++++++-
 Source/XnDeviceSensorV2/XnSensorImageStream.h   |    6 ++---
 4 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/Source/XnDeviceSensorV2/XnHostProtocol.h b/Source/XnDeviceSensorV2/XnHostProtocol.h
index 36721c8..e04f2b4 100644
--- a/Source/XnDeviceSensorV2/XnHostProtocol.h
+++ b/Source/XnDeviceSensorV2/XnHostProtocol.h
@@ -108,8 +108,8 @@ enum EPsProtocolOpCodes_V017
 typedef enum
 {
 	XN_HOST_PROTOCOL_ALGORITHM_DEPTH_INFO	= 0x00,
-	XN_HOST_PROTOCOL_ALGORITHM_REGISTRATION	= 0x02,
-	XN_HOST_PROTOCOL_ALGORITHM_PADDING		= 0x03,
+	XN_HOST_PROTOCOL_ALGORITHM_REGISTRATION	= 0x40,
+	XN_HOST_PROTOCOL_ALGORITHM_PADDING		= 0x41,
 	XN_HOST_PROTOCOL_ALGORITHM_BLANKING		= 0x06,
 	XN_HOST_PROTOCOL_ALGORITHM_DEVICE_INFO	= 0x07,
 	XN_HOST_PROTOCOL_ALGORITHM_FREQUENCY	= 0x80
diff --git a/Source/XnDeviceSensorV2/XnSensorDepthStream.h b/Source/XnDeviceSensorV2/XnSensorDepthStream.h
index 7ac329a..737ec68 100644
--- a/Source/XnDeviceSensorV2/XnSensorDepthStream.h
+++ b/Source/XnDeviceSensorV2/XnSensorDepthStream.h
@@ -36,11 +36,11 @@
 // Defines
 //---------------------------------------------------------------------------
 #define XN_DEPTH_STREAM_DEFAULT_INPUT_FORMAT				XN_IO_DEPTH_FORMAT_UNCOMPRESSED_11_BIT
-#define XN_DEPTH_STREAM_DEFAULT_RESOLUTION					XN_RESOLUTION_QVGA
+#define XN_DEPTH_STREAM_DEFAULT_RESOLUTION					XN_RESOLUTION_VGA
 #define XN_DEPTH_STREAM_DEFAULT_FPS							30
 #define XN_DEPTH_STREAM_DEFAULT_OUTPUT_FORMAT				XN_OUTPUT_FORMAT_DEPTH_VALUES
 #define XN_DEPTH_STREAM_DEFAULT_REGISTRATION				FALSE
-#define XN_DEPTH_STREAM_DEFAULT_REGISTRATION_TYPE			XN_PROCESSING_DONT_CARE
+#define XN_DEPTH_STREAM_DEFAULT_REGISTRATION_TYPE			XN_PROCESSING_SOFTWARE
 #define XN_DEPTH_STREAM_DEFAULT_HOLE_FILLER					TRUE
 #define XN_DEPTH_STREAM_DEFAULT_WHITE_BALANCE				TRUE
 #define XN_DEPTH_STREAM_DEFAULT_GAIN_OLD					50
@@ -162,4 +162,4 @@ private:
 	XnCallbackHandle m_hReferenceSizeChangedCallback;
 };
 
-#endif //__XN_SENSOR_DEPTH_STREAM_H__
\ No newline at end of file
+#endif //__XN_SENSOR_DEPTH_STREAM_H__
diff --git a/Source/XnDeviceSensorV2/XnSensorImageStream.cpp b/Source/XnDeviceSensorV2/XnSensorImageStream.cpp
index 23f25a5..8c17b11 100644
--- a/Source/XnDeviceSensorV2/XnSensorImageStream.cpp
+++ b/Source/XnDeviceSensorV2/XnSensorImageStream.cpp
@@ -214,6 +214,14 @@ XnStatus XnSensorImageStream::Init()
 		nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_YUV422, XN_RESOLUTION_VGA, 30);
 		XN_IS_STATUS_OK(nRetVal);
 
+		// Enable Bayer images
+		nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_QVGA, 30);
+		XN_IS_STATUS_OK(nRetVal);
+		nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_QVGA, 60);
+		XN_IS_STATUS_OK(nRetVal);
+		nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_VGA, 30);
+		XN_IS_STATUS_OK(nRetVal);
+
 		// add uncompressed ones
 		if (bUncompressedAllowed)
 		{
@@ -223,6 +231,16 @@ XnStatus XnSensorImageStream::Init()
 			XN_IS_STATUS_OK(nRetVal);
 			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422, XN_RESOLUTION_VGA, 30);
 			XN_IS_STATUS_OK(nRetVal);
+      
+      // Enable umcompressed Bayer			
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_SXGA, 15);
+			XN_IS_STATUS_OK(nRetVal);
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_VGA, 30);
+			XN_IS_STATUS_OK(nRetVal);
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_QVGA, 60);
+			XN_IS_STATUS_OK(nRetVal);
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_QVGA, 30);
+			XN_IS_STATUS_OK(nRetVal);
 		}
 
 		// starting with FW 5.1, 25 FPS is also supported
@@ -232,13 +250,22 @@ XnStatus XnSensorImageStream::Init()
 			XN_IS_STATUS_OK(nRetVal);
 			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_YUV422, XN_RESOLUTION_VGA, 25);
 			XN_IS_STATUS_OK(nRetVal);
-
+      // Enable Bayer
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_QVGA, 25);
+			XN_IS_STATUS_OK(nRetVal);
+			nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_VGA, 25);
+			XN_IS_STATUS_OK(nRetVal);
+      
 			if (bUncompressedAllowed)
 			{
 				nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422, XN_RESOLUTION_QVGA, 25);
 				XN_IS_STATUS_OK(nRetVal);
 				nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422, XN_RESOLUTION_VGA, 25);
 				XN_IS_STATUS_OK(nRetVal);
+			  nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_QVGA, 25);
+			  XN_IS_STATUS_OK(nRetVal);
+			  nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_VGA, 25);
+			  XN_IS_STATUS_OK(nRetVal);
 			}
 		}
 
@@ -255,11 +282,15 @@ XnStatus XnSensorImageStream::Init()
 			{
 				nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_YUV422, XN_RESOLUTION_SXGA, 30);
 				XN_IS_STATUS_OK(nRetVal);
+				nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_BAYER, XN_RESOLUTION_SXGA, 30);
+				XN_IS_STATUS_OK(nRetVal);
 
 				if (bUncompressedAllowed)
 				{
 					nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422, XN_RESOLUTION_SXGA, 30);
 					XN_IS_STATUS_OK(nRetVal);
+					nRetVal = AddSupportedMode(supportedModes, XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER, XN_RESOLUTION_SXGA, 30);
+					XN_IS_STATUS_OK(nRetVal);
 				}
 			}
 		}
diff --git a/Source/XnDeviceSensorV2/XnSensorImageStream.h b/Source/XnDeviceSensorV2/XnSensorImageStream.h
index 94bc3a5..be9091f 100644
--- a/Source/XnDeviceSensorV2/XnSensorImageStream.h
+++ b/Source/XnDeviceSensorV2/XnSensorImageStream.h
@@ -33,8 +33,8 @@
 // Defines
 //---------------------------------------------------------------------------
 #define XN_IMAGE_STREAM_DEFAULT_FPS				30
-#define XN_IMAGE_STREAM_DEFAULT_RESOLUTION		XN_RESOLUTION_QVGA
-#define XN_IMAGE_STREAM_DEFAULT_INPUT_FORMAT	XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422
+#define XN_IMAGE_STREAM_DEFAULT_RESOLUTION		XN_RESOLUTION_VGA
+#define XN_IMAGE_STREAM_DEFAULT_INPUT_FORMAT	XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER
 #define XN_IMAGE_STREAM_DEFAULT_OUTPUT_FORMAT	XN_OUTPUT_FORMAT_RGB24
 #define XN_IMAGE_STREAM_DEFAULT_FLICKER			0
 #define XN_IMAGE_STREAM_DEFAULT_QUALITY			3
@@ -169,4 +169,4 @@ private:
 	XnActualIntProperty m_ActualRead;
 };
 
-#endif //__XN_SENSOR_IMAGE_STREAM_H__
\ No newline at end of file
+#endif //__XN_SENSOR_IMAGE_STREAM_H__
