2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2012 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Xavier Thomas
24 * ***** END GPL LICENSE BLOCK *****
29 #include <OpenColorIO/OpenColorIO.h>
32 #define OCIO_CAPI_IMPLEMENTATION
33 #include "ocio_capi.h"
35 ConstConfigRcPtr* OCIO_getCurrentConfig(void)
37 ConstConfigRcPtr* config = new ConstConfigRcPtr();
40 *config = GetCurrentConfig();
44 catch(Exception & exception)
46 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
51 void OCIO_setCurrentConfig(const ConstConfigRcPtr* config)
57 SetCurrentConfig(*config);
59 catch(Exception & exception)
61 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
66 ConstConfigRcPtr* OCIO_configCreateFromEnv(void)
68 ConstConfigRcPtr* config = new ConstConfigRcPtr();
71 *config = Config::CreateFromEnv();
75 catch(Exception & exception)
77 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
83 ConstConfigRcPtr* OCIO_configCreateFromFile(const char* filename)
85 ConstConfigRcPtr* config = new ConstConfigRcPtr();
88 *config = Config::CreateFromFile(filename);
92 catch(Exception & exception)
94 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
99 void OCIO_configRelease(ConstConfigRcPtr* config)
107 int OCIO_configGetNumColorSpaces(ConstConfigRcPtr* config)
111 return (*config)->getNumColorSpaces();
113 catch(Exception & exception)
115 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
120 const char* OCIO_configGetColorSpaceNameByIndex(ConstConfigRcPtr* config, int index)
124 return (*config)->getColorSpaceNameByIndex(index);
126 catch(Exception & exception)
128 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
133 ConstColorSpaceRcPtr* OCIO_configGetColorSpace(ConstConfigRcPtr* config, const char* name)
135 ConstColorSpaceRcPtr* cs = new ConstColorSpaceRcPtr();
138 *cs = (*config)->getColorSpace(name);
142 catch(Exception & exception)
144 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
150 int OCIO_configGetIndexForColorSpace(ConstConfigRcPtr* config, const char* name)
154 return (*config)->getIndexForColorSpace(name);
156 catch(Exception & exception)
158 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
163 const char* OCIO_configGetDefaultDisplay(ConstConfigRcPtr* config)
167 return (*config)->getDefaultDisplay();
169 catch(Exception & exception)
171 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
176 int OCIO_configGetNumDisplays(ConstConfigRcPtr* config)
180 return (*config)->getNumDisplays();
182 catch(Exception & exception)
184 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
189 const char* OCIO_configGetDisplay(ConstConfigRcPtr* config, int index)
193 return (*config)->getDisplay(index);
195 catch(Exception & exception)
197 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
202 const char* OCIO_configGetDefaultView(ConstConfigRcPtr* config, const char* display)
206 return (*config)->getDefaultView(display);
208 catch(Exception & exception)
210 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
215 int OCIO_configGetNumViews(ConstConfigRcPtr* config, const char* display)
219 return (*config)->getNumViews(display);
221 catch(Exception & exception)
223 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
228 const char* OCIO_configGetView(ConstConfigRcPtr* config, const char* display, int index)
232 return (*config)->getView(display, index);
234 catch(Exception & exception)
236 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
241 const char* OCIO_configGetDisplayColorSpaceName(ConstConfigRcPtr* config, const char* display, const char* view)
245 return (*config)->getDisplayColorSpaceName(display, view);
247 catch(Exception & exception)
249 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
257 void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr* cs)
269 ConstProcessorRcPtr* OCIO_configGetProcessorWithNames(ConstConfigRcPtr* config, const char* srcName, const char* dstName)
271 ConstProcessorRcPtr* p = new ConstProcessorRcPtr();
274 *p = (*config)->getProcessor(srcName, dstName);
278 catch(Exception & exception)
280 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
285 extern ConstProcessorRcPtr* OCIO_configGetProcessor(ConstConfigRcPtr* config, ConstTransformRcPtr* transform)
287 ConstProcessorRcPtr* p = new ConstProcessorRcPtr();
290 *p = (*config)->getProcessor(*transform);
294 catch(Exception & exception)
296 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
301 void OCIO_processorApply(ConstProcessorRcPtr* processor, PackedImageDesc* img)
305 (*processor)->apply(*img);
307 catch(Exception & exception)
309 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
313 void OCIO_processorApplyRGB(ConstProcessorRcPtr* processor, float* pixel)
315 (*processor)->applyRGB(pixel);
318 void OCIO_processorApplyRGBA(ConstProcessorRcPtr* processor, float* pixel)
320 (*processor)->applyRGBA(pixel);
323 void OCIO_processorRelease(ConstProcessorRcPtr* p)
331 const char* OCIO_colorSpaceGetName(ConstColorSpaceRcPtr* cs)
333 return (*cs)->getName();
336 const char* OCIO_colorSpaceGetFamily(ConstColorSpaceRcPtr* cs)
338 return (*cs)->getFamily();
342 extern DisplayTransformRcPtr* OCIO_createDisplayTransform(void)
344 DisplayTransformRcPtr* dt = new DisplayTransformRcPtr();
345 *dt = DisplayTransform::Create();
349 extern void OCIO_displayTransformSetInputColorSpaceName(DisplayTransformRcPtr* dt, const char * name)
351 (*dt)->setInputColorSpaceName(name);
354 extern void OCIO_displayTransformSetDisplay(DisplayTransformRcPtr* dt, const char * name)
356 (*dt)->setDisplay(name);
359 extern void OCIO_displayTransformSetView(DisplayTransformRcPtr* dt, const char * name)
361 (*dt)->setView(name);
364 extern void OCIO_displayTransformSetDisplayCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *t)
366 (*dt)->setDisplayCC(*t);
369 extern void OCIO_displayTransformSetLinearCC(DisplayTransformRcPtr *dt, ConstTransformRcPtr *t)
371 (*dt)->setLinearCC(*t);
374 extern void OCIO_displayTransformRelease(DisplayTransformRcPtr* dt)
382 PackedImageDesc* OCIO_createPackedImageDesc(float * data, long width, long height, long numChannels,
383 long chanStrideBytes, long xStrideBytes, long yStrideBytes)
387 PackedImageDesc* id = new PackedImageDesc(data, width, height, numChannels, chanStrideBytes, xStrideBytes, yStrideBytes);
390 catch(Exception & exception)
392 std::cerr << "OpenColorIO Error: " << exception.what() << std::endl;
397 void OCIO_packedImageDescRelease(PackedImageDesc* id)
405 ExponentTransformRcPtr *OCIO_createExponentTransform(void)
407 ExponentTransformRcPtr *et = new ExponentTransformRcPtr();
409 *et = ExponentTransform::Create();
414 void OCIO_exponentTransformSetValue(ExponentTransformRcPtr *et, const float *exponent)
416 (*et)->setValue(exponent);
419 void OCIO_exponentTransformRelease(ExponentTransformRcPtr *et)
424 MatrixTransformRcPtr *OCIO_createMatrixTransform(void)
426 MatrixTransformRcPtr *mt = new MatrixTransformRcPtr();
428 *mt = MatrixTransform::Create();
433 void OCIO_matrixTransformSetValue(MatrixTransformRcPtr *mt, const float *m44, const float *offset4)
435 (*mt)->setValue(m44, offset4);
438 void OCIO_matrixTransformRelease(MatrixTransformRcPtr *mt)
443 void OCIO_matrixTransformScale(float * m44, float * offset4, const float *scale4f)
445 MatrixTransform::Scale(m44, offset4, scale4f);