/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. /*
  2. Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
  3. All Rights Reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Sony Pictures Imageworks nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <Python.h>
  28. #include <OpenColorIO/OpenColorIO.h>
  29. #include "PyUtil.h"
  30. #include "PyDoc.h"
  31. #define GetConstDisplayTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
  32. ConstDisplayTransformRcPtr, DisplayTransform>(pyobject, \
  33. PyOCIO_DisplayTransformType)
  34. #define GetEditableDisplayTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
  35. DisplayTransformRcPtr, DisplayTransform>(pyobject, \
  36. PyOCIO_DisplayTransformType)
  37. OCIO_NAMESPACE_ENTER
  38. {
  39. namespace
  40. {
  41. ///////////////////////////////////////////////////////////////////////
  42. ///
  43. int PyOCIO_DisplayTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds);
  44. PyObject * PyOCIO_DisplayTransform_getInputColorSpaceName(PyObject * self);
  45. PyObject * PyOCIO_DisplayTransform_setInputColorSpaceName(PyObject * self, PyObject * args);
  46. PyObject * PyOCIO_DisplayTransform_getLinearCC(PyObject * self);
  47. PyObject * PyOCIO_DisplayTransform_setLinearCC(PyObject * self, PyObject * args);
  48. PyObject * PyOCIO_DisplayTransform_getColorTimingCC(PyObject * self);
  49. PyObject * PyOCIO_DisplayTransform_setColorTimingCC(PyObject * self, PyObject * args);
  50. PyObject * PyOCIO_DisplayTransform_getChannelView(PyObject * self);
  51. PyObject * PyOCIO_DisplayTransform_setChannelView(PyObject * self, PyObject * args);
  52. PyObject * PyOCIO_DisplayTransform_getDisplay(PyObject * self);
  53. PyObject * PyOCIO_DisplayTransform_setDisplay(PyObject * self, PyObject * args);
  54. PyObject * PyOCIO_DisplayTransform_getView(PyObject * self);
  55. PyObject * PyOCIO_DisplayTransform_setView(PyObject * self, PyObject * args);
  56. PyObject * PyOCIO_DisplayTransform_getDisplayCC(PyObject * self);
  57. PyObject * PyOCIO_DisplayTransform_setDisplayCC(PyObject * self, PyObject * args );
  58. PyObject * PyOCIO_DisplayTransform_getLooksOverride(PyObject * self );
  59. PyObject * PyOCIO_DisplayTransform_setLooksOverride(PyObject * self, PyObject * args);
  60. PyObject * PyOCIO_DisplayTransform_getLooksOverrideEnabled(PyObject * self );
  61. PyObject * PyOCIO_DisplayTransform_setLooksOverrideEnabled(PyObject * self, PyObject * args);
  62. ///////////////////////////////////////////////////////////////////////
  63. ///
  64. PyMethodDef PyOCIO_DisplayTransform_methods[] = {
  65. { "getInputColorSpaceName",
  66. (PyCFunction) PyOCIO_DisplayTransform_getInputColorSpaceName, METH_NOARGS, DISPLAYTRANSFORM_GETINPUTCOLORSPACENAME__DOC__ },
  67. { "setInputColorSpaceName",
  68. PyOCIO_DisplayTransform_setInputColorSpaceName, METH_VARARGS, DISPLAYTRANSFORM_SETINPUTCOLORSPACENAME__DOC__ },
  69. { "getLinearCC",
  70. (PyCFunction) PyOCIO_DisplayTransform_getLinearCC, METH_NOARGS, DISPLAYTRANSFORM_GETLINEARCC__DOC__ },
  71. { "setLinearCC",
  72. PyOCIO_DisplayTransform_setLinearCC, METH_VARARGS, DISPLAYTRANSFORM_SETLINEARCC__DOC__ },
  73. { "getColorTimingCC",
  74. (PyCFunction) PyOCIO_DisplayTransform_getColorTimingCC, METH_NOARGS, DISPLAYTRANSFORM_GETCOLORTIMINGCC__DOC__ },
  75. { "setColorTimingCC",
  76. PyOCIO_DisplayTransform_setColorTimingCC, METH_VARARGS, DISPLAYTRANSFORM_SETCOLORTIMINGCC__DOC__ },
  77. { "getChannelView",
  78. (PyCFunction) PyOCIO_DisplayTransform_getChannelView, METH_NOARGS, DISPLAYTRANSFORM_GETCHANNELVIEW__DOC__ },
  79. { "setChannelView",
  80. PyOCIO_DisplayTransform_setChannelView, METH_VARARGS, DISPLAYTRANSFORM_SETCHANNELVIEW__DOC__ },
  81. { "getDisplay",
  82. (PyCFunction) PyOCIO_DisplayTransform_getDisplay, METH_NOARGS, DISPLAYTRANSFORM_GETDISPLAY__DOC__ },
  83. { "setDisplay",
  84. PyOCIO_DisplayTransform_setDisplay, METH_VARARGS, DISPLAYTRANSFORM_SETDISPLAY__DOC__ },
  85. { "getView",
  86. (PyCFunction) PyOCIO_DisplayTransform_getView, METH_NOARGS, DISPLAYTRANSFORM_GETVIEW__DOC__ },
  87. { "setView",
  88. PyOCIO_DisplayTransform_setView, METH_VARARGS, DISPLAYTRANSFORM_SETVIEW__DOC__ },
  89. { "getDisplayCC",
  90. (PyCFunction) PyOCIO_DisplayTransform_getDisplayCC, METH_NOARGS, DISPLAYTRANSFORM_GETDISPLAYCC__DOC__ },
  91. { "setDisplayCC",
  92. PyOCIO_DisplayTransform_setDisplayCC, METH_VARARGS, DISPLAYTRANSFORM_SETDISPLAYCC__DOC__ },
  93. { "getLooksOverride",
  94. (PyCFunction) PyOCIO_DisplayTransform_getLooksOverride, METH_NOARGS, DISPLAYTRANSFORM_GETLOOKSOVERRIDE__DOC__ },
  95. { "setLooksOverride",
  96. PyOCIO_DisplayTransform_setLooksOverride, METH_VARARGS, DISPLAYTRANSFORM_SETLOOKSOVERRIDE__DOC__ },
  97. { "getLooksOverrideEnabled",
  98. (PyCFunction) PyOCIO_DisplayTransform_getLooksOverrideEnabled, METH_NOARGS, DISPLAYTRANSFORM_GETLOOKSOVERRIDEENABLED__DOC__ },
  99. { "setLooksOverrideEnabled",
  100. PyOCIO_DisplayTransform_setLooksOverrideEnabled, METH_VARARGS, DISPLAYTRANSFORM_SETLOOKSOVERRIDEENABLED__DOC__ },
  101. { NULL, NULL, 0, NULL }
  102. };
  103. }
  104. ///////////////////////////////////////////////////////////////////////////
  105. ///
  106. PyTypeObject PyOCIO_DisplayTransformType = {
  107. PyVarObject_HEAD_INIT(NULL, 0)
  108. "OCIO.DisplayTransform", //tp_name
  109. sizeof(PyOCIO_Transform), //tp_basicsize
  110. 0, //tp_itemsize
  111. 0, //tp_dealloc
  112. 0, //tp_print
  113. 0, //tp_getattr
  114. 0, //tp_setattr
  115. 0, //tp_compare
  116. 0, //tp_repr
  117. 0, //tp_as_number
  118. 0, //tp_as_sequence
  119. 0, //tp_as_mapping
  120. 0, //tp_hash
  121. 0, //tp_call
  122. 0, //tp_str
  123. 0, //tp_getattro
  124. 0, //tp_setattro
  125. 0, //tp_as_buffer
  126. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
  127. DISPLAYTRANSFORM__DOC__, //tp_doc
  128. 0, //tp_traverse
  129. 0, //tp_clear
  130. 0, //tp_richcompare
  131. 0, //tp_weaklistoffset
  132. 0, //tp_iter
  133. 0, //tp_iternext
  134. PyOCIO_DisplayTransform_methods, //tp_methods
  135. 0, //tp_members
  136. 0, //tp_getset
  137. &PyOCIO_TransformType, //tp_base
  138. 0, //tp_dict
  139. 0, //tp_descr_get
  140. 0, //tp_descr_set
  141. 0, //tp_dictoffset
  142. (initproc) PyOCIO_DisplayTransform_init, //tp_init
  143. 0, //tp_alloc
  144. 0, //tp_new
  145. 0, //tp_free
  146. 0, //tp_is_gc
  147. };
  148. namespace
  149. {
  150. ///////////////////////////////////////////////////////////////////////
  151. ///
  152. int PyOCIO_DisplayTransform_init(PyOCIO_Transform * self, PyObject * /*args*/, PyObject * /*kwds*/)
  153. {
  154. OCIO_PYTRY_ENTER()
  155. return BuildPyTransformObject<DisplayTransformRcPtr>(self, DisplayTransform::Create());
  156. OCIO_PYTRY_EXIT(-1)
  157. }
  158. PyObject * PyOCIO_DisplayTransform_getInputColorSpaceName(PyObject * self)
  159. {
  160. OCIO_PYTRY_ENTER()
  161. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  162. return PyString_FromString(transform->getInputColorSpaceName());
  163. OCIO_PYTRY_EXIT(NULL)
  164. }
  165. PyObject * PyOCIO_DisplayTransform_setInputColorSpaceName(PyObject * self, PyObject * args)
  166. {
  167. OCIO_PYTRY_ENTER()
  168. char* name = 0;
  169. if (!PyArg_ParseTuple(args, "s:setInputColorSpaceName",
  170. &name)) return NULL;
  171. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  172. transform->setInputColorSpaceName(name);
  173. Py_RETURN_NONE;
  174. OCIO_PYTRY_EXIT(NULL)
  175. }
  176. PyObject * PyOCIO_DisplayTransform_getLinearCC(PyObject * self)
  177. {
  178. OCIO_PYTRY_ENTER()
  179. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  180. return BuildConstPyTransform(transform->getLinearCC());
  181. OCIO_PYTRY_EXIT(NULL)
  182. }
  183. PyObject * PyOCIO_DisplayTransform_setLinearCC(PyObject * self, PyObject * args)
  184. {
  185. OCIO_PYTRY_ENTER()
  186. PyObject * pyCC = 0;
  187. if (!PyArg_ParseTuple(args, "O:setLinearCC",
  188. &pyCC)) return NULL;
  189. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  190. ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
  191. transform->setLinearCC(cc);
  192. Py_RETURN_NONE;
  193. OCIO_PYTRY_EXIT(NULL)
  194. }
  195. PyObject * PyOCIO_DisplayTransform_getColorTimingCC(PyObject * self)
  196. {
  197. OCIO_PYTRY_ENTER()
  198. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  199. return BuildConstPyTransform(transform->getColorTimingCC());
  200. OCIO_PYTRY_EXIT(NULL)
  201. }
  202. PyObject * PyOCIO_DisplayTransform_setColorTimingCC(PyObject * self, PyObject * args)
  203. {
  204. OCIO_PYTRY_ENTER()
  205. PyObject* pyCC = 0;
  206. if (!PyArg_ParseTuple(args, "O:setColorTimingCC",
  207. &pyCC)) return NULL;
  208. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  209. ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
  210. transform->setColorTimingCC(cc);
  211. Py_RETURN_NONE;
  212. OCIO_PYTRY_EXIT(NULL)
  213. }
  214. PyObject * PyOCIO_DisplayTransform_getChannelView(PyObject * self)
  215. {
  216. OCIO_PYTRY_ENTER()
  217. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  218. return BuildConstPyTransform(transform->getChannelView());
  219. OCIO_PYTRY_EXIT(NULL)
  220. }
  221. PyObject * PyOCIO_DisplayTransform_setChannelView(PyObject * self, PyObject * args)
  222. {
  223. OCIO_PYTRY_ENTER()
  224. PyObject* pyCC = 0;
  225. if (!PyArg_ParseTuple(args, "O:setChannelView",
  226. &pyCC)) return NULL;
  227. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  228. ConstTransformRcPtr t = GetConstTransform(pyCC, true);
  229. transform->setChannelView(t);
  230. Py_RETURN_NONE;
  231. OCIO_PYTRY_EXIT(NULL)
  232. }
  233. PyObject * PyOCIO_DisplayTransform_getDisplay(PyObject * self)
  234. {
  235. OCIO_PYTRY_ENTER()
  236. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  237. return PyString_FromString(transform->getDisplay());
  238. OCIO_PYTRY_EXIT(NULL)
  239. }
  240. PyObject * PyOCIO_DisplayTransform_setDisplay(PyObject * self, PyObject * args)
  241. {
  242. OCIO_PYTRY_ENTER()
  243. char* str = 0;
  244. if (!PyArg_ParseTuple(args, "s:setDisplay",
  245. &str)) return NULL;
  246. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  247. transform->setDisplay(str);
  248. Py_RETURN_NONE;
  249. OCIO_PYTRY_EXIT(NULL)
  250. }
  251. PyObject * PyOCIO_DisplayTransform_getView(PyObject * self)
  252. {
  253. OCIO_PYTRY_ENTER()
  254. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  255. return PyString_FromString(transform->getView());
  256. OCIO_PYTRY_EXIT(NULL)
  257. }
  258. PyObject * PyOCIO_DisplayTransform_setView(PyObject * self, PyObject * args)
  259. {
  260. OCIO_PYTRY_ENTER()
  261. char* str = 0;
  262. if (!PyArg_ParseTuple(args, "s:setView",
  263. &str)) return NULL;
  264. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  265. transform->setView(str);
  266. Py_RETURN_NONE;
  267. OCIO_PYTRY_EXIT(NULL)
  268. }
  269. PyObject * PyOCIO_DisplayTransform_getDisplayCC(PyObject * self)
  270. {
  271. OCIO_PYTRY_ENTER()
  272. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  273. return BuildConstPyTransform(transform->getDisplayCC());
  274. OCIO_PYTRY_EXIT(NULL)
  275. }
  276. PyObject * PyOCIO_DisplayTransform_setDisplayCC(PyObject * self, PyObject * args)
  277. {
  278. OCIO_PYTRY_ENTER()
  279. PyObject* pyCC = 0;
  280. if (!PyArg_ParseTuple(args,"O:setDisplayCC",
  281. &pyCC)) return NULL;
  282. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  283. ConstTransformRcPtr cc = GetConstTransform(pyCC, true);
  284. transform->setDisplayCC(cc);
  285. Py_RETURN_NONE;
  286. OCIO_PYTRY_EXIT(NULL)
  287. }
  288. PyObject * PyOCIO_DisplayTransform_getLooksOverride(PyObject * self)
  289. {
  290. OCIO_PYTRY_ENTER()
  291. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  292. return PyString_FromString(transform->getLooksOverride());
  293. OCIO_PYTRY_EXIT(NULL)
  294. }
  295. PyObject * PyOCIO_DisplayTransform_setLooksOverride(PyObject * self, PyObject * args)
  296. {
  297. OCIO_PYTRY_ENTER()
  298. char* str = 0;
  299. if (!PyArg_ParseTuple(args,"s:setLooksOverride",
  300. &str)) return NULL;
  301. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  302. transform->setLooksOverride(str);
  303. Py_RETURN_NONE;
  304. OCIO_PYTRY_EXIT(NULL)
  305. }
  306. PyObject * PyOCIO_DisplayTransform_getLooksOverrideEnabled(PyObject * self)
  307. {
  308. OCIO_PYTRY_ENTER()
  309. ConstDisplayTransformRcPtr transform = GetConstDisplayTransform(self);
  310. return PyBool_FromLong(transform->getLooksOverrideEnabled());
  311. OCIO_PYTRY_EXIT(NULL)
  312. }
  313. PyObject * PyOCIO_DisplayTransform_setLooksOverrideEnabled(PyObject * self, PyObject * args)
  314. {
  315. OCIO_PYTRY_ENTER()
  316. bool enabled = false;
  317. if (!PyArg_ParseTuple(args, "O&:setLooksOverrideEnabled",
  318. ConvertPyObjectToBool, &enabled)) return NULL;
  319. DisplayTransformRcPtr transform = GetEditableDisplayTransform(self);
  320. transform->setLooksOverrideEnabled(enabled);
  321. Py_RETURN_NONE;
  322. OCIO_PYTRY_EXIT(NULL)
  323. }
  324. }
  325. }
  326. OCIO_NAMESPACE_EXIT