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 FILTERBASE_H 00028 #define FILTERBASE_H 00029 00030 #include "Common.h" 00031 00032 #include <PyObjectPlus.h> 00033 00034 #include "PyTypeList.h" 00035 00036 #define VT_C(v,idx) ((unsigned char*)&v)[idx] 00037 #define VT_R(v) ((unsigned char*)&v)[0] 00038 #define VT_G(v) ((unsigned char*)&v)[1] 00039 #define VT_B(v) ((unsigned char*)&v)[2] 00040 #define VT_A(v) ((unsigned char*)&v)[3] 00041 #define VT_RGBA(v,r,g,b,a) VT_R(v)=(unsigned char)r, VT_G(v)=(unsigned char)g, VT_B(v)=(unsigned char)b, VT_A(v)=(unsigned char)a 00042 00043 // forward declaration 00044 class FilterBase; 00045 00046 00047 // python structure for filter 00048 struct PyFilter 00049 { 00050 PyObject_HEAD 00051 // source object 00052 FilterBase * m_filter; 00053 }; 00054 00055 00057 class FilterBase 00058 { 00059 public: 00061 FilterBase (void); 00063 virtual ~FilterBase (void); 00064 // release python objects 00065 virtual void release (void); 00066 00068 template <class SRC> unsigned int convert (SRC src, short x, short y, 00069 short * size, unsigned int pixSize) 00070 { 00071 return filter(src, x, y, size, pixSize, 00072 convertPrevious(src, x, y, size, pixSize)); 00073 } 00074 00076 PyFilter * getPrevious (void) { return m_previous; } 00078 void setPrevious (PyFilter * filt, bool useRefCnt = true); 00079 00081 FilterBase * findFirst (void); 00082 00084 unsigned int firstPixelSize (void) { return findFirst()->getPixelSize(); } 00085 00086 protected: 00088 PyFilter * m_previous; 00089 00091 virtual unsigned int filter (unsigned char * src, short x, short y, 00092 short * size, unsigned int pixSize, unsigned int val = 0) 00093 { return val; } 00095 virtual unsigned int filter (unsigned int * src, short x, short y, 00096 short * size, unsigned int pixSize, unsigned int val = 0) 00097 { return val; } 00098 00100 virtual unsigned int getPixelSize (void) { return 1; } 00101 00103 template <class SRC> unsigned int convertPrevious (SRC src, short x, short y, 00104 short * size, unsigned int pixSize) 00105 { 00106 // if previous filter doesn't exists, return source pixel 00107 if (m_previous == NULL) return *src; 00108 // otherwise return converted pixel 00109 return m_previous->m_filter->convert(src, x, y, size, pixSize); 00110 } 00111 }; 00112 00113 00114 // list of python filter types 00115 extern PyTypeList pyFilterTypes; 00116 00117 00118 // functions for python interface 00119 00120 // object initialization 00121 template <class T> static int Filter_init (PyObject * pySelf, PyObject * args, PyObject * kwds) 00122 { 00123 PyFilter * self = reinterpret_cast<PyFilter*>(pySelf); 00124 // create filter object 00125 if (self->m_filter != NULL) delete self->m_filter; 00126 self->m_filter = new T(); 00127 // initialization succeded 00128 return 0; 00129 } 00130 00131 // object allocation 00132 PyObject * Filter_allocNew (PyTypeObject * type, PyObject * args, PyObject * kwds); 00133 // object deallocation 00134 void Filter_dealloc (PyFilter * self); 00135 00136 // get previous pixel filter object 00137 PyObject * Filter_getPrevious (PyFilter * self, void * closure); 00138 // set previous pixel filter object 00139 int Filter_setPrevious (PyFilter * self, PyObject * value, void * closure); 00140 00141 00142 #endif