PageRenderTime 73ms CodeModel.GetById 54ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/pyglue/PyLook.cpp

http://github.com/imageworks/OpenColorIO
C++ | 303 lines | 235 code | 33 blank | 35 comment | 8 complexity | 13a2a4b46e31b9944c262a561f77fc42 MD5 | raw file
  1/*
  2Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
  3All Rights Reserved.
  4
  5Redistribution and use in source and binary forms, with or without
  6modification, are permitted provided that the following conditions are
  7met:
  8* Redistributions of source code must retain the above copyright
  9  notice, this list of conditions and the following disclaimer.
 10* Redistributions in binary form must reproduce the above copyright
 11  notice, this list of conditions and the following disclaimer in the
 12  documentation and/or other materials provided with the distribution.
 13* Neither the name of Sony Pictures Imageworks nor the names of its
 14  contributors may be used to endorse or promote products derived from
 15  this software without specific prior written permission.
 16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 20OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27*/
 28
 29#include <Python.h>
 30#include <OpenColorIO/OpenColorIO.h>
 31
 32#include "PyUtil.h"
 33#include "PyDoc.h"
 34
 35OCIO_NAMESPACE_ENTER
 36{
 37    
 38    PyObject * BuildConstPyLook(ConstLookRcPtr look)
 39    {
 40        return BuildConstPyOCIO<PyOCIO_Look, LookRcPtr,
 41            ConstLookRcPtr>(look, PyOCIO_LookType);
 42    }
 43    
 44    PyObject * BuildEditablePyLook(LookRcPtr look)
 45    {
 46        return BuildEditablePyOCIO<PyOCIO_Look, LookRcPtr,
 47            ConstLookRcPtr>(look, PyOCIO_LookType);
 48    }
 49    
 50    bool IsPyLook(PyObject * pyobject)
 51    {
 52        return IsPyOCIOType(pyobject, PyOCIO_LookType);
 53    }
 54    
 55    bool IsPyLookEditable(PyObject * pyobject)
 56    {
 57        return IsPyEditable<PyOCIO_Look>(pyobject, PyOCIO_LookType);
 58    }
 59    
 60    ConstLookRcPtr GetConstLook(PyObject * pyobject, bool allowCast)
 61    {
 62        return GetConstPyOCIO<PyOCIO_Look, ConstLookRcPtr>(pyobject,
 63            PyOCIO_LookType, allowCast);
 64    }
 65    
 66    LookRcPtr GetEditableLook(PyObject * pyobject)
 67    {
 68        return GetEditablePyOCIO<PyOCIO_Look, LookRcPtr>(pyobject,
 69            PyOCIO_LookType);
 70    }
 71    
 72    namespace
 73    {
 74        
 75        ///////////////////////////////////////////////////////////////////////
 76        ///
 77        
 78        int PyOCIO_Look_init(PyOCIO_Look * self, PyObject * args, PyObject * kwds);
 79        void PyOCIO_Look_delete(PyOCIO_Look * self, PyObject * args);
 80        PyObject * PyOCIO_Look_isEditable(PyObject * self);
 81        PyObject * PyOCIO_Look_createEditableCopy(PyObject * self);
 82        PyObject * PyOCIO_Look_getName(PyObject * self);
 83        PyObject * PyOCIO_Look_setName(PyObject * self, PyObject * args);
 84        PyObject * PyOCIO_Look_getProcessSpace(PyObject * self);
 85        PyObject * PyOCIO_Look_setProcessSpace(PyObject * self, PyObject * args);
 86        PyObject * PyOCIO_Look_getTransform(PyObject * self);
 87        PyObject * PyOCIO_Look_setTransform(PyObject * self, PyObject * args);
 88        PyObject * PyOCIO_Look_getInverseTransform(PyObject * self);
 89        PyObject * PyOCIO_Look_setInverseTransform(PyObject * self, PyObject * args);
 90        
 91        ///////////////////////////////////////////////////////////////////////
 92        ///
 93        
 94        PyMethodDef PyOCIO_Look_methods[] = {
 95            { "isEditable",
 96            (PyCFunction) PyOCIO_Look_isEditable, METH_NOARGS, LOOK_ISEDITABLE__DOC__ },
 97            { "createEditableCopy",
 98            (PyCFunction) PyOCIO_Look_createEditableCopy, METH_NOARGS, LOOK_CREATEEDITABLECOPY__DOC__ },
 99            { "getName",
100            (PyCFunction) PyOCIO_Look_getName, METH_NOARGS, LOOK_GETNAME__DOC__ },
101            { "setName",
102            PyOCIO_Look_setName, METH_VARARGS, LOOK_SETNAME__DOC__ },
103            { "getProcessSpace",
104            (PyCFunction) PyOCIO_Look_getProcessSpace, METH_NOARGS, LOOK_GETPROCESSSPACE__DOC__ },
105            { "setProcessSpace",
106            PyOCIO_Look_setProcessSpace, METH_VARARGS, LOOK_SETPROCESSSPACE__DOC__ },
107            { "getTransform",
108            (PyCFunction) PyOCIO_Look_getTransform, METH_NOARGS, LOOK_GETTRANSFORM__DOC__ },
109            { "setTransform",
110            PyOCIO_Look_setTransform, METH_VARARGS, LOOK_SETTRANSFORM__DOC__ },
111            { "getInverseTransform",
112            (PyCFunction) PyOCIO_Look_getInverseTransform, METH_VARARGS, LOOK_GETINVERSETRANSFORM__DOC__ },
113            { "setInverseTransform",
114            PyOCIO_Look_setInverseTransform, METH_VARARGS, LOOK_SETINVERSETRANSFORM__DOC__ },
115            { NULL, NULL, 0, NULL }
116        };
117        
118    }
119    
120    ///////////////////////////////////////////////////////////////////////////
121    ///
122    
123    PyTypeObject PyOCIO_LookType = {
124        PyVarObject_HEAD_INIT(NULL, 0)              //ob_size
125        "OCIO.Look",                                //tp_name
126        sizeof(PyOCIO_Look),                        //tp_basicsize
127        0,                                          //tp_itemsize
128        (destructor)PyOCIO_Look_delete,             //tp_dealloc
129        0,                                          //tp_print
130        0,                                          //tp_getattr
131        0,                                          //tp_setattr
132        0,                                          //tp_compare
133        0,                                          //tp_repr
134        0,                                          //tp_as_number
135        0,                                          //tp_as_sequence
136        0,                                          //tp_as_mapping
137        0,                                          //tp_hash 
138        0,                                          //tp_call
139        0,                                          //tp_str
140        0,                                          //tp_getattro
141        0,                                          //tp_setattro
142        0,                                          //tp_as_buffer
143        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   //tp_flags
144        LOOK__DOC__,                                //tp_doc 
145        0,                                          //tp_traverse 
146        0,                                          //tp_clear 
147        0,                                          //tp_richcompare 
148        0,                                          //tp_weaklistoffset 
149        0,                                          //tp_iter 
150        0,                                          //tp_iternext 
151        PyOCIO_Look_methods,                        //tp_methods 
152        0,                                          //tp_members 
153        0,                                          //tp_getset 
154        0,                                          //tp_base 
155        0,                                          //tp_dict 
156        0,                                          //tp_descr_get 
157        0,                                          //tp_descr_set 
158        0,                                          //tp_dictoffset 
159        (initproc) PyOCIO_Look_init,                //tp_init 
160        0,                                          //tp_alloc 
161        0,                                          //tp_new 
162        0,                                          //tp_free
163        0,                                          //tp_is_gc
164    };
165    
166    namespace
167    {
168        
169        ///////////////////////////////////////////////////////////////////////
170        ///
171        
172        int PyOCIO_Look_init(PyOCIO_Look *self, PyObject * args, PyObject * kwds)
173        {
174            OCIO_PYTRY_ENTER()
175            LookRcPtr ptr = Look::Create();
176            /*int ret =*/ BuildPyObject<PyOCIO_Look, ConstLookRcPtr, LookRcPtr>(self, ptr);
177            char* name = NULL;
178            char* processSpace = NULL;
179            PyObject* pytransform = NULL;
180            const char* kwlist[] = { "name", "processSpace", "transform", NULL };
181            if(!PyArg_ParseTupleAndKeywords(args, kwds, "|ssO",
182                const_cast<char **>(kwlist),
183                &name, &processSpace, &pytransform)) return -1;
184            if(name) ptr->setName(name);
185            if(processSpace) ptr->setProcessSpace(processSpace);
186            if(pytransform)
187            {
188                ConstTransformRcPtr transform = GetConstTransform(pytransform, true);
189                ptr->setTransform(transform);
190            }
191            return 0;
192            OCIO_PYTRY_EXIT(-1)
193        }
194        
195        void PyOCIO_Look_delete(PyOCIO_Look *self, PyObject * /*args*/)
196        {
197            DeletePyObject<PyOCIO_Look>(self);
198        }
199        
200        PyObject * PyOCIO_Look_isEditable(PyObject * self)
201        {
202            return PyBool_FromLong(IsPyLookEditable(self));
203        }
204        
205        PyObject * PyOCIO_Look_createEditableCopy(PyObject * self)
206        {
207            OCIO_PYTRY_ENTER()
208            ConstLookRcPtr look = GetConstLook(self, true);
209            LookRcPtr copy = look->createEditableCopy();
210            return BuildEditablePyLook(copy);
211            OCIO_PYTRY_EXIT(NULL)
212        }
213        
214        PyObject * PyOCIO_Look_getName(PyObject * self)
215        {
216            OCIO_PYTRY_ENTER()
217            ConstLookRcPtr look = GetConstLook(self, true);
218            return PyString_FromString(look->getName());
219            OCIO_PYTRY_EXIT(NULL)
220        }
221        
222        PyObject * PyOCIO_Look_setName(PyObject * self, PyObject * args)
223        {
224            OCIO_PYTRY_ENTER()
225            char* name = 0;
226            if (!PyArg_ParseTuple(args, "s:setName",
227                &name)) return NULL;
228            LookRcPtr look = GetEditableLook(self);
229            look->setName(name);
230            Py_RETURN_NONE;
231            OCIO_PYTRY_EXIT(NULL)
232        }
233        
234        PyObject * PyOCIO_Look_getProcessSpace(PyObject * self)
235        {
236            OCIO_PYTRY_ENTER()
237            ConstLookRcPtr look = GetConstLook(self, true);
238            return PyString_FromString(look->getProcessSpace());
239            OCIO_PYTRY_EXIT(NULL)
240        }
241        
242        PyObject * PyOCIO_Look_setProcessSpace(PyObject * self, PyObject * args)
243        {
244            OCIO_PYTRY_ENTER()
245            char* processSpace = 0;
246            if (!PyArg_ParseTuple(args,"s:setProcessSpace",
247                &processSpace)) return NULL;
248            LookRcPtr look = GetEditableLook(self);
249            look->setProcessSpace(processSpace);
250            Py_RETURN_NONE;
251            OCIO_PYTRY_EXIT(NULL)
252        }
253        
254        PyObject * PyOCIO_Look_getTransform(PyObject * self)
255        {
256            OCIO_PYTRY_ENTER()
257            ConstLookRcPtr look = GetConstLook(self, true);
258            ConstTransformRcPtr transform = look->getTransform();
259            return BuildConstPyTransform(transform);
260            OCIO_PYTRY_EXIT(NULL)
261        }
262        
263        PyObject * PyOCIO_Look_setTransform(PyObject * self, PyObject * args)
264        {
265            OCIO_PYTRY_ENTER()
266            PyObject* pytransform = 0;
267            if (!PyArg_ParseTuple(args, "O:setTransform",
268                &pytransform))
269                return NULL;
270            ConstTransformRcPtr transform = GetConstTransform(pytransform, true);
271            LookRcPtr look = GetEditableLook(self);
272            look->setTransform(transform);
273            Py_RETURN_NONE;
274            OCIO_PYTRY_EXIT(NULL)
275        }
276        
277        PyObject * PyOCIO_Look_getInverseTransform(PyObject * self)
278        {
279            OCIO_PYTRY_ENTER()
280            ConstLookRcPtr look = GetConstLook(self, true);
281            ConstTransformRcPtr transform = look->getInverseTransform();
282            return BuildConstPyTransform(transform);
283            OCIO_PYTRY_EXIT(NULL)
284        }
285        
286        PyObject * PyOCIO_Look_setInverseTransform(PyObject * self, PyObject * args)
287        {
288            OCIO_PYTRY_ENTER()
289            PyObject* pytransform = 0;
290            if (!PyArg_ParseTuple(args, "O:setTransform",
291                &pytransform))
292                return NULL;
293            ConstTransformRcPtr transform = GetConstTransform(pytransform, true);
294            LookRcPtr look = GetEditableLook(self);
295            look->setInverseTransform(transform);
296            Py_RETURN_NONE;
297            OCIO_PYTRY_EXIT(NULL)
298        }
299        
300    }
301
302}
303OCIO_NAMESPACE_EXIT