Blender V2.61 - r43446
|
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 VIDEOBASE_H 00028 #define VIDEOBASE_H 00029 00030 00031 #include <PyObjectPlus.h> 00032 00033 #include "ImageBase.h" 00034 00035 #include "Exception.h" 00036 00037 // source states 00038 const int SourceError = -1; 00039 const int SourceEmpty = 0; 00040 const int SourceReady = 1; 00041 const int SourcePlaying = 2; 00042 const int SourceStopped = 3; 00043 00044 00045 // video source formats 00046 enum VideoFormat { None, RGB24, YV12, RGBA32 }; 00047 00048 00050 class VideoBase : public ImageBase 00051 { 00052 public: 00054 VideoBase (void) : ImageBase(true), m_format(None), m_status(SourceEmpty), 00055 m_repeat(0), m_frameRate(1.0) 00056 { 00057 m_orgSize[0] = m_orgSize[1] = 0; 00058 m_range[0] = m_range[1] = 0.0; 00059 } 00060 00062 virtual ~VideoBase (void) {} 00063 00065 virtual void openFile (char * file) 00066 { 00067 m_isFile = true; 00068 m_status = SourceReady; 00069 } 00071 virtual void openCam (char * file, short camIdx) 00072 { 00073 m_isFile = false; 00074 m_status = SourceReady; 00075 } 00076 00078 virtual bool play (void) 00079 { 00080 if (m_status == SourceReady || m_status == SourceStopped) 00081 { 00082 m_status = SourcePlaying; 00083 return true; 00084 } 00085 return false; 00086 } 00088 virtual bool pause (void) 00089 { 00090 if (m_status == SourcePlaying) 00091 { 00092 m_status = SourceStopped; 00093 return true; 00094 } 00095 return false; 00096 } 00098 virtual bool stop (void) 00099 { 00100 if (m_status == SourcePlaying) 00101 { 00102 m_status = SourceStopped; 00103 return true; 00104 } 00105 return false; 00106 } 00107 00108 // get video status 00109 int getStatus (void) { return m_status; } 00110 00112 const double * getRange (void) { return m_range; } 00114 virtual void setRange (double start, double stop) 00115 { 00116 if (m_isFile) 00117 { 00118 m_range[0] = start; 00119 m_range[1] = stop; 00120 } 00121 } 00122 00123 // get video repeat 00124 int getRepeat (void) { return m_repeat; } 00126 virtual void setRepeat (int rep) 00127 { if (m_isFile) m_repeat = rep; } 00128 00130 float getFrameRate (void) { return m_frameRate; } 00132 virtual void setFrameRate (float rate) 00133 { if (m_isFile) m_frameRate = rate > 0.0 ? rate : 1.0f; } 00134 00135 protected: 00137 VideoFormat m_format; 00139 short m_orgSize[2]; 00140 00142 int m_status; 00143 00145 bool m_isFile; 00146 00148 double m_range[2]; 00150 int m_repeat; 00152 float m_frameRate; 00153 00155 void init (short width, short height); 00156 00158 void process (BYTE * sample); 00159 }; 00160 00161 00162 00163 // python fuctions 00164 00165 00166 // cast Image pointer to Video 00167 inline VideoBase * getVideo (PyImage * self) 00168 { return static_cast<VideoBase*>(self->m_image); } 00169 00170 00171 extern ExceptionID SourceVideoCreation; 00172 00173 // object initialization 00174 template <class T> void Video_init (PyImage * self) 00175 { 00176 // create source video object 00177 if (self->m_image != NULL) delete self->m_image; 00178 HRESULT hRslt = S_OK; 00179 self->m_image = new T(&hRslt); 00180 CHCKHRSLT(hRslt, SourceVideoCreation); 00181 } 00182 00183 00184 // video functions 00185 void Video_open (VideoBase * self, char * file, short captureID); 00186 PyObject * Video_play (PyImage * self); 00187 PyObject * Video_pause (PyImage * self); 00188 PyObject * Video_stop (PyImage * self); 00189 PyObject * Video_refresh (PyImage * self); 00190 PyObject * Video_getStatus (PyImage * self, void * closure); 00191 PyObject * Video_getRange (PyImage * self, void * closure); 00192 int Video_setRange (PyImage * self, PyObject * value, void * closure); 00193 PyObject * Video_getRepeat (PyImage * self, void * closure); 00194 int Video_setRepeat (PyImage * self, PyObject * value, void * closure); 00195 PyObject * Video_getFrameRate (PyImage * self, void * closure); 00196 int Video_setFrameRate (PyImage * self, PyObject * value, void * closure); 00197 00198 00199 #endif 00200