PageRenderTime 63ms CodeModel.GetById 12ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 1ms

/src/pyglue/PyFileTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 258 lines | 196 code | 27 blank | 35 comment | 10 complexity | 42663f1faeeadd9e6efcbde8e2e5861e 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 GetConstFileTransform(pyobject) GetConstPyOCIO<PyOCIO_Transform, \
 36    ConstFileTransformRcPtr, FileTransform>(pyobject, \
 37    PyOCIO_FileTransformType)
 38
 39#define GetEditableFileTransform(pyobject) GetEditablePyOCIO<PyOCIO_Transform, \
 40    FileTransformRcPtr, FileTransform>(pyobject, \
 41    PyOCIO_FileTransformType);
 42
 43OCIO_NAMESPACE_ENTER
 44{
 45    
 46    namespace
 47    {
 48        
 49        ///////////////////////////////////////////////////////////////////////
 50        ///
 51        
 52        int PyOCIO_FileTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds);
 53        PyObject * PyOCIO_FileTransform_getSrc(PyObject * self);
 54        PyObject * PyOCIO_FileTransform_setSrc(PyObject * self, PyObject * args);
 55        PyObject * PyOCIO_FileTransform_getCCCId(PyObject * self);
 56        PyObject * PyOCIO_FileTransform_setCCCId(PyObject * self, PyObject * args);
 57        PyObject * PyOCIO_FileTransform_getInterpolation(PyObject * self);
 58        PyObject * PyOCIO_FileTransform_setInterpolation(PyObject * self, PyObject * args);
 59        PyObject * PyOCIO_FileTransform_getNumFormats(PyObject * self);
 60        PyObject * PyOCIO_FileTransform_getFormatNameByIndex(PyObject * self, PyObject * args);
 61        PyObject * PyOCIO_FileTransform_getFormatExtensionByIndex(PyObject * self, PyObject * args);
 62        
 63        ///////////////////////////////////////////////////////////////////////
 64        ///
 65        
 66        PyMethodDef PyOCIO_FileTransform_methods[] = {
 67            { "getSrc",
 68            (PyCFunction) PyOCIO_FileTransform_getSrc, METH_NOARGS, FILETRANSFORM_GETSRC__DOC__ },
 69            { "setSrc",
 70            PyOCIO_FileTransform_setSrc, METH_VARARGS, FILETRANSFORM_SETSRC__DOC__ },
 71            { "getCCCId",
 72            (PyCFunction) PyOCIO_FileTransform_getCCCId, METH_NOARGS, FILETRANSFORM_GETCCCID__DOC__ },
 73            { "setCCCId",
 74            PyOCIO_FileTransform_setCCCId, METH_VARARGS, FILETRANSFORM_SETCCCID__DOC__ },
 75            { "getInterpolation",
 76            (PyCFunction) PyOCIO_FileTransform_getInterpolation, METH_NOARGS, FILETRANSFORM_GETINTERPOLATION__DOC__ },
 77            { "setInterpolation",
 78            PyOCIO_FileTransform_setInterpolation, METH_VARARGS, FILETRANSFORM_SETINTERPOLATION__DOC__ },
 79            { "getNumFormats",
 80            (PyCFunction) PyOCIO_FileTransform_getNumFormats, METH_VARARGS, FILETRANSFORM_GETNUMFORMATS__DOC__ },
 81            { "getFormatNameByIndex",
 82            PyOCIO_FileTransform_getFormatNameByIndex, METH_VARARGS, FILETRANSFORM_GETFORMATNAMEBYINDEX__DOC__ },
 83            { "getFormatExtensionByIndex",
 84            PyOCIO_FileTransform_getFormatExtensionByIndex, METH_VARARGS, FILETRANSFORM_GETFORMATEXTENSIONBYINDEX__DOC__ },
 85            { NULL, NULL, 0, NULL }
 86        };
 87        
 88    }
 89    
 90    ///////////////////////////////////////////////////////////////////////////
 91    ///
 92    
 93    PyTypeObject PyOCIO_FileTransformType = {
 94        PyVarObject_HEAD_INIT(NULL, 0)
 95        "OCIO.FileTransform",                       //tp_name
 96        sizeof(PyOCIO_Transform),                   //tp_basicsize
 97        0,                                          //tp_itemsize
 98        0,                                          //tp_dealloc
 99        0,                                          //tp_print
100        0,                                          //tp_getattr
101        0,                                          //tp_setattr
102        0,                                          //tp_compare
103        0,                                          //tp_repr
104        0,                                          //tp_as_number
105        0,                                          //tp_as_sequence
106        0,                                          //tp_as_mapping
107        0,                                          //tp_hash 
108        0,                                          //tp_call
109        0,                                          //tp_str
110        0,                                          //tp_getattro
111        0,                                          //tp_setattro
112        0,                                          //tp_as_buffer
113        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   //tp_flags
114        FILETRANSFORM__DOC__,                       //tp_doc 
115        0,                                          //tp_traverse 
116        0,                                          //tp_clear 
117        0,                                          //tp_richcompare 
118        0,                                          //tp_weaklistoffset 
119        0,                                          //tp_iter 
120        0,                                          //tp_iternext 
121        PyOCIO_FileTransform_methods,               //tp_methods 
122        0,                                          //tp_members 
123        0,                                          //tp_getset 
124        &PyOCIO_TransformType,                      //tp_base 
125        0,                                          //tp_dict 
126        0,                                          //tp_descr_get 
127        0,                                          //tp_descr_set 
128        0,                                          //tp_dictoffset 
129        (initproc) PyOCIO_FileTransform_init,       //tp_init 
130        0,                                          //tp_alloc 
131        0,                                          //tp_new 
132        0,                                          //tp_free
133        0,                                          //tp_is_gc
134    };
135    
136    namespace
137    {
138        
139        ///////////////////////////////////////////////////////////////////////
140        ///
141        
142        int PyOCIO_FileTransform_init(PyOCIO_Transform * self, PyObject * args, PyObject * kwds)
143        {
144            OCIO_PYTRY_ENTER()
145            FileTransformRcPtr ptr = FileTransform::Create();
146            int ret = BuildPyTransformObject<FileTransformRcPtr>(self, ptr);
147            char* src = NULL;
148            char* cccid = NULL;
149            char* interpolation = NULL;
150            char* direction = NULL;
151            static const char *kwlist[] = { "src", "cccid", "interpolation",
152                "direction", NULL };
153            if(!PyArg_ParseTupleAndKeywords(args, kwds, "|ssss",
154                const_cast<char **>(kwlist),
155                &src, &cccid, &interpolation, &direction)) return -1;
156            if(src) ptr->setSrc(src);
157            if(cccid) ptr->setCCCId(cccid);
158            if(interpolation) ptr->setInterpolation(InterpolationFromString(interpolation));
159            if(direction) ptr->setDirection(TransformDirectionFromString(direction));
160            return ret;
161            OCIO_PYTRY_EXIT(-1)
162        }
163        
164        PyObject * PyOCIO_FileTransform_getSrc(PyObject * self)
165        {
166            OCIO_PYTRY_ENTER()
167            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
168            return PyString_FromString(transform->getSrc());
169            OCIO_PYTRY_EXIT(NULL)
170        }
171        
172        PyObject * PyOCIO_FileTransform_setSrc(PyObject * self, PyObject * args)
173        {
174            OCIO_PYTRY_ENTER()
175            char* src = 0;
176            if (!PyArg_ParseTuple(args, "s:setSrc",
177                &src)) return NULL;
178            FileTransformRcPtr transform = GetEditableFileTransform(self);
179            transform->setSrc(src);
180            Py_RETURN_NONE;
181            OCIO_PYTRY_EXIT(NULL)
182        }
183        
184        PyObject * PyOCIO_FileTransform_getCCCId(PyObject * self)
185        {
186            OCIO_PYTRY_ENTER()
187            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
188            return PyString_FromString(transform->getCCCId());
189            OCIO_PYTRY_EXIT(NULL)
190        }
191        
192        PyObject * PyOCIO_FileTransform_setCCCId(PyObject * self, PyObject * args)
193        {
194            OCIO_PYTRY_ENTER()
195            char* id = 0;
196            if (!PyArg_ParseTuple(args,"s:setCCCId",
197                &id)) return NULL;
198            FileTransformRcPtr transform = GetEditableFileTransform(self);
199            transform->setCCCId(id);
200            Py_RETURN_NONE;
201            OCIO_PYTRY_EXIT(NULL)
202        }
203        
204        PyObject * PyOCIO_FileTransform_getInterpolation(PyObject * self)
205        {
206            OCIO_PYTRY_ENTER()
207            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
208            Interpolation interp = transform->getInterpolation();
209            return PyString_FromString(InterpolationToString(interp));
210            OCIO_PYTRY_EXIT(NULL)
211        }
212        
213        PyObject * PyOCIO_FileTransform_setInterpolation(PyObject * self, PyObject * args)
214        {
215            OCIO_PYTRY_ENTER()
216            Interpolation interp;
217            if (!PyArg_ParseTuple(args,"O&:setInterpolation",
218                 ConvertPyObjectToInterpolation, &interp)) return NULL;
219            FileTransformRcPtr transform = GetEditableFileTransform(self);
220            transform->setInterpolation(interp);
221            Py_RETURN_NONE;
222            OCIO_PYTRY_EXIT(NULL)
223        }
224        
225        PyObject * PyOCIO_FileTransform_getNumFormats(PyObject * self)
226        {
227            OCIO_PYTRY_ENTER()
228            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
229            return PyInt_FromLong(transform->getNumFormats());
230            OCIO_PYTRY_EXIT(NULL)
231        }
232        
233        PyObject * PyOCIO_FileTransform_getFormatNameByIndex(PyObject * self, PyObject * args)
234        {
235            OCIO_PYTRY_ENTER()
236            int index = 0;
237            if (!PyArg_ParseTuple(args,"i:getFormatNameByIndex",
238                &index)) return NULL;
239            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
240            return PyString_FromString(transform->getFormatNameByIndex(index));
241            OCIO_PYTRY_EXIT(NULL)
242        }
243        
244        PyObject * PyOCIO_FileTransform_getFormatExtensionByIndex(PyObject * self, PyObject * args)
245        {
246            OCIO_PYTRY_ENTER()
247            int index = 0;
248            if (!PyArg_ParseTuple(args,"i:getFormatExtensionByIndex",
249                &index)) return NULL;
250            ConstFileTransformRcPtr transform = GetConstFileTransform(self);
251            return PyString_FromString(transform->getFormatExtensionByIndex(index));
252            OCIO_PYTRY_EXIT(NULL)
253        }
254        
255    }
256
257}
258OCIO_NAMESPACE_EXIT