File: depth_images-3.diff

package info (click to toggle)
morse-simulator 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 169,784 kB
  • ctags: 3,593
  • sloc: python: 23,947; ansic: 1,370; cpp: 786; makefile: 120; xml: 34; sh: 7
file content (346 lines) | stat: -rw-r--r-- 11,433 bytes parent folder | download
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
Index: ImageViewport.cpp
===================================================================
--- ImageViewport.cpp	(revision 50470)
+++ ImageViewport.cpp	(working copy)
@@ -1,4 +1,7 @@
-/*
+/** \file gameengine/VideoTexture/ImageViewport.cpp
+ *  \ingroup bgevideotex
+ */
+/* $Id: ImageViewport.cpp 39834 2011-09-01 02:12:53Z campbellbarton $
 -----------------------------------------------------------------------------
 This source file is part of VideoTexture library
 
@@ -20,10 +23,6 @@
 -----------------------------------------------------------------------------
 */
 
-/** \file gameengine/VideoTexture/ImageViewport.cpp
- *  \ingroup bgevideotex
- */
-
 // implementation
 
 #include "PyObjectPlus.h"
@@ -51,13 +50,18 @@
 	//glGetIntegerv(GL_VIEWPORT, m_viewport);
 	// create buffer for viewport image
 	m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]];
+    // create a buffer for depth images
+    m_depthImage = new float[getViewportSize()[0] * getViewportSize()[1]];
 	// set attributes
 	setWhole(false);
 }
 
 // destructor
 ImageViewport::~ImageViewport (void)
-{ delete [] m_viewportImage; }
+{
+    delete [] m_viewportImage;
+    delete [] m_depthImage;
+}
 
 
 // use whole viewport to capture image
@@ -131,17 +135,39 @@
 	}
 	// if texture can be directly created
 	if (texId != 0 && m_pyfilter == NULL && m_capSize[0] == calcSize(m_capSize[0])
-	        && m_capSize[1] == calcSize(m_capSize[1]) && !m_flip)
+	        && m_capSize[1] == calcSize(m_capSize[1]) && !m_flip && !m_zbuff && !m_depth)
 	{
 		// just copy current viewport to texture
-		glBindTexture(GL_TEXTURE_2D, texId);
-		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1]);
-		// image is not available
-		m_avail = false;
+	    glBindTexture(GL_TEXTURE_2D, texId);
+        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1]);
+	    // image is not available
+	    m_avail = false;
 	}
 	// otherwise copy viewport to buffer, if image is not available
 	else if (!m_avail)
 	{
+        if (m_zbuff)
+        {
+            // Use read pixels with the depth buffer
+            glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
+                    GL_DEPTH_COMPONENT, GL_FLOAT, m_depthImage);
+            // filter loaded data
+            FilterZZZA filt;
+            filterImage(filt, m_depthImage, m_capSize);
+        }
+        else
+
+        if (m_depth)
+        {
+            // Use read pixels with the depth buffer
+            glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
+                    GL_DEPTH_COMPONENT, GL_FLOAT, m_depthImage);
+            // filter loaded data
+            FilterDEPTH filt;
+            filterImage(filt, m_depthImage, m_capSize);
+        }
+        else
+
 		// get frame buffer data
 		if (m_alpha)
 		{
@@ -310,6 +336,8 @@
 	{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
 	{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
 	{(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
+	{(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
+	{(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer using unsigned int precision", NULL},
 	{(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
 	{NULL}
 };
Index: ImageRender.cpp
===================================================================
--- ImageRender.cpp	(revision 50470)
+++ ImageRender.cpp	(working copy)
@@ -385,6 +385,8 @@
 	{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
 	{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)",	NULL},
 	{(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
+	{(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
+	{(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer using unsigned int precision", NULL},
 	{(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
 	{NULL}
 };
@@ -547,6 +549,8 @@
 	{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
 	{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)",	NULL},
 	{(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
+	{(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
+	{(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer using unsigned int precision", NULL},
 	{(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
 	{NULL}
 };
Index: ImageBase.h
===================================================================
--- ImageBase.h	(revision 50470)
+++ ImageBase.h	(working copy)
@@ -78,6 +78,14 @@
 	bool getFlip (void) { return m_flip; }
 	/// set vertical flip
 	void setFlip (bool flip) { m_flip = flip; }
+	/// get Z buffer
+	bool getZbuff (void) { return m_zbuff; }
+	/// set Z buffer
+	void setZbuff (bool zbuff) { m_zbuff = zbuff; }
+	/// get depth
+	bool getDepth (void) { return m_depth; }
+	/// set depth
+	void setDepth (bool depth) { m_depth = depth; }
 
 	/// get source object
 	PyImage * getSource (const char * id);
@@ -111,6 +119,10 @@
 	bool m_scaleChange;
 	/// flip image vertically
 	bool m_flip;
+	/// use the Z buffer as a texture
+	bool m_zbuff;
+	/// extract the Z buffer with unisgned int precision
+	bool m_depth;
 
 	/// source image list
 	ImageSourceList m_sources;
@@ -342,6 +354,14 @@
 PyObject * Image_getFlip (PyImage * self, void * closure);
 // set flip
 int Image_setFlip (PyImage * self, PyObject * value, void * closure);
+// get Z buffer
+PyObject * Image_getZbuff (PyImage * self, void * closure);
+// set Z buffer
+int Image_setZbuff (PyImage * self, PyObject * value, void * closure);
+// get depth
+PyObject * Image_getDepth (PyImage * self, void * closure);
+// set depth
+int Image_setDepth (PyImage * self, PyObject * value, void * closure);
 
 // get filter source object
 PyObject * Image_getSource (PyImage * self, PyObject * args);
Index: FilterSource.h
===================================================================
--- FilterSource.h	(revision 50470)
+++ FilterSource.h	(working copy)
@@ -31,7 +31,6 @@
 
 #include "FilterBase.h"
 
-
 /// class for RGB24 conversion
 class FilterRGB24 : public FilterBase
 {
@@ -97,6 +96,73 @@
 	{ VT_RGBA(val,src[2],src[1],src[0],0xFF); return val; }
 };
 
+/// class for Z_buffer conversion
+class FilterZZZA : public FilterBase
+{
+public:
+	/// constructor
+	FilterZZZA (void) {}
+	/// destructor
+	virtual ~FilterZZZA (void) {}
+
+	/// get source pixel size
+	virtual unsigned int getPixelSize (void) { return 1; }
+
+protected:
+	/// filter pixel, source float buffer
+	virtual unsigned int filter (float * src, short x, short y,
+		short * size, unsigned int pixSize, unsigned int val)
+	{
+		// calculate gray value
+        // convert float to unsigned char
+		unsigned int depth = int(src[0] * 255);
+		// return depth scale value
+		VT_R(val) = depth;
+		VT_G(val) = depth;
+		VT_B(val) = depth;
+		VT_A(val) = 0xFF;
+
+		return val;
+	}
+};
+
+
+/// class for Z_buffer conversion
+class FilterDEPTH : public FilterBase
+{
+public:
+	/// constructor
+	FilterDEPTH (void) {}
+	/// destructor
+	virtual ~FilterDEPTH (void) {}
+
+	/// get source pixel size
+	virtual unsigned int getPixelSize (void) { return 1; }
+
+protected:
+	/// filter pixel, source float buffer
+	virtual unsigned int filter (float * src, short x, short y,
+		short * size, unsigned int pixSize, unsigned int val)
+	{
+		// calculate the value multiplying by the limit of a unsigned int (assuming 32 bits)
+        double result = src[0] * 4294967295.0;
+		unsigned int depth = (unsigned int)result;
+        //printf ("src = %f | result = %lf | depth = %u\n", src[0], result, depth);
+
+        // copy the integer value directly into the unsigned int array
+        memcpy(&val, &depth, sizeof (unsigned int));
+
+        /*
+        // Copy the float value straight away
+        memcpy(&val, src, sizeof (unsigned int));
+        */
+		return val;
+	}
+};
+
+
+
+
 /// class for YV12 conversion
 class FilterYV12 : public FilterBase
 {
Index: ImageBase.cpp
===================================================================
--- ImageBase.cpp	(revision 50470)
+++ ImageBase.cpp	(working copy)
@@ -49,6 +49,8 @@
 // constructor
 ImageBase::ImageBase (bool staticSrc) : m_image(NULL), m_imgSize(0),
 m_avail(false), m_scale(false), m_scaleChange(false), m_flip(false),
+m_zbuff(false),
+m_depth(false),
 m_staticSources(staticSrc), m_pyfilter(NULL)
 {
 	m_size[0] = m_size[1] = 0;
@@ -532,7 +534,53 @@
 	return 0;
 }
 
+// get zbuff
+PyObject * Image_getZbuff (PyImage * self, void * closure)
+{
+	if (self->m_image != NULL && self->m_image->getZbuff()) Py_RETURN_TRUE;
+	else Py_RETURN_FALSE;
+}
 
+// set zbuff
+int Image_setZbuff (PyImage * self, PyObject * value, void * closure)
+{
+	// check parameter, report failure
+	if (value == NULL || !PyBool_Check(value))
+	{
+		PyErr_SetString(PyExc_TypeError, "The value must be a bool");
+		return -1;
+	}
+	// set scale
+	if (self->m_image != NULL) self->m_image->setZbuff(value == Py_True);
+	// success
+	return 0;
+}
+
+// get depth
+PyObject * Image_getDepth (PyImage * self, void * closure)
+{
+	if (self->m_image != NULL && self->m_image->getDepth()) Py_RETURN_TRUE;
+	else Py_RETURN_FALSE;
+}
+
+// set depth
+int Image_setDepth (PyImage * self, PyObject * value, void * closure)
+{
+	// check parameter, report failure
+	if (value == NULL || !PyBool_Check(value))
+	{
+		PyErr_SetString(PyExc_TypeError, "The value must be a bool");
+		return -1;
+	}
+	// set scale
+	if (self->m_image != NULL) self->m_image->setDepth(value == Py_True);
+	// success
+	return 0;
+}
+
+
+
+
 // get filter source object
 PyObject * Image_getSource (PyImage * self, PyObject * args)
 {
Index: FilterBase.h
===================================================================
--- FilterBase.h	(revision 50470)
+++ FilterBase.h	(working copy)
@@ -95,6 +95,10 @@
 	virtual unsigned int filter (unsigned int * src, short x, short y,
 		short * size, unsigned int pixSize, unsigned int val = 0)
 	{ return val; }
+	/// filter pixel, source float buffer
+	virtual unsigned int filter (float * src, short x, short y,
+		short * size, unsigned int pixSize, unsigned int val = 0)
+	{ return val; }
 
 	/// get source pixel size
 	virtual unsigned int getPixelSize (void) { return 1; }
Index: ImageViewport.h
===================================================================
--- ImageViewport.h	(revision 50470)
+++ ImageViewport.h	(working copy)
@@ -81,6 +81,8 @@
 
 	/// buffer to copy viewport
 	BYTE * m_viewportImage;
+    /// buffer to copy z buffer images
+    float * m_depthImage;
 	/// texture is initialized
 	bool m_texInit;