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