Blender  V2.59
FilterBlueScreen.cpp
Go to the documentation of this file.
00001 
00004 /* $Id: FilterBlueScreen.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 
00027 #include <PyObjectPlus.h>
00028 #include <structmember.h>
00029 
00030 #include "FilterBlueScreen.h"
00031 
00032 #include "FilterBase.h"
00033 #include "PyTypeList.h"
00034 
00035 // implementation FilterBlueScreen
00036 
00037 // constructor
00038 FilterBlueScreen::FilterBlueScreen (void)
00039 {
00040         // set color to blue
00041         setColor(0, 0, 255);
00042         // set limits
00043         setLimits(64, 64);
00044 }
00045 
00046 // set color
00047 void FilterBlueScreen::setColor (unsigned char red, unsigned char green, unsigned char blue)
00048 {
00049         m_color[0] = red;
00050         m_color[1] = green;
00051         m_color[2] = blue;
00052 }
00053 
00054 // set limits for color variation
00055 void FilterBlueScreen::setLimits (unsigned short minLimit, unsigned short maxLimit)
00056 {
00057         m_limits[0] = minLimit;
00058         m_limits[1] = maxLimit > minLimit ? maxLimit : minLimit;
00059         // calculate square values
00060         for (short idx = 0; idx < 2; ++idx)
00061                 m_squareLimits[idx] = m_limits[idx] * m_limits[idx];
00062         // limits distance
00063         m_limitDist = m_squareLimits[1] - m_squareLimits[0];
00064 }
00065 
00066 
00067 
00068 // cast Filter pointer to FilterBlueScreen
00069 inline FilterBlueScreen * getFilter (PyFilter * self)
00070 { return static_cast<FilterBlueScreen*>(self->m_filter); }
00071 
00072 
00073 // python methods and get/sets
00074 
00075 // get color
00076 static PyObject * getColor (PyFilter * self, void * closure)
00077 {
00078         return Py_BuildValue("[BBB]", getFilter(self)->getColor()[0],
00079                 getFilter(self)->getColor()[1], getFilter(self)->getColor()[2]);
00080 }
00081 
00082 // set color
00083 static int setColor (PyFilter * self, PyObject * value, void * closure)
00084 {
00085         // check validity of parameter
00086         if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 3
00087                 || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
00088                 || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1))
00089                 || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 2)))
00090         {
00091                 PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 3 ints");
00092                 return -1;
00093         }
00094         // set color
00095         getFilter(self)->setColor((unsigned char)(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 0))),
00096                 (unsigned char)(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 1))),
00097                 (unsigned char)(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 2))));
00098         // success
00099         return 0;
00100 }
00101 
00102 // get limits
00103 static PyObject * getLimits (PyFilter * self, void * closure)
00104 {
00105         return Py_BuildValue("[II]", getFilter(self)->getLimits()[0],
00106                 getFilter(self)->getLimits()[1]);
00107 }
00108 
00109 // set limit
00110 static int setLimits (PyFilter * self, PyObject * value, void * closure)
00111 {
00112         // check validity of parameter
00113         if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2
00114                 || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0))
00115                 || !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
00116         {
00117                 PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
00118                 return -1;
00119         }
00120         // set limits
00121         getFilter(self)->setLimits((unsigned short)(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 0))),
00122                 (unsigned short)(PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, 1))));
00123         // success
00124         return 0;
00125 }
00126 
00127 
00128 // attributes structure
00129 static PyGetSetDef filterBSGetSets[] =
00130 { 
00131         {(char*)"color", (getter)getColor, (setter)setColor, (char*)"blue screen color", NULL},
00132         {(char*)"limits", (getter)getLimits, (setter)setLimits, (char*)"blue screen color limits", NULL},
00133         // attributes from FilterBase class
00134         {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
00135         {NULL}
00136 };
00137 
00138 // define python type
00139 PyTypeObject FilterBlueScreenType =
00140 { 
00141         PyVarObject_HEAD_INIT(NULL, 0)
00142         "VideoTexture.FilterBlueScreen",   /*tp_name*/
00143         sizeof(PyFilter),          /*tp_basicsize*/
00144         0,                         /*tp_itemsize*/
00145         (destructor)Filter_dealloc,/*tp_dealloc*/
00146         0,                         /*tp_print*/
00147         0,                         /*tp_getattr*/
00148         0,                         /*tp_setattr*/
00149         0,                         /*tp_compare*/
00150         0,                         /*tp_repr*/
00151         0,                         /*tp_as_number*/
00152         0,                         /*tp_as_sequence*/
00153         0,                         /*tp_as_mapping*/
00154         0,                         /*tp_hash */
00155         0,                         /*tp_call*/
00156         0,                         /*tp_str*/
00157         0,                         /*tp_getattro*/
00158         0,                         /*tp_setattro*/
00159         0,                         /*tp_as_buffer*/
00160         Py_TPFLAGS_DEFAULT,        /*tp_flags*/
00161         "Filter for Blue Screen objects",       /* tp_doc */
00162         0,                             /* tp_traverse */
00163         0,                             /* tp_clear */
00164         0,                             /* tp_richcompare */
00165         0,                             /* tp_weaklistoffset */
00166         0,                             /* tp_iter */
00167         0,                             /* tp_iternext */
00168         NULL,                /* tp_methods */
00169         0,                   /* tp_members */
00170         filterBSGetSets,           /* tp_getset */
00171         0,                         /* tp_base */
00172         0,                         /* tp_dict */
00173         0,                         /* tp_descr_get */
00174         0,                         /* tp_descr_set */
00175         0,                         /* tp_dictoffset */
00176         (initproc)Filter_init<FilterBlueScreen>,     /* tp_init */
00177         0,                         /* tp_alloc */
00178         Filter_allocNew,           /* tp_new */
00179 };
00180