|
Blender
V2.59
|
00001 00004 /* $Id: FilterBase.cpp 35176 2011-02-25 13:39:34Z jesterking $ 00005 ----------------------------------------------------------------------------- 00006 This source file is part of VideoTexture library 00007 00008 Copyright (c) 2007 The Zdeno Ash Miklas 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include "FilterBase.h" 00027 00028 #include <PyObjectPlus.h> 00029 #include <structmember.h> 00030 00031 00032 // FilterBase class implementation 00033 00034 // constructor 00035 FilterBase::FilterBase (void) : m_previous(NULL) {} 00036 00037 00038 // destructor 00039 FilterBase::~FilterBase (void) 00040 { 00041 // release Python objects, if not released yet 00042 release(); 00043 } 00044 00045 00046 // release python objects 00047 void FilterBase::release (void) 00048 { 00049 // release previous filter object 00050 setPrevious(NULL); 00051 } 00052 00053 00054 // set new previous filter 00055 void FilterBase::setPrevious (PyFilter * filt, bool useRefCnt) 00056 { 00057 // if reference counting has to be used 00058 if (useRefCnt) 00059 { 00060 // reference new filter 00061 if (filt != NULL) Py_INCREF(filt); 00062 // release old filter 00063 Py_XDECREF(m_previous); 00064 } 00065 // set new previous filter 00066 m_previous = filt; 00067 } 00068 00069 00070 // find first filter 00071 FilterBase * FilterBase::findFirst (void) 00072 { 00073 // find first filter in chain 00074 FilterBase * frst; 00075 for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {}; 00076 // set first filter 00077 return frst; 00078 } 00079 00080 00081 00082 // list offilter types 00083 PyTypeList pyFilterTypes; 00084 00085 00086 00087 // functions for python interface 00088 00089 00090 // object allocation 00091 PyObject * Filter_allocNew (PyTypeObject * type, PyObject * args, PyObject * kwds) 00092 { 00093 // allocate object 00094 PyFilter * self = reinterpret_cast<PyFilter*>(type->tp_alloc(type, 0)); 00095 // initialize object structure 00096 self->m_filter = NULL; 00097 // return allocated object 00098 return reinterpret_cast<PyObject*>(self); 00099 } 00100 00101 // object deallocation 00102 void Filter_dealloc (PyFilter * self) 00103 { 00104 // release object attributes 00105 if (self->m_filter != NULL) 00106 { 00107 self->m_filter->release(); 00108 delete self->m_filter; 00109 self->m_filter = NULL; 00110 } 00111 } 00112 00113 00114 // get previous pixel filter object 00115 PyObject * Filter_getPrevious (PyFilter * self, void * closure) 00116 { 00117 // if filter object is available 00118 if (self->m_filter != NULL) 00119 { 00120 // pixel filter object 00121 PyObject * filt = reinterpret_cast<PyObject*>(self->m_filter->getPrevious()); 00122 // if filter is present 00123 if (filt != NULL) 00124 { 00125 // return it 00126 Py_INCREF(filt); 00127 return filt; 00128 } 00129 } 00130 // otherwise return none 00131 Py_RETURN_NONE; 00132 } 00133 00134 00135 // set previous pixel filter object 00136 int Filter_setPrevious (PyFilter * self, PyObject * value, void * closure) 00137 { 00138 // if filter object is available 00139 if (self->m_filter != NULL) 00140 { 00141 // check new value 00142 if (value == NULL || !pyFilterTypes.in(value->ob_type)) 00143 { 00144 // report value error 00145 PyErr_SetString(PyExc_TypeError, "Invalid type of value"); 00146 return -1; 00147 } 00148 // set new value 00149 self->m_filter->setPrevious(reinterpret_cast<PyFilter*>(value)); 00150 } 00151 // return success 00152 return 0; 00153 }