PageRenderTime 43ms CodeModel.GetById 12ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/pyglue/PyCDLTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 397 lines | 325 code | 37 blank | 35 comment | 23 complexity | 9778fdd716e30c94a90447098b276dc2 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
 35#define GetConstCDLTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
 36    ConstCDLTransformRcPtr, CDLTransform>(pyobject, PyOCIO_CDLTransformType)
 37
 38#define GetEditableCDLTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
 39    CDLTransformRcPtr, CDLTransform>(pyobject, PyOCIO_CDLTransformType)
 40
 41OCIO_NAMESPACE_ENTER
 42{
 43    
 44    namespace
 45    {
 46        
 47        ///////////////////////////////////////////////////////////////////////
 48        ///
 49        
 50        int PyOCIO_CDLTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds); 
 51        PyObject * PyOCIO_CDLTransform_CreateFromFile(PyObject * self, PyObject * args);
 52        PyObject * PyOCIO_CDLTransform_equals(PyObject * self, PyObject * args);
 53        PyObject * PyOCIO_CDLTransform_getXML(PyObject * self);
 54        PyObject * PyOCIO_CDLTransform_setXML(PyObject * self, PyObject * args);
 55        PyObject * PyOCIO_CDLTransform_getSlope(PyObject * self);
 56        PyObject * PyOCIO_CDLTransform_getOffset(PyObject * self);
 57        PyObject * PyOCIO_CDLTransform_getPower(PyObject * self);
 58        PyObject * PyOCIO_CDLTransform_getSOP(PyObject * self);
 59        PyObject * PyOCIO_CDLTransform_getSat(PyObject * self);
 60        PyObject * PyOCIO_CDLTransform_setSlope(PyObject * self, PyObject * args);
 61        PyObject * PyOCIO_CDLTransform_setOffset(PyObject * self, PyObject * args);
 62        PyObject * PyOCIO_CDLTransform_setPower(PyObject * self, PyObject * args);
 63        PyObject * PyOCIO_CDLTransform_setSOP(PyObject * self, PyObject * args);
 64        PyObject * PyOCIO_CDLTransform_setSat(PyObject * self, PyObject * args);
 65        PyObject * PyOCIO_CDLTransform_getSatLumaCoefs(PyObject * self);
 66        PyObject * PyOCIO_CDLTransform_getID(PyObject * self);
 67        PyObject * PyOCIO_CDLTransform_setID(PyObject * self,  PyObject * args);
 68        PyObject * PyOCIO_CDLTransform_getDescription(PyObject * self);
 69        PyObject * PyOCIO_CDLTransform_setDescription(PyObject * self, PyObject * args);
 70        
 71        ///////////////////////////////////////////////////////////////////////
 72        ///
 73        
 74        PyMethodDef PyOCIO_CDLTransform_methods[] = {
 75            { "CreateFromFile",
 76            PyOCIO_CDLTransform_CreateFromFile, METH_VARARGS, CDLTRANSFORM_CREATEFROMFILE__DOC__ },
 77            { "equals",
 78            PyOCIO_CDLTransform_equals, METH_VARARGS, CDLTRANSFORM_EQUALS__DOC__ },
 79            { "getXML",
 80            (PyCFunction) PyOCIO_CDLTransform_getXML, METH_NOARGS, CDLTRANSFORM_GETXML__DOC__ },
 81            { "setXML",
 82            PyOCIO_CDLTransform_setXML, METH_VARARGS, CDLTRANSFORM_SETXML__DOC__ },
 83            { "getSlope",
 84            (PyCFunction) PyOCIO_CDLTransform_getSlope, METH_NOARGS, CDLTRANSFORM_GETSLOPE__DOC__ },
 85            { "getOffset",
 86            (PyCFunction) PyOCIO_CDLTransform_getOffset, METH_NOARGS, CDLTRANSFORM_GETOFFSET__DOC__ },
 87            { "getPower",
 88            (PyCFunction) PyOCIO_CDLTransform_getPower, METH_NOARGS, CDLTRANSFORM_GETPOWER__DOC__ },
 89            { "getSOP",
 90            (PyCFunction) PyOCIO_CDLTransform_getSOP, METH_NOARGS, CDLTRANSFORM_GETSOP__DOC__ },
 91            { "getSat",
 92            (PyCFunction) PyOCIO_CDLTransform_getSat, METH_NOARGS, CDLTRANSFORM_GETSAT__DOC__ },
 93            { "setSlope",
 94            PyOCIO_CDLTransform_setSlope, METH_VARARGS, CDLTRANSFORM_SETSLOPE__DOC__ },
 95            { "setOffset",
 96            PyOCIO_CDLTransform_setOffset, METH_VARARGS, CDLTRANSFORM_SETOFFSET__DOC__ },
 97            { "setPower",
 98            PyOCIO_CDLTransform_setPower, METH_VARARGS, CDLTRANSFORM_SETPOWER__DOC__ },
 99            { "setSOP",
100            PyOCIO_CDLTransform_setSOP, METH_VARARGS, CDLTRANSFORM_SETSOP__DOC__ },
101            { "setSat",
102            PyOCIO_CDLTransform_setSat, METH_VARARGS, CDLTRANSFORM_SETSAT__DOC__ },
103            { "getSatLumaCoefs",
104            (PyCFunction) PyOCIO_CDLTransform_getSatLumaCoefs, METH_NOARGS, CDLTRANSFORM_GETSATLUMACOEFS__DOC__ },
105            { "getID",
106            (PyCFunction) PyOCIO_CDLTransform_getID, METH_NOARGS, CDLTRANSFORM_GETID__DOC__ },
107            { "setID",
108            PyOCIO_CDLTransform_setID, METH_VARARGS, CDLTRANSFORM_SETID__DOC__ },
109            { "getDescription",
110            (PyCFunction) PyOCIO_CDLTransform_getDescription, METH_NOARGS, CDLTRANSFORM_GETDESCRIPTION__DOC__ },
111            { "setDescription",
112            PyOCIO_CDLTransform_setDescription, METH_VARARGS, CDLTRANSFORM_SETDESCRIPTION__DOC__ },
113            { NULL, NULL, 0, NULL }
114        };
115        
116    }
117    
118    ///////////////////////////////////////////////////////////////////////////
119    ///
120    
121    PyTypeObject PyOCIO_CDLTransformType = {
122        PyVarObject_HEAD_INIT(NULL, 0)
123        "OCIO.CDLTransform",                        //tp_name
124        sizeof(PyOCIO_Transform),                   //tp_basicsize
125        0,                                          //tp_itemsize
126        0,                                          //tp_dealloc
127        0,                                          //tp_print
128        0,                                          //tp_getattr
129        0,                                          //tp_setattr
130        0,                                          //tp_compare
131        0,                                          //tp_repr
132        0,                                          //tp_as_number
133        0,                                          //tp_as_sequence
134        0,                                          //tp_as_mapping
135        0,                                          //tp_hash 
136        0,                                          //tp_call
137        0,                                          //tp_str
138        0,                                          //tp_getattro
139        0,                                          //tp_setattro
140        0,                                          //tp_as_buffer
141        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   //tp_flags
142        CDLTRANSFORM__DOC__,                        //tp_doc 
143        0,                                          //tp_traverse 
144        0,                                          //tp_clear 
145        0,                                          //tp_richcompare 
146        0,                                          //tp_weaklistoffset 
147        0,                                          //tp_iter 
148        0,                                          //tp_iternext 
149        PyOCIO_CDLTransform_methods,                //tp_methods 
150        0,                                          //tp_members 
151        0,                                          //tp_getset 
152        &PyOCIO_TransformType,                      //tp_base 
153        0,                                          //tp_dict 
154        0,                                          //tp_descr_get 
155        0,                                          //tp_descr_set 
156        0,                                          //tp_dictoffset 
157        (initproc) PyOCIO_CDLTransform_init,        //tp_init 
158        0,                                          //tp_alloc 
159        0,                                          //tp_new 
160        0,                                          //tp_free
161        0,                                          //tp_is_gc
162    };
163    
164    namespace
165    {
166        
167        ///////////////////////////////////////////////////////////////////////
168        ///
169        
170        int PyOCIO_CDLTransform_init(PyOCIO_Transform *self, PyObject* /*args*/, PyObject* /*kwds*/)
171        {
172            OCIO_PYTRY_ENTER()
173            return BuildPyTransformObject<CDLTransformRcPtr>(self, CDLTransform::Create());
174            OCIO_PYTRY_EXIT(-1)
175        }
176        
177        PyObject * PyOCIO_CDLTransform_CreateFromFile(PyObject * /*self*/, PyObject * args)
178        {
179            OCIO_PYTRY_ENTER()
180            const char * src = 0;
181            const char * cccid = 0;
182            if (!PyArg_ParseTuple(args, "ss:CreateFromFile", &src, &cccid)) return NULL;
183            return BuildEditablePyTransform(CDLTransform::CreateFromFile(src, cccid));
184            OCIO_PYTRY_EXIT(NULL)
185        }
186        
187        PyObject * PyOCIO_CDLTransform_equals(PyObject * self, PyObject * args)
188        {
189            OCIO_PYTRY_ENTER()
190            PyObject* pyother = 0;
191            if (!PyArg_ParseTuple(args, "O:equals", &pyother)) return NULL;
192            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
193            if(IsPyOCIOType(pyother, PyOCIO_CDLTransformType))
194                return PyBool_FromLong(false);
195            ConstCDLTransformRcPtr other = GetConstCDLTransform(pyother);
196            return PyBool_FromLong(transform->equals(other));
197            OCIO_PYTRY_EXIT(NULL)
198        }
199        
200        PyObject * PyOCIO_CDLTransform_getXML(PyObject * self)
201        {
202            OCIO_PYTRY_ENTER()
203            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
204            return PyString_FromString(transform->getXML());
205            OCIO_PYTRY_EXIT(NULL)
206        }
207        
208        PyObject * PyOCIO_CDLTransform_setXML(PyObject * self, PyObject * args)
209        {
210            OCIO_PYTRY_ENTER()
211            const char* str = 0;
212            if (!PyArg_ParseTuple(args, "s:setXML", &str)) return NULL;
213            CDLTransformRcPtr transform = GetEditableCDLTransform(self);
214            transform->setXML(str);
215            Py_RETURN_NONE;
216            OCIO_PYTRY_EXIT(NULL)
217        }
218        
219        PyObject * PyOCIO_CDLTransform_getSlope(PyObject * self)
220        {
221            OCIO_PYTRY_ENTER()
222            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
223            std::vector<float> data(3);
224            transform->getSlope(&data[0]);
225            return CreatePyListFromFloatVector(data);
226            OCIO_PYTRY_EXIT(NULL)
227        }
228        
229        PyObject * PyOCIO_CDLTransform_getOffset(PyObject * self)
230        {
231            OCIO_PYTRY_ENTER()
232            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
233            std::vector<float> data(3);
234            transform->getOffset(&data[0]);
235            return CreatePyListFromFloatVector(data);
236            OCIO_PYTRY_EXIT(NULL)
237        }
238        
239        PyObject * PyOCIO_CDLTransform_getPower(PyObject * self)
240        {
241            OCIO_PYTRY_ENTER()
242            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
243            std::vector<float> data(3);
244            transform->getPower(&data[0]);
245            return CreatePyListFromFloatVector(data);
246            OCIO_PYTRY_EXIT(NULL)
247        }
248        
249        PyObject * PyOCIO_CDLTransform_getSOP(PyObject * self)
250        {
251            OCIO_PYTRY_ENTER()
252            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
253            std::vector<float> data(9);
254            transform->getSOP(&data[0]);
255            return CreatePyListFromFloatVector(data);
256            OCIO_PYTRY_EXIT(NULL)
257        }
258        
259        PyObject * PyOCIO_CDLTransform_getSat(PyObject * self)
260        {
261            OCIO_PYTRY_ENTER()
262            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
263            return PyFloat_FromDouble(transform->getSat());
264            OCIO_PYTRY_EXIT(NULL)
265        }
266        
267        PyObject * PyOCIO_CDLTransform_setSlope(PyObject * self, PyObject * args)
268        {
269            OCIO_PYTRY_ENTER()
270            PyObject* pyData = 0;
271            if (!PyArg_ParseTuple(args, "O:setSlope", &pyData)) return NULL;
272            CDLTransformRcPtr transform = GetEditableCDLTransform(self);
273            std::vector<float> data;
274            if(!FillFloatVectorFromPySequence(pyData, data) || (data.size() != 3))
275            {
276                PyErr_SetString(PyExc_TypeError, "First argument must be a float array, size 3");
277                return 0;
278            }
279            transform->setSlope(&data[0]);
280            Py_RETURN_NONE;
281            OCIO_PYTRY_EXIT(NULL)
282        }
283        
284        PyObject * PyOCIO_CDLTransform_setOffset(PyObject * self, PyObject * args)
285        {
286            OCIO_PYTRY_ENTER()
287            PyObject* pyData = 0;
288            if (!PyArg_ParseTuple(args, "O:setOffset", &pyData)) return NULL;
289            CDLTransformRcPtr transform = GetEditableCDLTransform(self);
290            std::vector<float> data;
291            if(!FillFloatVectorFromPySequence(pyData, data) || (data.size() != 3))
292            {
293                PyErr_SetString(PyExc_TypeError, "First argument must be a float array, size 3");
294                return 0;
295            }
296            transform->setOffset(&data[0]);
297            Py_RETURN_NONE;
298            OCIO_PYTRY_EXIT(NULL)
299        }
300        
301        PyObject * PyOCIO_CDLTransform_setPower(PyObject * self, PyObject * args)
302        {
303            OCIO_PYTRY_ENTER()
304            PyObject* pyData = 0;
305            if (!PyArg_ParseTuple(args, "O:setPower", &pyData)) return NULL;
306            CDLTransformRcPtr transform = GetEditableCDLTransform(self);    
307            std::vector<float> data;
308            if(!FillFloatVectorFromPySequence(pyData, data) || (data.size() != 3))
309            {
310                PyErr_SetString(PyExc_TypeError, "First argument must be a float array, size 3");
311                return 0;
312            }
313            transform->setPower(&data[0]);
314            Py_RETURN_NONE;
315            OCIO_PYTRY_EXIT(NULL)
316        }
317        
318        PyObject * PyOCIO_CDLTransform_setSOP(PyObject * self, PyObject * args)
319        {
320            OCIO_PYTRY_ENTER()
321            PyObject* pyData = 0;
322            if (!PyArg_ParseTuple(args, "O:setSOP", &pyData)) return NULL;
323            CDLTransformRcPtr transform = GetEditableCDLTransform(self); 
324            std::vector<float> data;
325            if(!FillFloatVectorFromPySequence(pyData, data) || (data.size() != 9))
326            {
327            	PyErr_SetString(PyExc_TypeError, "First argument must be a float array, size 9");
328                return 0;
329            }
330            transform->setSOP(&data[0]);    
331            Py_RETURN_NONE;
332            OCIO_PYTRY_EXIT(NULL)
333        }
334        
335        PyObject * PyOCIO_CDLTransform_setSat(PyObject * self, PyObject * args)
336        {
337            OCIO_PYTRY_ENTER()
338            float sat;
339            if (!PyArg_ParseTuple(args, "f:setSat", &sat)) return NULL;
340            CDLTransformRcPtr transform = GetEditableCDLTransform(self);    
341            transform->setSat(sat);    
342            Py_RETURN_NONE;
343            OCIO_PYTRY_EXIT(NULL)
344        }
345        
346        PyObject * PyOCIO_CDLTransform_getSatLumaCoefs(PyObject * self)
347        {
348            OCIO_PYTRY_ENTER()
349            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
350            std::vector<float> data(3);
351            transform->getSatLumaCoefs(&data[0]);
352            return CreatePyListFromFloatVector(data);
353            OCIO_PYTRY_EXIT(NULL)
354        }
355        
356        PyObject * PyOCIO_CDLTransform_getID(PyObject * self)
357        {
358            OCIO_PYTRY_ENTER()
359            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
360            return PyString_FromString(transform->getID());
361            OCIO_PYTRY_EXIT(NULL)
362        }
363        
364        PyObject * PyOCIO_CDLTransform_setID(PyObject * self, PyObject * args)
365        {
366            OCIO_PYTRY_ENTER()
367            const char* str = 0;
368            if (!PyArg_ParseTuple(args, "s:setID", &str)) return NULL;
369            CDLTransformRcPtr transform = GetEditableCDLTransform(self);
370            transform->setID(str);
371            Py_RETURN_NONE;
372            OCIO_PYTRY_EXIT(NULL)
373        }
374        
375        PyObject * PyOCIO_CDLTransform_getDescription(PyObject * self)
376        {
377            OCIO_PYTRY_ENTER()
378            ConstCDLTransformRcPtr transform = GetConstCDLTransform(self);
379            return PyString_FromString(transform->getDescription());
380            OCIO_PYTRY_EXIT(NULL)
381        }
382        
383        PyObject * PyOCIO_CDLTransform_setDescription(PyObject * self, PyObject * args)
384        {
385            OCIO_PYTRY_ENTER()
386            const char* str = 0;
387            if (!PyArg_ParseTuple(args, "s:setDescription", &str)) return NULL;
388            CDLTransformRcPtr transform = GetEditableCDLTransform(self);
389            transform->setDescription(str);
390            Py_RETURN_NONE;
391            OCIO_PYTRY_EXIT(NULL)
392        }
393        
394    }
395
396}
397OCIO_NAMESPACE_EXIT