PageRenderTime 23ms CodeModel.GetById 2ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

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