Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FilterBase.cpp « VideoTexture « gameengine « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b41a20958904f4ff7079ccb2e6e8014010cda989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software  Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Copyright (c) 2007 The Zdeno Ash Miklas
 *
 * This source file is part of VideoTexture library
 *
 * Contributor(s):
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file gameengine/VideoTexture/FilterBase.cpp
 *  \ingroup bgevideotex
 */


#include "FilterBase.h"

#include "EXP_PyObjectPlus.h"
#include <structmember.h>


// FilterBase class implementation

// constructor
FilterBase::FilterBase (void) : m_previous(NULL) {}


// destructor
FilterBase::~FilterBase (void)
{
	// release Python objects, if not released yet
	release();
}


// release python objects
void FilterBase::release (void)
{
	// release previous filter object
	setPrevious(NULL);
}


// set new previous filter
void FilterBase::setPrevious(PyFilter *filt, bool useRefCnt)
{
	// if reference counting has to be used
	if (useRefCnt)
	{
		// reference new filter
		if (filt != NULL) Py_INCREF(filt);
		// release old filter
		Py_XDECREF(m_previous);
	}
	// set new previous filter
	m_previous = filt;
}


// find first filter
FilterBase * FilterBase::findFirst (void)
{
	// find first filter in chain
	FilterBase * frst;
	for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {};
	// set first filter
	return frst;
}



// list offilter types
PyTypeList pyFilterTypes;



// functions for python interface


// object allocation
PyObject *Filter_allocNew (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	// allocate object
	PyFilter *self = reinterpret_cast<PyFilter*>(type->tp_alloc(type, 0));
	// initialize object structure
	self->m_filter = NULL;
	// return allocated object
	return reinterpret_cast<PyObject*>(self);
}

// object deallocation
void Filter_dealloc(PyFilter *self)
{
	// release object attributes
	if (self->m_filter != NULL)
	{
		self->m_filter->release();
		delete self->m_filter;
		self->m_filter = NULL;
	}
	Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
}


// get previous pixel filter object
PyObject *Filter_getPrevious (PyFilter *self, void *closure)
{
	// if filter object is available
	if (self->m_filter != NULL)
	{
		// pixel filter object
		PyObject *filt = reinterpret_cast<PyObject*>(self->m_filter->getPrevious());
		// if filter is present
		if (filt != NULL)
		{
			// return it
			Py_INCREF(filt);
			return filt;
		}
	}
	// otherwise return none
	Py_RETURN_NONE;
}


// set previous pixel filter object
int Filter_setPrevious(PyFilter *self, PyObject *value, void *closure)
{
	// if filter object is available
	if (self->m_filter != NULL)
	{
		// check new value
		if (value == NULL || !pyFilterTypes.in(Py_TYPE(value)))
		{
			// report value error
			PyErr_SetString(PyExc_TypeError, "Invalid type of value");
			return -1;
		}
		// set new value
		self->m_filter->setPrevious(reinterpret_cast<PyFilter*>(value));
	}
	// return success
	return 0;
}