Blender V2.61 - r43446

VideoBase.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of VideoTexture library
00004 
00005 Copyright (c) 2007 The Zdeno Ash Miklas
00006 
00007 This program is free software; you can redistribute it and/or modify it under
00008 the terms of the GNU Lesser General Public License as published by the Free Software
00009 Foundation; either version 2 of the License, or (at your option) any later
00010 version.
00011 
00012 This program is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License along with
00017 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00018 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00019 http://www.gnu.org/copyleft/lesser.txt.
00020 -----------------------------------------------------------------------------
00021 */
00022 
00027 #if defined WIN32
00028 #define WINDOWS_LEAN_AND_MEAN
00029 #include <windows.h>
00030 #endif
00031 
00032 #include "VideoBase.h"
00033 
00034 #include "FilterSource.h"
00035 
00036 // VideoBase implementation
00037 
00038 
00039 // initialize image data
00040 void VideoBase::init(short width, short height)
00041 {
00042     // save original sizes
00043     m_orgSize[0] = width;
00044     m_orgSize[1] = height;
00045     // call base class initialization
00046     ImageBase::init(width, height);
00047 }
00048 
00049 
00050 // process video frame
00051 void VideoBase::process (BYTE * sample)
00052 {
00053     // if scale was changed
00054     if (m_scaleChange)
00055         // reset image
00056         init(m_orgSize[0], m_orgSize[1]);
00057     // if image is allocated and is able to store new image
00058     if (m_image != NULL && !m_avail)
00059     {
00060         // filters used
00061         // convert video format to image
00062         switch (m_format)
00063         {
00064         case RGBA32:
00065             {
00066                 FilterRGBA32 filtRGBA;
00067                 // use filter object for format to convert image
00068                 filterImage(filtRGBA, sample, m_orgSize);
00069                 // finish
00070                 break;
00071             }
00072         case RGB24:
00073             {
00074                 FilterRGB24 filtRGB;
00075                 // use filter object for format to convert image
00076                 filterImage(filtRGB, sample, m_orgSize);
00077                 // finish
00078                 break;
00079             }
00080         case YV12:
00081             {
00082                 // use filter object for format to convert image
00083                 FilterYV12 filtYUV;
00084                 filtYUV.setBuffs(sample, m_orgSize);
00085                 filterImage(filtYUV, sample, m_orgSize);
00086                 // finish
00087                 break;
00088             }
00089         case None:
00090             break; /* assert? */
00091         }
00092     }
00093 }
00094 
00095 
00096 // python functions
00097 
00098 
00099 // exceptions for video source initialization
00100 ExceptionID SourceVideoEmpty, SourceVideoCreation;
00101 ExpDesc SourceVideoEmptyDesc (SourceVideoEmpty, "Source Video is empty");
00102 ExpDesc SourceVideoCreationDesc (SourceVideoCreation, "SourceVideo object was not created");
00103 
00104 // open video source
00105 void Video_open (VideoBase * self, char * file, short captureID)
00106 {
00107     // if file is empty, throw exception
00108     if (file == NULL) THRWEXCP(SourceVideoEmpty, S_OK);
00109 
00110     // open video file or capture device
00111     if (captureID >= 0) 
00112         self->openCam(file, captureID);
00113     else 
00114         self->openFile(file);
00115 }
00116 
00117 
00118 // play video
00119 PyObject * Video_play (PyImage * self)
00120 { if (getVideo(self)->play()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
00121 
00122 // pause video
00123 PyObject * Video_pause (PyImage * self)
00124 { if (getVideo(self)->pause()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
00125 
00126 PyObject * Video_stop (PyImage * self)
00127 { if (getVideo(self)->stop()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
00128 
00129 // get status
00130 PyObject * Video_getStatus (PyImage * self, void * closure)
00131 {
00132     return Py_BuildValue("h", getVideo(self)->getStatus());
00133 }
00134 
00135 // refresh video
00136 PyObject * Video_refresh (PyImage * self)
00137 {
00138     getVideo(self)->refresh();
00139     return Video_getStatus(self, NULL);
00140 }
00141 
00142 
00143 // get range
00144 PyObject * Video_getRange (PyImage * self, void * closure)
00145 {
00146     return Py_BuildValue("[ff]", getVideo(self)->getRange()[0],
00147         getVideo(self)->getRange()[1]);
00148 }
00149 
00150 // set range
00151 int Video_setRange (PyImage * self, PyObject * value, void * closure)
00152 {
00153     // check validity of parameter
00154     if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2
00155         || !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 0))
00156         || !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 1)))
00157     {
00158         PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 float");
00159         return -1;
00160     }
00161     // set range
00162     getVideo(self)->setRange(PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0)),
00163         PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1)));
00164     // success
00165     return 0;
00166 }
00167 
00168 // get repeat
00169 PyObject * Video_getRepeat (PyImage * self, void * closure)
00170 { return Py_BuildValue("h", getVideo(self)->getRepeat()); }
00171 
00172 // set repeat
00173 int Video_setRepeat (PyImage * self, PyObject * value, void * closure)
00174 {
00175     // check validity of parameter
00176     if (value == NULL || !PyLong_Check(value))
00177     {
00178         PyErr_SetString(PyExc_TypeError, "The value must be an int");
00179         return -1;
00180     }
00181     // set repeat
00182     getVideo(self)->setRepeat(int(PyLong_AsSsize_t(value)));
00183     // success
00184     return 0;
00185 }
00186 
00187 // get frame rate
00188 PyObject * Video_getFrameRate (PyImage * self, void * closure)
00189 { return Py_BuildValue("f", double(getVideo(self)->getFrameRate())); }
00190 
00191 // set frame rate
00192 int Video_setFrameRate (PyImage * self, PyObject * value, void * closure)
00193 {
00194     // check validity of parameter
00195     if (value == NULL || !PyFloat_Check(value))
00196     {
00197         PyErr_SetString(PyExc_TypeError, "The value must be a float");
00198         return -1;
00199     }
00200     // set repeat
00201     getVideo(self)->setFrameRate(float(PyFloat_AsDouble(value)));
00202     // success
00203     return 0;
00204 }