PageRenderTime 41ms CodeModel.GetById 13ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 0ms

/src/pyglue/PyDisplayTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 362 lines | 292 code | 35 blank | 35 comment | 9 complexity | 91f2f393b80ce5777daa1b19e8dd0343 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 GetConstDisplayTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
 36    ConstDisplayTransformRcPtr, DisplayTransform>(pyobject, \
 37    PyOCIO_DisplayTransformType)
 38
 39#define GetEditableDisplayTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
 40    DisplayTransformRcPtr, DisplayTransform>(pyobject, \
 41    PyOCIO_DisplayTransformType)
 42
 43OCIO_NAMESPACE_ENTER
 44{
 45    
 46    namespace
 47    {
 48        
 49        ///////////////////////////////////////////////////////////////////////
 50        ///
 51        
 52        int PyOCIO_DisplayTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds);
 53        PyObject * PyOCIO_DisplayTransform_getInputColorSpaceName(PyObject * self);
 54        PyObject * PyOCIO_DisplayTransform_setInputColorSpaceName(PyObject * self, PyObject * args);
 55        PyObject * PyOCIO_DisplayTransform_getLinearCC(PyObject * self);
 56        PyObject * PyOCIO_DisplayTransform_setLinearCC(PyObject * self, PyObject * args);
 57        PyObject * PyOCIO_DisplayTransform_getColorTimingCC(PyObject * self);
 58        PyObject * PyOCIO_DisplayTransform_setColorTimingCC(PyObject * self, PyObject * args);
 59        PyObject * PyOCIO_DisplayTransform_getChannelView(PyObject * self);
 60        PyObject * PyOCIO_DisplayTransform_setChannelView(PyObject * self, PyObject * args);
 61        PyObject * PyOCIO_DisplayTransform_getDisplay(PyObject * self);
 62        PyObject * PyOCIO_DisplayTransform_setDisplay(PyObject * self, PyObject * args);
 63        PyObject * PyOCIO_DisplayTransform_getView(PyObject * self);
 64        PyObject * PyOCIO_DisplayTransform_setView(PyObject * self, PyObject * args);
 65        PyObject * PyOCIO_DisplayTransform_getDisplayCC(PyObject * self);
 66        PyObject * PyOCIO_DisplayTransform_setDisplayCC(PyObject * self, PyObject * args );
 67        PyObject * PyOCIO_DisplayTransform_getLooksOverride(PyObject * self );
 68        PyObject * PyOCIO_DisplayTransform_setLooksOverride(PyObject * self, PyObject * args);
 69        PyObject * PyOCIO_DisplayTransform_getLooksOverrideEnabled(PyObject * self );
 70        PyObject * PyOCIO_DisplayTransform_setLooksOverrideEnabled(PyObject * self,  PyObject * args);
 71        
 72        ///////////////////////////////////////////////////////////////////////
 73        ///
 74        
 75        PyMethodDef PyOCIO_DisplayTransform_methods[] = {
 76            { "getInputColorSpaceName",
 77            (PyCFunction) PyOCIO_DisplayTransform_getInputColorSpaceName, METH_NOARGS, DISPLAYTRANSFORM_GETINPUTCOLORSPACENAME__DOC__ },
 78            { "setInputColorSpaceName",
 79            PyOCIO_DisplayTransform_setInputColorSpaceName, METH_VARARGS, DISPLAYTRANSFORM_SETINPUTCOLORSPACENAME__DOC__ },
 80            { "getLinearCC",
 81            (PyCFunction) PyOCIO_DisplayTransform_getLinearCC, METH_NOARGS, DISPLAYTRANSFORM_GETLINEARCC__DOC__ },
 82            { "setLinearCC",
 83            PyOCIO_DisplayTransform_setLinearCC, METH_VARARGS, DISPLAYTRANSFORM_SETLINEARCC__DOC__ },
 84            { "getColorTimingCC",
 85            (PyCFunction) PyOCIO_DisplayTransform_getColorTimingCC, METH_NOARGS, DISPLAYTRANSFORM_GETCOLORTIMINGCC__DOC__ },
 86            { "setColorTimingCC",
 87            PyOCIO_DisplayTransform_setColorTimingCC, METH_VARARGS, DISPLAYTRANSFORM_SETCOLORTIMINGCC__DOC__ },
 88            { "getChannelView",
 89            (PyCFunction) PyOCIO_DisplayTransform_getChannelView, METH_NOARGS, DISPLAYTRANSFORM_GETCHANNELVIEW__DOC__ },
 90            { "setChannelView",
 91            PyOCIO_DisplayTransform_setChannelView, METH_VARARGS, DISPLAYTRANSFORM_SETCHANNELVIEW__DOC__ },
 92            { "getDisplay",
 93            (PyCFunction) PyOCIO_DisplayTransform_getDisplay, METH_NOARGS, DISPLAYTRANSFORM_GETDISPLAY__DOC__ },
 94            { "setDisplay",
 95            PyOCIO_DisplayTransform_setDisplay, METH_VARARGS, DISPLAYTRANSFORM_SETDISPLAY__DOC__ },
 96            { "getView",
 97            (PyCFunction) PyOCIO_DisplayTransform_getView, METH_NOARGS, DISPLAYTRANSFORM_GETVIEW__DOC__ },
 98            { "setView",
 99            PyOCIO_DisplayTransform_setView, METH_VARARGS, DISPLAYTRANSFORM_SETVIEW__DOC__ },
100            { "getDisplayCC",
101            (PyCFunction) PyOCIO_DisplayTransform_getDisplayCC, METH_NOARGS, DISPLAYTRANSFORM_GETDISPLAYCC__DOC__ },
102            { "setDisplayCC",
103            PyOCIO_DisplayTransform_setDisplayCC, METH_VARARGS, DISPLAYTRANSFORM_SETDISPLAYCC__DOC__ },
104            { "getLooksOverride",
105            (PyCFunction) PyOCIO_DisplayTransform_getLooksOverride, METH_NOARGS, DISPLAYTRANSFORM_GETLOOKSOVERRIDE__DOC__ },
106            { "setLooksOverride",
107            PyOCIO_DisplayTransform_setLooksOverride, METH_VARARGS, DISPLAYTRANSFORM_SETLOOKSOVERRIDE__DOC__ },
108            { "getLooksOverrideEnabled",
109            (PyCFunction) PyOCIO_DisplayTransform_getLooksOverrideEnabled, METH_NOARGS, DISPLAYTRANSFORM_GETLOOKSOVERRIDEENABLED__DOC__ },
110            { "setLooksOverrideEnabled",
111            PyOCIO_DisplayTransform_setLooksOverrideEnabled, METH_VARARGS, DISPLAYTRANSFORM_SETLOOKSOVERRIDEENABLED__DOC__ },
112            { NULL, NULL, 0, NULL }
113        };
114    }
115    
116    ///////////////////////////////////////////////////////////////////////////
117    ///
118    
119    PyTypeObject PyOCIO_DisplayTransformType = {
120        PyVarObject_HEAD_INIT(NULL, 0)
121        "OCIO.DisplayTransform",                    //tp_name
122        sizeof(PyOCIO_Transform),                   //tp_basicsize
123        0,                                          //tp_itemsize
124        0,                                          //tp_dealloc
125        0,                                          //tp_print
126        0,                                          //tp_getattr
127        0,                                          //tp_setattr
128        0,                                          //tp_compare
129        0,                                          //tp_repr
130        0,                                          //tp_as_number
131        0,                                          //tp_as_sequence
132        0,                                          //tp_as_mapping
133        0,                                          //tp_hash 
134        0,                                          //tp_call
135        0,                                          //tp_str
136        0,                                          //tp_getattro
137        0,                                          //tp_setattro
138        0,                                          //tp_as_buffer
139        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   //tp_flags
140        DISPLAYTRANSFORM__DOC__,                    //tp_doc 
141        0,                                          //tp_traverse 
142        0,                                          //tp_clear 
143        0,                                          //tp_richcompare 
144        0,                                          //tp_weaklistoffset 
145        0,                                          //tp_iter 
146        0,                                          //tp_iternext 
147        PyOCIO_DisplayTransform_methods,            //tp_methods 
148        0,                                          //tp_members 
149        0,                                          //tp_getset 
150        &PyOCIO_TransformType,                      //tp_base 
151        0,                                          //tp_dict 
152        0,                                          //tp_descr_get 
153        0,                                          //tp_descr_set 
154        0,                                          //tp_dictoffset 
155        (initproc) PyOCIO_DisplayTransform_init,    //tp_init 
156        0,                                          //tp_alloc 
157        0,                                          //tp_new 
158        0,                                          //tp_free
159        0,                                          //tp_is_gc
160    };
161    
162    namespace
163    {
164        
165        ///////////////////////////////////////////////////////////////////////
166        ///
167        
168        int PyOCIO_DisplayTransform_init(PyOCIO_Transform * self, PyObject * /*args*/, PyObject * /*kwds*/)
169        {
170            OCIO_PYTRY_ENTER()
171            return BuildPyTransformObject<DisplayTransformRcPtr>(self, DisplayTransform::Create());
172            OCIO_PYTRY_EXIT(-1)
173        }
174        
175        PyObject * PyOCIO_DisplayTransform_getInputColorSpaceName(PyObject * self)
176        {
177            OCIO_PYTRY_ENTER()
178            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
179            return PyString_FromString(transform->getInputColorSpaceName());
180            OCIO_PYTRY_EXIT(NULL)
181        }
182        
183        PyObject * PyOCIO_DisplayTransform_setInputColorSpaceName(PyObject * self, PyObject * args)
184        {
185            OCIO_PYTRY_ENTER()
186            char* name = 0;
187            if (!PyArg_ParseTuple(args, "s:setInputColorSpaceName",
188                &name)) return NULL;
189            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
190            transform->setInputColorSpaceName(name);
191            Py_RETURN_NONE;
192            OCIO_PYTRY_EXIT(NULL)
193        }
194        
195        PyObject * PyOCIO_DisplayTransform_getLinearCC(PyObject * self)
196        {
197            OCIO_PYTRY_ENTER()
198            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
199            return BuildConstPyTransform(transform->getLinearCC());
200            OCIO_PYTRY_EXIT(NULL)
201        }
202        
203        PyObject * PyOCIO_DisplayTransform_setLinearCC(PyObject * self, PyObject * args)
204        {
205            OCIO_PYTRY_ENTER()
206            PyObject * pyCC = 0;
207            if (!PyArg_ParseTuple(args, "O:setLinearCC",
208                &pyCC)) return NULL;
209            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
210            ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
211            transform->setLinearCC(cc);
212            Py_RETURN_NONE;
213            OCIO_PYTRY_EXIT(NULL)
214        }
215        
216        PyObject * PyOCIO_DisplayTransform_getColorTimingCC(PyObject * self)
217        {
218            OCIO_PYTRY_ENTER()
219            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
220            return BuildConstPyTransform(transform->getColorTimingCC());
221            OCIO_PYTRY_EXIT(NULL)
222        }
223        
224        PyObject * PyOCIO_DisplayTransform_setColorTimingCC(PyObject * self, PyObject * args)
225        {
226            OCIO_PYTRY_ENTER()
227            PyObject* pyCC = 0;
228            if (!PyArg_ParseTuple(args, "O:setColorTimingCC",
229                &pyCC)) return NULL;
230            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
231            ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
232            transform->setColorTimingCC(cc);
233            Py_RETURN_NONE;
234            OCIO_PYTRY_EXIT(NULL)
235        }
236        
237        PyObject * PyOCIO_DisplayTransform_getChannelView(PyObject * self)
238        {
239            OCIO_PYTRY_ENTER()
240            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
241            return BuildConstPyTransform(transform->getChannelView());
242            OCIO_PYTRY_EXIT(NULL)
243        }
244        
245        PyObject * PyOCIO_DisplayTransform_setChannelView(PyObject * self, PyObject * args)
246        {
247            OCIO_PYTRY_ENTER()
248            PyObject* pyCC = 0;
249            if (!PyArg_ParseTuple(args, "O:setChannelView",
250                &pyCC)) return NULL;
251            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
252            ConstTransformRcPtr t = GetConstTransform(pyCC, true);
253            transform->setChannelView(t);
254            Py_RETURN_NONE;
255            OCIO_PYTRY_EXIT(NULL)
256        }
257        
258        PyObject * PyOCIO_DisplayTransform_getDisplay(PyObject * self)
259        {
260            OCIO_PYTRY_ENTER()
261            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
262            return PyString_FromString(transform->getDisplay());
263            OCIO_PYTRY_EXIT(NULL)
264        }
265        
266        PyObject * PyOCIO_DisplayTransform_setDisplay(PyObject * self, PyObject * args)
267        {
268            OCIO_PYTRY_ENTER()
269            char* str = 0;
270            if (!PyArg_ParseTuple(args, "s:setDisplay",
271                &str)) return NULL;
272            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
273            transform->setDisplay(str);
274            Py_RETURN_NONE;
275            OCIO_PYTRY_EXIT(NULL)
276        }
277        
278        PyObject * PyOCIO_DisplayTransform_getView(PyObject * self)
279        {
280            OCIO_PYTRY_ENTER()
281            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
282            return PyString_FromString(transform->getView());
283            OCIO_PYTRY_EXIT(NULL)
284        }
285        
286        PyObject * PyOCIO_DisplayTransform_setView(PyObject * self, PyObject * args)
287        {
288            OCIO_PYTRY_ENTER()
289            char* str = 0;
290            if (!PyArg_ParseTuple(args, "s:setView",
291                &str)) return NULL;
292            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
293            transform->setView(str);
294            Py_RETURN_NONE;
295            OCIO_PYTRY_EXIT(NULL)
296        }
297        
298        PyObject * PyOCIO_DisplayTransform_getDisplayCC(PyObject * self)
299        {
300            OCIO_PYTRY_ENTER()
301            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
302            return BuildConstPyTransform(transform->getDisplayCC());
303            OCIO_PYTRY_EXIT(NULL)
304        }
305        
306        PyObject * PyOCIO_DisplayTransform_setDisplayCC(PyObject * self, PyObject * args)
307        {
308            OCIO_PYTRY_ENTER()
309            PyObject* pyCC = 0;
310            if (!PyArg_ParseTuple(args,"O:setDisplayCC",
311                &pyCC)) return NULL;
312            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
313            ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
314            transform->setDisplayCC(cc);
315            Py_RETURN_NONE;
316            OCIO_PYTRY_EXIT(NULL)
317        }
318        
319        PyObject * PyOCIO_DisplayTransform_getLooksOverride(PyObject * self)
320        {
321            OCIO_PYTRY_ENTER()
322            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
323            return PyString_FromString(transform->getLooksOverride());
324            OCIO_PYTRY_EXIT(NULL)
325        }
326        
327        PyObject * PyOCIO_DisplayTransform_setLooksOverride(PyObject * self, PyObject * args)
328        {
329            OCIO_PYTRY_ENTER()
330            char* str = 0;
331            if (!PyArg_ParseTuple(args,"s:setLooksOverride",
332                &str)) return NULL;
333            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
334            transform->setLooksOverride(str);
335            Py_RETURN_NONE;
336            OCIO_PYTRY_EXIT(NULL)
337        }
338        
339        PyObject * PyOCIO_DisplayTransform_getLooksOverrideEnabled(PyObject * self)
340        {
341            OCIO_PYTRY_ENTER()
342            ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
343            return PyBool_FromLong(transform->getLooksOverrideEnabled());
344            OCIO_PYTRY_EXIT(NULL)
345        }
346        
347        PyObject * PyOCIO_DisplayTransform_setLooksOverrideEnabled(PyObject * self, PyObject * args)
348        {
349            OCIO_PYTRY_ENTER()
350            bool enabled = false;
351            if (!PyArg_ParseTuple(args, "O&:setLooksOverrideEnabled",
352                ConvertPyObjectToBool, &enabled)) return NULL;
353            DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
354            transform->setLooksOverrideEnabled(enabled);
355            Py_RETURN_NONE;
356            OCIO_PYTRY_EXIT(NULL)
357        }
358        
359    }
360
361}
362OCIO_NAMESPACE_EXIT