Blender V2.61 - r43446

FilterBase.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 
00028 #include "FilterBase.h"
00029 
00030 #include <PyObjectPlus.h>
00031 #include <structmember.h>
00032 
00033 
00034 // FilterBase class implementation
00035 
00036 // constructor
00037 FilterBase::FilterBase (void) : m_previous(NULL) {}
00038 
00039 
00040 // destructor
00041 FilterBase::~FilterBase (void)
00042 {
00043     // release Python objects, if not released yet
00044     release();
00045 }
00046 
00047 
00048 // release python objects
00049 void FilterBase::release (void)
00050 {
00051     // release previous filter object
00052     setPrevious(NULL);
00053 }
00054 
00055 
00056 // set new previous filter
00057 void FilterBase::setPrevious (PyFilter * filt, bool useRefCnt)
00058 {
00059     // if reference counting has to be used
00060     if (useRefCnt)
00061     {
00062         // reference new filter
00063         if (filt != NULL) Py_INCREF(filt);
00064         // release old filter
00065         Py_XDECREF(m_previous);
00066     }
00067     // set new previous filter
00068     m_previous = filt;
00069 }
00070 
00071 
00072 // find first filter
00073 FilterBase * FilterBase::findFirst (void)
00074 {
00075     // find first filter in chain
00076     FilterBase * frst;
00077     for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {};
00078     // set first filter
00079     return frst;
00080 }
00081 
00082 
00083 
00084 // list offilter types
00085 PyTypeList pyFilterTypes;
00086 
00087 
00088 
00089 // functions for python interface
00090 
00091 
00092 // object allocation
00093 PyObject * Filter_allocNew (PyTypeObject * type, PyObject * args, PyObject * kwds)
00094 {
00095     // allocate object
00096     PyFilter * self = reinterpret_cast<PyFilter*>(type->tp_alloc(type, 0));
00097     // initialize object structure
00098     self->m_filter = NULL;
00099     // return allocated object
00100     return reinterpret_cast<PyObject*>(self);
00101 }
00102 
00103 // object deallocation
00104 void Filter_dealloc (PyFilter * self)
00105 {
00106     // release object attributes
00107     if (self->m_filter != NULL)
00108     {
00109         self->m_filter->release();
00110         delete self->m_filter;
00111         self->m_filter = NULL;
00112     }
00113 }
00114 
00115 
00116 // get previous pixel filter object
00117 PyObject * Filter_getPrevious (PyFilter * self, void * closure)
00118 {
00119     // if filter object is available
00120     if (self->m_filter != NULL)
00121     {
00122         // pixel filter object
00123         PyObject * filt = reinterpret_cast<PyObject*>(self->m_filter->getPrevious());
00124         // if filter is present
00125         if (filt != NULL)
00126         {
00127             // return it
00128             Py_INCREF(filt);
00129             return filt;
00130         }
00131     }
00132     // otherwise return none
00133     Py_RETURN_NONE;
00134 }
00135 
00136 
00137 // set previous pixel filter object
00138 int Filter_setPrevious (PyFilter * self, PyObject * value, void * closure)
00139 {
00140     // if filter object is available
00141     if (self->m_filter != NULL)
00142     {
00143         // check new value
00144         if (value == NULL || !pyFilterTypes.in(Py_TYPE(value)))
00145         {
00146             // report value error
00147             PyErr_SetString(PyExc_TypeError, "Invalid type of value");
00148             return -1;
00149         }
00150         // set new value
00151         self->m_filter->setPrevious(reinterpret_cast<PyFilter*>(value));
00152     }
00153     // return success
00154     return 0;
00155 }