File: XnBackwardsCompatibility36.cpp

package info (click to toggle)
openni-sensor-pointclouds 5.1.0.41.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,656 kB
  • sloc: cpp: 34,881; ansic: 14,901; sh: 249; python: 155; makefile: 93; xml: 8
file content (243 lines) | stat: -rw-r--r-- 7,785 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/****************************************************************************
*                                                                           *
*  PrimeSense Sensor 5.x Alpha                                              *
*  Copyright (C) 2011 PrimeSense Ltd.                                       *
*                                                                           *
*  This file is part of PrimeSense Sensor.                                  *
*                                                                           *
*  PrimeSense Sensor is free software: you can redistribute it and/or modify*
*  it under the terms of the GNU Lesser General Public License as published *
*  by the Free Software Foundation, either version 3 of the License, or     *
*  (at your option) any later version.                                      *
*                                                                           *
*  PrimeSense Sensor is distributed in the hope that it will be useful,     *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
*  GNU Lesser General Public License for more details.                      *
*                                                                           *
*  You should have received a copy of the GNU Lesser General Public License *
*  along with PrimeSense Sensor. If not, see <http://www.gnu.org/licenses/>.*
*                                                                           *
****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnBackwardsCompatibility36.h"
#include <XnFormatsStatus.h>
#include <XnLog.h>

//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XnStatus XnBCDepthFormatToOutputFormat(XnStreamDepthFormat nDepthFormat, XnOutputFormats* pnOutputFormat)
{
	switch (nDepthFormat)
	{
	case XN_DEPTH_FORMAT_RAW10:
	case XN_DEPTH_FORMAT_RAW12:
		*pnOutputFormat = XN_OUTPUT_FORMAT_DEPTH_VALUES;
		break;
	case XN_DEPTH_FORMAT_SHIFTS:
		*pnOutputFormat = XN_OUTPUT_FORMAT_SHIFT_VALUES;
		break;
	default:
		XN_LOG_ERROR_RETURN(XN_STATUS_IO_INVALID_STREAM_DEPTH_FORMAT, XN_MASK_DDK, "Failed to translate depth format %d to output format!", nDepthFormat);
	}

	return (XN_STATUS_OK);
}

XnStatus XnBCOutputFormatToDepthFormat(XnOutputFormats nOutputFormat, XnStreamDepthFormat* pnDepthFormat)
{
	switch (nOutputFormat)
	{
	case XN_OUTPUT_FORMAT_DEPTH_VALUES:
		*pnDepthFormat = XN_DEPTH_FORMAT_RAW12;
		break;
	case XN_OUTPUT_FORMAT_SHIFT_VALUES:
		*pnDepthFormat = XN_DEPTH_FORMAT_SHIFTS;
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_INVALID_STREAM_DEPTH_FORMAT, XN_MASK_DDK, "Failed to translate output format %d to depth format!", nOutputFormat);
	}

	return(XN_STATUS_OK);
}

XnStatus XnBCImageFormatToOutputFormat(XnStreamImageFormat nImageFormat, XnOutputFormats* pnOutputFormat)
{
	switch (nImageFormat)
	{
	case XN_IMAGE_FORMAT_GRAYSCALE8:
		*pnOutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8;
		break;
	case XN_IMAGE_FORMAT_RGB24:
		*pnOutputFormat = XN_OUTPUT_FORMAT_RGB24;
		break;
	case XN_IMAGE_FORMAT_YUV422:
		*pnOutputFormat = XN_OUTPUT_FORMAT_YUV422;
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_INVALID_STREAM_IMAGE_FORMAT, XN_MASK_DDK, "Failed to translate image format %d to output format!", nImageFormat);
	}

	return(XN_STATUS_OK);
}

XnStatus XnBCOutputFormatToImageFormat(XnOutputFormats nOutputFormat, XnStreamImageFormat* pnImageFormat)
{
	switch (nOutputFormat)
	{
	case XN_OUTPUT_FORMAT_GRAYSCALE8:
		*pnImageFormat = XN_IMAGE_FORMAT_GRAYSCALE8;
		break;
	case XN_OUTPUT_FORMAT_RGB24:
		*pnImageFormat = XN_IMAGE_FORMAT_RGB24;
		break;
	case XN_OUTPUT_FORMAT_YUV422:
		*pnImageFormat = XN_IMAGE_FORMAT_YUV422;
		break;
	case XN_OUTPUT_FORMAT_GRAYSCALE16:
		*pnImageFormat = (XnStreamImageFormat)-1;
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_INVALID_STREAM_IMAGE_FORMAT, XN_MASK_DDK, "Failed to translate output format %d to image format!", nOutputFormat);
	}

	return (XN_STATUS_OK);
}

XnStatus XnBCAudioFormatToOutputFormat(XnStreamAudioFormat nAudioFormat, XnOutputFormats* pnOutputFormat)
{
	switch (nAudioFormat)
	{
	case XN_AUDIO_FORMAT_PCM:
		*pnOutputFormat = XN_OUTPUT_FORMAT_PCM;
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_INVALID_STREAM_IMAGE_FORMAT, XN_MASK_DDK, "Failed to translate audio format %d to output format!", nAudioFormat);
	}

	return (XN_STATUS_OK);
}

XnStatus XnBCOutputFormatToAudioFormat(XnOutputFormats nOutputFormat, XnStreamAudioFormat* pnAudioFormat)
{
	switch (nOutputFormat)
	{
	case XN_OUTPUT_FORMAT_PCM:
		*pnAudioFormat = XN_AUDIO_FORMAT_PCM;
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_INVALID_STREAM_IMAGE_FORMAT, XN_MASK_DDK, "Failed to translate audio format %d to output format!", nOutputFormat);
	}

	return (XN_STATUS_OK);
}

XnStreamDepthFormat XnBCGetStreamDepthFormatFromString(const XnChar* cpDepthFormat)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	if (cpDepthFormat == NULL)
	{
		return ((XnStreamDepthFormat)-1);
	}

	// Convert each string into the proper depth format enum
	if (strcmp(cpDepthFormat, "Raw12") == 0)
	{
		return (XN_DEPTH_FORMAT_RAW12);
	}
	else if (strcmp(cpDepthFormat, "Raw10") == 0)
	{
		return (XN_DEPTH_FORMAT_RAW10);
	}
	else if (strcmp(cpDepthFormat, "Shifts") == 0)
	{
		return (XN_DEPTH_FORMAT_SHIFTS);
	}
	else if (strcmp(cpDepthFormat, "Disabled") == 0)
	{
		return (XN_DEPTH_FORMAT_DISABLED);
	}

	// Unknown mode...
	return ((XnStreamDepthFormat)-1);
}

XnStreamImageFormat XnBCGetStreamImageFormatFromString(const XnChar* cpImageFormat)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	if (cpImageFormat == NULL)
	{
		return ((XnStreamImageFormat)-1);
	}

	// Convert each string into the proper image format enum
	if (strcmp(cpImageFormat, "RGB24") == 0)
	{
		return (XN_IMAGE_FORMAT_RGB24);
	}
	else if (strcmp(cpImageFormat, "Gray8") == 0)
	{
		return (XN_IMAGE_FORMAT_GRAYSCALE8);
	}
	else if (strcmp(cpImageFormat, "YUV422") == 0)
	{
		return (XN_IMAGE_FORMAT_YUV422);
	}
	else if (strcmp(cpImageFormat, "Disabled") == 0)
	{
		return (XN_IMAGE_FORMAT_DISABLED);
	}

	// Unknown mode...
	return ((XnStreamImageFormat)-1);
}

XnStreamAudioFormat XnBCGetStreamAudioFormatFromString(const XnChar* cpAudioFormat)
{
	// Validate the input/output pointers (to make sure none of them is NULL)
	if (cpAudioFormat == NULL)
	{
		return ((XnStreamAudioFormat)-1);
	}

	// Convert each string into the proper image format enum
	if (strcmp(cpAudioFormat, "PCM") == 0)
	{
		return (XN_AUDIO_FORMAT_PCM);
	}
	else if (strcmp(cpAudioFormat, "Disabled") == 0)
	{
		return (XN_AUDIO_FORMAT_DISABLED);
	}

	// Unknown mode...
	return ((XnStreamAudioFormat)-1);
}

XN_STREAM_FLAGS_TYPE XnBCGetStreamFlagsFromString(XnChar* cpStreamFlags)
{
	// Local function variables
	XnChar* cpToken = NULL;
	XN_STREAM_FLAGS_TYPE StreamFlags = 0;

	cpToken = strtok (cpStreamFlags, ";");
	while (cpToken != NULL)
	{
		if (strcmp(cpToken, "Mirror") == 0)
		{
			StreamFlags |= XN_STREAM_FLAG_MIRROR;
		}
		else
		{
			return ((XN_STREAM_FLAGS_TYPE)-1);
		}

		cpToken = strtok (NULL, ";");
	}

	// All is good...
	return (StreamFlags);
}