2
-----------------------------------------------------------------------------
3
This source file is part of VideoTexture library
5
Copyright (c) 2007 The Zdeno Ash Miklas
7
This program is free software; you can redistribute it and/or modify it under
8
the terms of the GNU Lesser General Public License as published by the Free Software
9
Foundation; either version 2 of the License, or (at your option) any later
12
This program is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License along with
17
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
19
http://www.gnu.org/copyleft/lesser.txt.
20
-----------------------------------------------------------------------------
2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Copyright (c) 2007 The Zdeno Ash Miklas
20
* This source file is part of VideoTexture library
24
* ***** END GPL LICENSE BLOCK *****
23
27
/** \file gameengine/VideoTexture/ImageViewport.cpp
24
28
* \ingroup bgevideotex
124
132
init(m_capSize[0], m_capSize[1]);
125
133
// if texture wasn't initialized
129
136
loadTexture(texId, m_image, m_size);
130
137
m_texInit = true;
132
139
// if texture can be directly created
133
140
if (texId != 0 && m_pyfilter == NULL && m_capSize[0] == calcSize(m_capSize[0])
134
&& m_capSize[1] == calcSize(m_capSize[1]) && !m_flip)
141
&& m_capSize[1] == calcSize(m_capSize[1]) && !m_flip && !m_zbuff && !m_depth)
136
143
// just copy current viewport to texture
137
144
glBindTexture(GL_TEXTURE_2D, texId);
142
149
// otherwise copy viewport to buffer, if image is not available
145
// get frame buffer data
148
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGBA,
149
GL_UNSIGNED_BYTE, m_viewportImage);
152
// Use read pixels with the depth buffer
153
// *** misusing m_viewportImage here, but since it has the correct size
154
// (4 bytes per pixel = size of float) and we just need it to apply
155
// the filter, it's ok
156
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
157
GL_DEPTH_COMPONENT, GL_FLOAT, m_viewportImage);
150
158
// filter loaded data
152
filterImage(filt, m_viewportImage, m_capSize);
160
filterImage(filt, (float *)m_viewportImage, m_capSize);
156
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGB,
157
GL_UNSIGNED_BYTE, m_viewportImage);
158
// filter loaded data
160
filterImage(filt, m_viewportImage, m_capSize);
165
// Use read pixels with the depth buffer
166
// See warning above about m_viewportImage.
167
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
168
GL_DEPTH_COMPONENT, GL_FLOAT, m_viewportImage);
169
// filter loaded data
171
filterImage(filt, (float *)m_viewportImage, m_capSize);
175
// get frame buffer data
177
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGBA,
178
GL_UNSIGNED_BYTE, m_viewportImage);
179
// filter loaded data
181
filterImage(filt, m_viewportImage, m_capSize);
184
glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGB,
185
GL_UNSIGNED_BYTE, m_viewportImage);
186
// filter loaded data
188
filterImage(filt, m_viewportImage, m_capSize);
176
PyObject * ImageViewport_getWhole (PyImage * self, void * closure)
206
PyObject *ImageViewport_getWhole (PyImage *self, void *closure)
178
208
if (self->m_image != NULL && getImageViewport(self)->getWhole()) Py_RETURN_TRUE;
179
209
else Py_RETURN_FALSE;
183
int ImageViewport_setWhole (PyImage * self, PyObject * value, void * closure)
213
int ImageViewport_setWhole (PyImage *self, PyObject *value, void *closure)
185
215
// check parameter, report failure
186
216
if (value == NULL || !PyBool_Check(value))
206
PyObject * ImageViewport_getAlpha (PyImage * self, void * closure)
236
PyObject *ImageViewport_getAlpha (PyImage *self, void *closure)
208
238
if (self->m_image != NULL && getImageViewport(self)->getAlpha()) Py_RETURN_TRUE;
209
239
else Py_RETURN_FALSE;
213
int ImageViewport_setAlpha (PyImage * self, PyObject * value, void * closure)
243
int ImageViewport_setAlpha (PyImage *self, PyObject *value, void *closure)
215
245
// check parameter, report failure
216
246
if (value == NULL || !PyBool_Check(value))
229
static PyObject * ImageViewport_getPosition (PyImage * self, void * closure)
259
static PyObject *ImageViewport_getPosition (PyImage *self, void *closure)
231
return Py_BuildValue("(ii)", getImageViewport(self)->getPosition()[0],
232
getImageViewport(self)->getPosition()[1]);
261
GLint *pos = getImageViewport(self)->getPosition();
262
PyObject *ret = PyTuple_New(2);
263
PyTuple_SET_ITEM(ret, 0, PyLong_FromLong(pos[0]));
264
PyTuple_SET_ITEM(ret, 1, PyLong_FromLong(pos[1]));
236
static int ImageViewport_setPosition (PyImage * self, PyObject * value, void * closure)
269
static int ImageViewport_setPosition (PyImage *self, PyObject *value, void *closure)
238
271
// check validity of parameter
239
if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2
240
|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
241
|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
273
!(PyTuple_Check(value) || PyList_Check(value)) ||
274
PySequence_Fast_GET_SIZE(value) != 2 ||
275
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
276
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
243
278
PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
248
GLint(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 0))),
249
GLint(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 1)))
283
GLint(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
284
GLint(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1)))
251
286
getImageViewport(self)->setPosition(pos);
256
291
// get capture size
257
PyObject * ImageViewport_getCaptureSize (PyImage * self, void * closure)
292
PyObject *ImageViewport_getCaptureSize (PyImage *self, void *closure)
259
return Py_BuildValue("(ii)", getImageViewport(self)->getCaptureSize()[0],
260
getImageViewport(self)->getCaptureSize()[1]);
294
short *size = getImageViewport(self)->getCaptureSize();
295
PyObject *ret = PyTuple_New(2);
296
PyTuple_SET_ITEM(ret, 0, PyLong_FromLong(size[0]));
297
PyTuple_SET_ITEM(ret, 1, PyLong_FromLong(size[1]));
263
301
// set capture size
264
int ImageViewport_setCaptureSize (PyImage * self, PyObject * value, void * closure)
302
int ImageViewport_setCaptureSize (PyImage *self, PyObject *value, void *closure)
266
304
// check validity of parameter
267
if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2
268
|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
269
|| !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
306
!(PyTuple_Check(value) || PyList_Check(value)) ||
307
PySequence_Fast_GET_SIZE(value) != 2 ||
308
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
309
!PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
271
311
PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
274
314
// set capture size
276
short(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 0))),
277
short(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 1)))
316
short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
317
short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1)))
310
350
{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
311
351
{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
312
352
{(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
353
{(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
354
{(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer as array of float", NULL},
313
355
{(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},