2 -----------------------------------------------------------------------------
3 This source file is part of VideoTexture library
5 Copyright (c) 2007 The Zdeno Ash Miklas
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the Free Software
9 Foundation; either version 2 of the License, or (at your option) any later
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
19 http://www.gnu.org/copyleft/lesser.txt.
20 -----------------------------------------------------------------------------
23 #if !defined FILTERBASE_H
30 #include "PyTypeList.h"
33 // forward declaration
37 // python structure for filter
42 FilterBase * m_filter;
46 /// base class for pixel filters
53 virtual ~FilterBase (void);
54 // release python objects
55 virtual void release (void);
58 template <class SRC> unsigned int convert (SRC src, short x, short y,
59 short * size, unsigned int pixSize)
61 return filter(src, x, y, size, pixSize,
62 convertPrevious(src, x, y, size, pixSize));
65 /// get previous filter
66 PyFilter * getPrevious (void) { return m_previous; }
67 /// set previous filter
68 void setPrevious (PyFilter * filt, bool useRefCnt = true);
70 /// find first filter in chain
71 FilterBase * findFirst (void);
73 /// get first filter's source pixel size
74 unsigned int firstPixelSize (void) { return findFirst()->getPixelSize(); }
77 /// previous pixel filter
78 PyFilter * m_previous;
80 /// filter pixel, source byte buffer
81 virtual unsigned int filter (unsigned char * src, short x, short y,
82 short * size, unsigned int pixSize, unsigned int val = 0)
84 /// filter pixel, source int buffer
85 virtual unsigned int filter (unsigned int * src, short x, short y,
86 short * size, unsigned int pixSize, unsigned int val = 0)
89 /// get source pixel size
90 virtual unsigned int getPixelSize (void) { return 1; }
92 /// get converted pixel from previous filters
93 template <class SRC> unsigned int convertPrevious (SRC src, short x, short y,
94 short * size, unsigned int pixSize)
96 // if previous filter doesn't exists, return source pixel
97 if (m_previous == NULL) return *src;
98 // otherwise return converted pixel
99 return m_previous->m_filter->convert(src, x, y, size, pixSize);
104 // list of python filter types
105 extern PyTypeList pyFilterTypes;
108 // functions for python interface
110 // object initialization
111 template <class T> static int Filter_init (PyObject * pySelf, PyObject * args, PyObject * kwds)
113 PyFilter * self = reinterpret_cast<PyFilter*>(pySelf);
114 // create filter object
115 if (self->m_filter != NULL) delete self->m_filter;
116 self->m_filter = new T();
117 // initialization succeded
122 PyObject * Filter_allocNew (PyTypeObject * type, PyObject * args, PyObject * kwds);
123 // object deallocation
124 void Filter_dealloc (PyFilter * self);
126 // get previous pixel filter object
127 PyObject * Filter_getPrevious (PyFilter * self, void * closure);
128 // set previous pixel filter object
129 int Filter_setPrevious (PyFilter * self, PyObject * value, void * closure);