PageRenderTime 22ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/pyglue/PyColorSpaceTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 187 lines | 130 code | 22 blank | 35 comment | 6 complexity | 870ad5682afc7ff90cae0248f9a127da MD5 | raw file
Possible License(s): BSD-3-Clause
  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 GetConstColorSpaceTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
  32. ConstColorSpaceTransformRcPtr, ColorSpaceTransform>(pyobject, \
  33. PyOCIO_ColorSpaceTransformType)
  34. #define GetEditableColorSpaceTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
  35. ColorSpaceTransformRcPtr, ColorSpaceTransform>(pyobject, \
  36. PyOCIO_ColorSpaceTransformType);
  37. OCIO_NAMESPACE_ENTER
  38. {
  39. namespace
  40. {
  41. ///////////////////////////////////////////////////////////////////////
  42. ///
  43. int PyOCIO_ColorSpaceTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds);
  44. PyObject * PyOCIO_ColorSpaceTransform_getSrc(PyObject * self);
  45. PyObject * PyOCIO_ColorSpaceTransform_setSrc(PyObject * self, PyObject * args);
  46. PyObject * PyOCIO_ColorSpaceTransform_getDst(PyObject * self);
  47. PyObject * PyOCIO_ColorSpaceTransform_setDst(PyObject * self, PyObject * args);
  48. ///////////////////////////////////////////////////////////////////////
  49. ///
  50. PyMethodDef PyOCIO_ColorSpaceTransform_methods[] = {
  51. { "getSrc",
  52. (PyCFunction) PyOCIO_ColorSpaceTransform_getSrc, METH_NOARGS, COLORSPACETRANSFORM_GETSRC__DOC__ },
  53. { "setSrc",
  54. PyOCIO_ColorSpaceTransform_setSrc, METH_VARARGS, COLORSPACETRANSFORM_SETSRC__DOC__ },
  55. { "getDst",
  56. (PyCFunction) PyOCIO_ColorSpaceTransform_getDst, METH_NOARGS, COLORSPACETRANSFORM_GETDST__DOC__ },
  57. { "setDst",
  58. PyOCIO_ColorSpaceTransform_setDst, METH_VARARGS, COLORSPACETRANSFORM_SETDST__DOC__ },
  59. { NULL, NULL, 0, NULL }
  60. };
  61. }
  62. ///////////////////////////////////////////////////////////////////////////
  63. ///
  64. PyTypeObject PyOCIO_ColorSpaceTransformType = {
  65. PyVarObject_HEAD_INIT(NULL, 0)
  66. "OCIO.ColorSpaceTransform", //tp_name
  67. sizeof(PyOCIO_Transform), //tp_basicsize
  68. 0, //tp_itemsize
  69. 0, //tp_dealloc
  70. 0, //tp_print
  71. 0, //tp_getattr
  72. 0, //tp_setattr
  73. 0, //tp_compare
  74. 0, //tp_repr
  75. 0, //tp_as_number
  76. 0, //tp_as_sequence
  77. 0, //tp_as_mapping
  78. 0, //tp_hash
  79. 0, //tp_call
  80. 0, //tp_str
  81. 0, //tp_getattro
  82. 0, //tp_setattro
  83. 0, //tp_as_buffer
  84. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
  85. COLORSPACETRANSFORM__DOC__, //tp_doc
  86. 0, //tp_traverse
  87. 0, //tp_clear
  88. 0, //tp_richcompare
  89. 0, //tp_weaklistoffset
  90. 0, //tp_iter
  91. 0, //tp_iternext
  92. PyOCIO_ColorSpaceTransform_methods, //tp_methods
  93. 0, //tp_members
  94. 0, //tp_getset
  95. &PyOCIO_TransformType, //tp_base
  96. 0, //tp_dict
  97. 0, //tp_descr_get
  98. 0, //tp_descr_set
  99. 0, //tp_dictoffset
  100. (initproc) PyOCIO_ColorSpaceTransform_init, //tp_init
  101. 0, //tp_alloc
  102. 0, //tp_new
  103. 0, //tp_free
  104. 0, //tp_is_gc
  105. };
  106. namespace
  107. {
  108. ///////////////////////////////////////////////////////////////////////
  109. ///
  110. int PyOCIO_ColorSpaceTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds)
  111. {
  112. OCIO_PYTRY_ENTER()
  113. ColorSpaceTransformRcPtr ptr = ColorSpaceTransform::Create();
  114. int ret = BuildPyTransformObject<ColorSpaceTransformRcPtr>(self, ptr);
  115. char* src = NULL;
  116. char* dst = NULL;
  117. char* direction = NULL;
  118. static const char* kwlist[] = { "src", "dst", "direction", NULL };
  119. if(!PyArg_ParseTupleAndKeywords(args, kwds, "|sss",
  120. const_cast<char **>(kwlist),
  121. &src, &dst, &direction)) return -1;
  122. if(src) ptr->setSrc(src);
  123. if(dst) ptr->setDst(dst);
  124. if(direction) ptr->setDirection(TransformDirectionFromString(direction));
  125. return ret;
  126. OCIO_PYTRY_EXIT(-1)
  127. }
  128. PyObject * PyOCIO_ColorSpaceTransform_getSrc(PyObject * self)
  129. {
  130. OCIO_PYTRY_ENTER()
  131. ConstColorSpaceTransformRcPtr transform = GetConstColorSpaceTransform(self);
  132. return PyString_FromString(transform->getSrc());
  133. OCIO_PYTRY_EXIT(NULL)
  134. }
  135. PyObject * PyOCIO_ColorSpaceTransform_setSrc(PyObject * self, PyObject * args)
  136. {
  137. OCIO_PYTRY_ENTER()
  138. const char* str = 0;
  139. if (!PyArg_ParseTuple(args, "s:setSrc", &str)) return NULL;
  140. ColorSpaceTransformRcPtr transform = GetEditableColorSpaceTransform(self);
  141. transform->setSrc(str);
  142. Py_RETURN_NONE;
  143. OCIO_PYTRY_EXIT(NULL)
  144. }
  145. PyObject * PyOCIO_ColorSpaceTransform_getDst(PyObject * self)
  146. {
  147. OCIO_PYTRY_ENTER()
  148. ConstColorSpaceTransformRcPtr transform = GetConstColorSpaceTransform(self);
  149. return PyString_FromString(transform->getDst());
  150. OCIO_PYTRY_EXIT(NULL)
  151. }
  152. PyObject * PyOCIO_ColorSpaceTransform_setDst(PyObject * self, PyObject * args)
  153. {
  154. OCIO_PYTRY_ENTER()
  155. const char* str = 0;
  156. if (!PyArg_ParseTuple(args, "s:setDst", &str)) return NULL;
  157. ColorSpaceTransformRcPtr transform = GetEditableColorSpaceTransform(self);
  158. transform->setDst(str);
  159. Py_RETURN_NONE;
  160. OCIO_PYTRY_EXIT(NULL)
  161. }
  162. }
  163. }
  164. OCIO_NAMESPACE_EXIT