1 /*
2 Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
3 All Rights Reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
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.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF 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 
43 OCIO_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_PYTHON_NAMESPACE(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             DisplayTransformRcPtr ptr = DisplayTransform::Create();
172             int ret = BuildPyTransformObject<DisplayTransformRcPtr>(self, ptr);
173             char* inputColorSpaceName = NULL;
174             char* display = NULL;
175             char* view = NULL;
176             char* direction = NULL;
177             static const char *kwlist[] = { "inputColorSpaceName",
178                 "display", "view", "direction", NULL };
179             if(!PyArg_ParseTupleAndKeywords(args, kwds, "|ssss",
180                 const_cast<char **>(kwlist),
181                 &inputColorSpaceName, &display, &view, &direction)) return -1;
182             if(inputColorSpaceName) ptr->setInputColorSpaceName(inputColorSpaceName);
183             if(display) ptr->setDisplay(display);
184             if(view) ptr->setView(view);
185             if(direction) ptr->setDirection(TransformDirectionFromString(direction));
186             return ret;
187             OCIO_PYTRY_EXIT(-1)
188         }
189 
190         PyObject * PyOCIO_DisplayTransform_getInputColorSpaceName(PyObject * self)
191         {
192             OCIO_PYTRY_ENTER()
193             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
194             return PyString_FromString(transform->getInputColorSpaceName());
195             OCIO_PYTRY_EXIT(NULL)
196         }
197 
198         PyObject * PyOCIO_DisplayTransform_setInputColorSpaceName(PyObject * self, PyObject * args)
199         {
200             OCIO_PYTRY_ENTER()
201             char* name = 0;
202             if (!PyArg_ParseTuple(args, "s:setInputColorSpaceName",
203                 &name)) return NULL;
204             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
205             transform->setInputColorSpaceName(name);
206             Py_RETURN_NONE;
207             OCIO_PYTRY_EXIT(NULL)
208         }
209 
210         PyObject * PyOCIO_DisplayTransform_getLinearCC(PyObject * self)
211         {
212             OCIO_PYTRY_ENTER()
213             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
214             return BuildConstPyTransform(transform->getLinearCC());
215             OCIO_PYTRY_EXIT(NULL)
216         }
217 
218         PyObject * PyOCIO_DisplayTransform_setLinearCC(PyObject * self, PyObject * args)
219         {
220             OCIO_PYTRY_ENTER()
221             PyObject * pyCC = 0;
222             if (!PyArg_ParseTuple(args, "O:setLinearCC",
223                 &pyCC)) return NULL;
224             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
225             ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
226             transform->setLinearCC(cc);
227             Py_RETURN_NONE;
228             OCIO_PYTRY_EXIT(NULL)
229         }
230 
231         PyObject * PyOCIO_DisplayTransform_getColorTimingCC(PyObject * self)
232         {
233             OCIO_PYTRY_ENTER()
234             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
235             return BuildConstPyTransform(transform->getColorTimingCC());
236             OCIO_PYTRY_EXIT(NULL)
237         }
238 
239         PyObject * PyOCIO_DisplayTransform_setColorTimingCC(PyObject * self, PyObject * args)
240         {
241             OCIO_PYTRY_ENTER()
242             PyObject* pyCC = 0;
243             if (!PyArg_ParseTuple(args, "O:setColorTimingCC",
244                 &pyCC)) return NULL;
245             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
246             ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
247             transform->setColorTimingCC(cc);
248             Py_RETURN_NONE;
249             OCIO_PYTRY_EXIT(NULL)
250         }
251 
252         PyObject * PyOCIO_DisplayTransform_getChannelView(PyObject * self)
253         {
254             OCIO_PYTRY_ENTER()
255             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
256             return BuildConstPyTransform(transform->getChannelView());
257             OCIO_PYTRY_EXIT(NULL)
258         }
259 
260         PyObject * PyOCIO_DisplayTransform_setChannelView(PyObject * self, PyObject * args)
261         {
262             OCIO_PYTRY_ENTER()
263             PyObject* pyCC = 0;
264             if (!PyArg_ParseTuple(args, "O:setChannelView",
265                 &pyCC)) return NULL;
266             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
267             ConstTransformRcPtr t = GetConstTransform(pyCC, true);
268             transform->setChannelView(t);
269             Py_RETURN_NONE;
270             OCIO_PYTRY_EXIT(NULL)
271         }
272 
273         PyObject * PyOCIO_DisplayTransform_getDisplay(PyObject * self)
274         {
275             OCIO_PYTRY_ENTER()
276             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
277             return PyString_FromString(transform->getDisplay());
278             OCIO_PYTRY_EXIT(NULL)
279         }
280 
281         PyObject * PyOCIO_DisplayTransform_setDisplay(PyObject * self, PyObject * args)
282         {
283             OCIO_PYTRY_ENTER()
284             char* str = 0;
285             if (!PyArg_ParseTuple(args, "s:setDisplay",
286                 &str)) return NULL;
287             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
288             transform->setDisplay(str);
289             Py_RETURN_NONE;
290             OCIO_PYTRY_EXIT(NULL)
291         }
292 
293         PyObject * PyOCIO_DisplayTransform_getView(PyObject * self)
294         {
295             OCIO_PYTRY_ENTER()
296             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
297             return PyString_FromString(transform->getView());
298             OCIO_PYTRY_EXIT(NULL)
299         }
300 
301         PyObject * PyOCIO_DisplayTransform_setView(PyObject * self, PyObject * args)
302         {
303             OCIO_PYTRY_ENTER()
304             char* str = 0;
305             if (!PyArg_ParseTuple(args, "s:setView",
306                 &str)) return NULL;
307             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
308             transform->setView(str);
309             Py_RETURN_NONE;
310             OCIO_PYTRY_EXIT(NULL)
311         }
312 
313         PyObject * PyOCIO_DisplayTransform_getDisplayCC(PyObject * self)
314         {
315             OCIO_PYTRY_ENTER()
316             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
317             return BuildConstPyTransform(transform->getDisplayCC());
318             OCIO_PYTRY_EXIT(NULL)
319         }
320 
321         PyObject * PyOCIO_DisplayTransform_setDisplayCC(PyObject * self, PyObject * args)
322         {
323             OCIO_PYTRY_ENTER()
324             PyObject* pyCC = 0;
325             if (!PyArg_ParseTuple(args,"O:setDisplayCC",
326                 &pyCC)) return NULL;
327             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
328             ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
329             transform->setDisplayCC(cc);
330             Py_RETURN_NONE;
331             OCIO_PYTRY_EXIT(NULL)
332         }
333 
334         PyObject * PyOCIO_DisplayTransform_getLooksOverride(PyObject * self)
335         {
336             OCIO_PYTRY_ENTER()
337             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
338             return PyString_FromString(transform->getLooksOverride());
339             OCIO_PYTRY_EXIT(NULL)
340         }
341 
342         PyObject * PyOCIO_DisplayTransform_setLooksOverride(PyObject * self, PyObject * args)
343         {
344             OCIO_PYTRY_ENTER()
345             char* str = 0;
346             if (!PyArg_ParseTuple(args,"s:setLooksOverride",
347                 &str)) return NULL;
348             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
349             transform->setLooksOverride(str);
350             Py_RETURN_NONE;
351             OCIO_PYTRY_EXIT(NULL)
352         }
353 
354         PyObject * PyOCIO_DisplayTransform_getLooksOverrideEnabled(PyObject * self)
355         {
356             OCIO_PYTRY_ENTER()
357             ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
358             return PyBool_FromLong(transform->getLooksOverrideEnabled());
359             OCIO_PYTRY_EXIT(NULL)
360         }
361 
362         PyObject * PyOCIO_DisplayTransform_setLooksOverrideEnabled(PyObject * self, PyObject * args)
363         {
364             OCIO_PYTRY_ENTER()
365             bool enabled = false;
366             if (!PyArg_ParseTuple(args, "O&:setLooksOverrideEnabled",
367                 ConvertPyObjectToBool, &enabled)) return NULL;
368             DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
369             transform->setLooksOverrideEnabled(enabled);
370             Py_RETURN_NONE;
371             OCIO_PYTRY_EXIT(NULL)
372         }
373 
374     }
375 
376 }
377 OCIO_NAMESPACE_EXIT
378