Quiet compiler warnings.
[blender-staging.git] / source / gameengine / VideoTexture / VideoBase.cpp
1 /* $Id$
2 -----------------------------------------------------------------------------
3 This source file is part of VideoTexture library
4
5 Copyright (c) 2007 The Zdeno Ash Miklas
6
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
10 version.
11
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.
15
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 -----------------------------------------------------------------------------
21 */
22
23 #if defined WIN32
24 #define WINDOWS_LEAN_AND_MEAN
25 #include <windows.h>
26 #endif
27
28 #include "VideoBase.h"
29
30 #include "FilterSource.h"
31
32 // VideoBase implementation
33
34
35 // initialize image data
36 void VideoBase::init(short width, short height)
37 {
38         // save original sizes
39         m_orgSize[0] = width;
40         m_orgSize[1] = height;
41         // call base class initialization
42         ImageBase::init(width, height);
43 }
44
45
46 // process video frame
47 void VideoBase::process (BYTE * sample)
48 {
49         // if scale was changed
50         if (m_scaleChange)
51                 // reset image
52                 init(m_orgSize[0], m_orgSize[1]);
53         // if image is allocated and is able to store new image
54         if (m_image != NULL && !m_avail)
55         {
56                 // filters used
57                 // convert video format to image
58                 switch (m_format)
59                 {
60                 case RGBA32:
61                         {
62                                 FilterRGBA32 filtRGBA;
63                                 // use filter object for format to convert image
64                                 filterImage(filtRGBA, sample, m_orgSize);
65                                 // finish
66                                 break;
67                         }
68                 case RGB24:
69                         {
70                                 FilterRGB24 filtRGB;
71                                 // use filter object for format to convert image
72                                 filterImage(filtRGB, sample, m_orgSize);
73                                 // finish
74                                 break;
75                         }
76                 case YV12:
77                         {
78                                 // use filter object for format to convert image
79                                 FilterYV12 filtYUV;
80                                 filtYUV.setBuffs(sample, m_orgSize);
81                                 filterImage(filtYUV, sample, m_orgSize);
82                                 // finish
83                                 break;
84                         }
85                 case None:
86                         break; /* assert? */
87                 }
88         }
89 }
90
91
92 // python functions
93
94
95 // exceptions for video source initialization
96 ExceptionID SourceVideoEmpty, SourceVideoCreation;
97 ExpDesc SourceVideoEmptyDesc (SourceVideoEmpty, "Source Video is empty");
98 ExpDesc SourceVideoCreationDesc (SourceVideoCreation, "SourceVideo object was not created");
99
100 // open video source
101 void Video_open (VideoBase * self, char * file, short captureID)
102 {
103         // if file is empty, throw exception
104         if (file == NULL) THRWEXCP(SourceVideoEmpty, S_OK);
105
106         // open video file or capture device
107         if (captureID >= 0) 
108                 self->openCam(file, captureID);
109         else 
110                 self->openFile(file);
111 }
112
113
114 // play video
115 PyObject * Video_play (PyImage * self)
116 { if (getVideo(self)->play()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
117
118 // pause video
119 PyObject * Video_pause (PyImage * self)
120 { if (getVideo(self)->pause()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
121
122 PyObject * Video_stop (PyImage * self)
123 { if (getVideo(self)->stop()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
124
125 // get status
126 PyObject * Video_getStatus (PyImage * self, void * closure)
127 {
128         return Py_BuildValue("h", getVideo(self)->getStatus());
129 }
130
131 // refresh video
132 PyObject * Video_refresh (PyImage * self)
133 {
134         getVideo(self)->refresh();
135         return Video_getStatus(self, NULL);
136 }
137
138
139 // get range
140 PyObject * Video_getRange (PyImage * self, void * closure)
141 {
142         return Py_BuildValue("[ff]", getVideo(self)->getRange()[0],
143                 getVideo(self)->getRange()[1]);
144 }
145
146 // set range
147 int Video_setRange (PyImage * self, PyObject * value, void * closure)
148 {
149         // check validity of parameter
150         if (value == NULL || !PySequence_Check(value) || PySequence_Length(value) != 2
151                 || !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 0))
152                 || !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 1)))
153         {
154                 PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 float");
155                 return -1;
156         }
157         // set range
158         getVideo(self)->setRange(PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0)),
159                 PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1)));
160         // success
161         return 0;
162 }
163
164 // get repeat
165 PyObject * Video_getRepeat (PyImage * self, void * closure)
166 { return Py_BuildValue("h", getVideo(self)->getRepeat()); }
167
168 // set repeat
169 int Video_setRepeat (PyImage * self, PyObject * value, void * closure)
170 {
171         // check validity of parameter
172         if (value == NULL || !PyLong_Check(value))
173         {
174                 PyErr_SetString(PyExc_TypeError, "The value must be an int");
175                 return -1;
176         }
177         // set repeat
178         getVideo(self)->setRepeat(int(PyLong_AsSsize_t(value)));
179         // success
180         return 0;
181 }
182
183 // get frame rate
184 PyObject * Video_getFrameRate (PyImage * self, void * closure)
185 { return Py_BuildValue("f", double(getVideo(self)->getFrameRate())); }
186
187 // set frame rate
188 int Video_setFrameRate (PyImage * self, PyObject * value, void * closure)
189 {
190         // check validity of parameter
191         if (value == NULL || !PyFloat_Check(value))
192         {
193                 PyErr_SetString(PyExc_TypeError, "The value must be a float");
194                 return -1;
195         }
196         // set repeat
197         getVideo(self)->setFrameRate(float(PyFloat_AsDouble(value)));
198         // success
199         return 0;
200 }