/src/pyglue/PyLookTransform.cpp

http://github.com/imageworks/OpenColorIO · C++ · 216 lines · 157 code · 24 blank · 35 comment · 8 complexity · 3ee1cb5a4c9a34fa8f3df36f9cf8d052 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 GetConstLookTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
  32. ConstLookTransformRcPtr, LookTransform>(pyobject, PyOCIO_LookTransformType)
  33. #define GetEditableLookTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
  34. LookTransformRcPtr, LookTransform>(pyobject, PyOCIO_LookTransformType)
  35. OCIO_NAMESPACE_ENTER
  36. {
  37. namespace
  38. {
  39. ///////////////////////////////////////////////////////////////////////
  40. ///
  41. int PyOCIO_LookTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds);
  42. PyObject * PyOCIO_LookTransform_getSrc(PyObject * self);
  43. PyObject * PyOCIO_LookTransform_setSrc(PyObject * self, PyObject * args);
  44. PyObject * PyOCIO_LookTransform_getDst(PyObject * self);
  45. PyObject * PyOCIO_LookTransform_setDst(PyObject * self, PyObject * args);
  46. PyObject * PyOCIO_LookTransform_getLooks(PyObject * self);
  47. PyObject * PyOCIO_LookTransform_setLooks(PyObject * self, PyObject * args);
  48. ///////////////////////////////////////////////////////////////////////
  49. ///
  50. PyMethodDef PyOCIO_LookTransform_methods[] = {
  51. { "getSrc",
  52. (PyCFunction) PyOCIO_LookTransform_getSrc, METH_NOARGS, LOOKTRANSFORM_GETSRC__DOC__ },
  53. { "setSrc",
  54. PyOCIO_LookTransform_setSrc, METH_VARARGS, LOOKTRANSFORM_SETSRC__DOC__ },
  55. { "getDst",
  56. (PyCFunction) PyOCIO_LookTransform_getDst, METH_NOARGS, LOOKTRANSFORM_GETDST__DOC__ },
  57. { "setDst",
  58. PyOCIO_LookTransform_setDst, METH_VARARGS, LOOKTRANSFORM_SETDST__DOC__ },
  59. { "getLooks",
  60. (PyCFunction) PyOCIO_LookTransform_getLooks, METH_NOARGS, LOOKTRANSFORM_GETLOOKS__DOC__ },
  61. { "setLooks",
  62. PyOCIO_LookTransform_setLooks, METH_VARARGS, LOOKTRANSFORM_SETLOOKS__DOC__ },
  63. { NULL, NULL, 0, NULL }
  64. };
  65. }
  66. ///////////////////////////////////////////////////////////////////////////
  67. ///
  68. PyTypeObject PyOCIO_LookTransformType = {
  69. PyVarObject_HEAD_INIT(NULL, 0) //ob_size
  70. "OCIO.LookTransform", //tp_name
  71. sizeof(PyOCIO_Transform), //tp_basicsize
  72. 0, //tp_itemsize
  73. 0, //tp_dealloc
  74. 0, //tp_print
  75. 0, //tp_getattr
  76. 0, //tp_setattr
  77. 0, //tp_compare
  78. 0, //tp_repr
  79. 0, //tp_as_number
  80. 0, //tp_as_sequence
  81. 0, //tp_as_mapping
  82. 0, //tp_hash
  83. 0, //tp_call
  84. 0, //tp_str
  85. 0, //tp_getattro
  86. 0, //tp_setattro
  87. 0, //tp_as_buffer
  88. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
  89. LOOKTRANSFORM__DOC__, //tp_doc
  90. 0, //tp_traverse
  91. 0, //tp_clear
  92. 0, //tp_richcompare
  93. 0, //tp_weaklistoffset
  94. 0, //tp_iter
  95. 0, //tp_iternext
  96. PyOCIO_LookTransform_methods, //tp_methods
  97. 0, //tp_members
  98. 0, //tp_getset
  99. &PyOCIO_TransformType, //tp_base
  100. 0, //tp_dict
  101. 0, //tp_descr_get
  102. 0, //tp_descr_set
  103. 0, //tp_dictoffset
  104. (initproc) PyOCIO_LookTransform_init, //tp_init
  105. 0, //tp_alloc
  106. 0, //tp_new
  107. 0, //tp_free
  108. 0, //tp_is_gc
  109. };
  110. namespace
  111. {
  112. ///////////////////////////////////////////////////////////////////////
  113. ///
  114. int PyOCIO_LookTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds)
  115. {
  116. OCIO_PYTRY_ENTER()
  117. LookTransformRcPtr ptr = LookTransform::Create();
  118. int ret = BuildPyTransformObject<LookTransformRcPtr>(self, ptr);
  119. char* src = NULL;
  120. char* dst = NULL;
  121. char* looks = NULL;
  122. char* direction = NULL;
  123. static const char *kwlist[] = { "src", "dst", "looks", "direction",
  124. NULL };
  125. if(!PyArg_ParseTupleAndKeywords(args, kwds, "|ssss",
  126. const_cast<char **>(kwlist),
  127. &src, &dst, &looks, &direction)) return -1;
  128. if(src) ptr->setSrc(src);
  129. if(dst) ptr->setDst(dst);
  130. if(looks) ptr->setLooks(looks);
  131. if(direction) ptr->setDirection(TransformDirectionFromString(direction));
  132. return ret;
  133. OCIO_PYTRY_EXIT(-1)
  134. }
  135. PyObject * PyOCIO_LookTransform_getSrc(PyObject * self)
  136. {
  137. OCIO_PYTRY_ENTER()
  138. ConstLookTransformRcPtr transform = GetConstLookTransform(self);
  139. return PyString_FromString(transform->getSrc());
  140. OCIO_PYTRY_EXIT(NULL)
  141. }
  142. PyObject * PyOCIO_LookTransform_setSrc(PyObject * self, PyObject * args)
  143. {
  144. OCIO_PYTRY_ENTER()
  145. const char* str = 0;
  146. if (!PyArg_ParseTuple(args, "s:setSrc",
  147. &str)) return NULL;
  148. LookTransformRcPtr transform = GetEditableLookTransform(self);
  149. transform->setSrc(str);
  150. Py_RETURN_NONE;
  151. OCIO_PYTRY_EXIT(NULL)
  152. }
  153. PyObject * PyOCIO_LookTransform_getDst(PyObject * self)
  154. {
  155. OCIO_PYTRY_ENTER()
  156. ConstLookTransformRcPtr transform = GetConstLookTransform(self);
  157. return PyString_FromString(transform->getDst());
  158. OCIO_PYTRY_EXIT(NULL)
  159. }
  160. PyObject * PyOCIO_LookTransform_setDst(PyObject * self, PyObject * args)
  161. {
  162. OCIO_PYTRY_ENTER()
  163. const char* str = 0;
  164. if (!PyArg_ParseTuple(args, "s:setDst",
  165. &str)) return NULL;
  166. LookTransformRcPtr transform = GetEditableLookTransform(self);
  167. transform->setDst(str);
  168. Py_RETURN_NONE;
  169. OCIO_PYTRY_EXIT(NULL)
  170. }
  171. PyObject * PyOCIO_LookTransform_getLooks(PyObject * self)
  172. {
  173. OCIO_PYTRY_ENTER()
  174. ConstLookTransformRcPtr transform = GetConstLookTransform(self);
  175. return PyString_FromString( transform->getLooks() );
  176. OCIO_PYTRY_EXIT(NULL)
  177. }
  178. PyObject * PyOCIO_LookTransform_setLooks(PyObject * self, PyObject * args)
  179. {
  180. OCIO_PYTRY_ENTER()
  181. const char* str = 0;
  182. if (!PyArg_ParseTuple(args, "s:setLooks",
  183. &str)) return NULL;
  184. LookTransformRcPtr transform = GetEditableLookTransform(self);
  185. transform->setLooks(str);
  186. Py_RETURN_NONE;
  187. OCIO_PYTRY_EXIT(NULL)
  188. }
  189. }
  190. }
  191. OCIO_NAMESPACE_EXIT