2012-09-15 10:03:17 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Xavier Thomas
|
|
|
|
* Lukas Toene,
|
|
|
|
* Sergey Sharybin
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2013-03-29 16:02:27 +00:00
|
|
|
#include <sstream>
|
2012-09-15 10:03:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-03-29 16:02:27 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
#include <OpenGL/glu.h>
|
|
|
|
#else
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#endif
|
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
#include <OpenColorIO/OpenColorIO.h>
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
using namespace OCIO_NAMESPACE;
|
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2012-10-04 13:39:08 +00:00
|
|
|
#include "ocio_impl.h"
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2012-09-26 13:21:10 +00:00
|
|
|
#if !defined(WITH_ASSERT_ABORT)
|
2012-09-15 10:03:17 +00:00
|
|
|
# define OCIO_abort()
|
|
|
|
#else
|
|
|
|
# include <stdlib.h>
|
|
|
|
# define OCIO_abort() abort()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# define __func__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void OCIO_reportError(const char *err)
|
|
|
|
{
|
|
|
|
std::cerr << "OpenColorIO Error: " << err << std::endl;
|
|
|
|
|
2012-09-26 13:21:10 +00:00
|
|
|
OCIO_abort();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OCIO_reportException(Exception &exception)
|
|
|
|
{
|
|
|
|
OCIO_reportError(exception.what());
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstConfigRcPtr *OCIOImpl::getCurrentConfig(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
*config = GetCurrentConfig();
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
if (*config)
|
|
|
|
return (OCIO_ConstConfigRcPtr *) config;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::setCurrentConfig(const OCIO_ConstConfigRcPtr *config)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
SetCurrentConfig(*(ConstConfigRcPtr *) config);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromEnv(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
*config = Config::CreateFromEnv();
|
|
|
|
|
|
|
|
if (*config)
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ConstConfigRcPtr *) config;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromFile(const char *filename)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
*config = Config::CreateFromFile(filename);
|
|
|
|
|
|
|
|
if (*config)
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ConstConfigRcPtr *) config;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(config, ConstConfigRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::configRelease(OCIO_ConstConfigRcPtr *config)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((ConstConfigRcPtr *) config, ConstConfigRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::configGetNumColorSpaces(OCIO_ConstConfigRcPtr *config)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getNumColorSpaces();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetColorSpaceNameByIndex(OCIO_ConstConfigRcPtr *config, int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getColorSpaceNameByIndex(index);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstColorSpaceRcPtr *OCIOImpl::configGetColorSpace(OCIO_ConstConfigRcPtr *config, const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstColorSpaceRcPtr *cs = OBJECT_GUARDED_NEW(ConstColorSpaceRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
*cs = (*(ConstConfigRcPtr *) config)->getColorSpace(name);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
if (*cs)
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ConstColorSpaceRcPtr *) cs;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(cs, ConstColorSpaceRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::configGetIndexForColorSpace(OCIO_ConstConfigRcPtr *config, const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getIndexForColorSpace(name);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetDefaultDisplay(OCIO_ConstConfigRcPtr *config)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getDefaultDisplay();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::configGetNumDisplays(OCIO_ConstConfigRcPtr* config)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getNumDisplays();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetDisplay(OCIO_ConstConfigRcPtr *config, int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getDisplay(index);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetDefaultView(OCIO_ConstConfigRcPtr *config, const char *display)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getDefaultView(display);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::configGetNumViews(OCIO_ConstConfigRcPtr *config, const char *display)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getNumViews(display);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetView(OCIO_ConstConfigRcPtr *config, const char *display, int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getView(display, index);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::configGetDisplayColorSpaceName(OCIO_ConstConfigRcPtr *config, const char *display, const char *view)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstConfigRcPtr *) config)->getDisplayColorSpaceName(display, view);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-09 09:48:26 +00:00
|
|
|
int OCIOImpl::configGetNumLooks(OCIO_ConstConfigRcPtr *config)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return (*(ConstConfigRcPtr *) config)->getNumLooks();
|
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OCIOImpl::configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return (*(ConstConfigRcPtr *) config)->getLookNameByIndex(index);
|
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OCIO_ConstLookRcPtr *OCIOImpl::configGetLook(OCIO_ConstConfigRcPtr *config, const char *name)
|
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstLookRcPtr *look = OBJECT_GUARDED_NEW(ConstLookRcPtr);
|
2013-09-09 09:48:26 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
*look = (*(ConstConfigRcPtr *) config)->getLook(name);
|
|
|
|
|
|
|
|
if (*look)
|
|
|
|
return (OCIO_ConstLookRcPtr *) look;
|
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(look, ConstLookRcPtr);
|
2013-09-09 09:48:26 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OCIOImpl::lookGetProcessSpace(OCIO_ConstLookRcPtr *look)
|
|
|
|
{
|
|
|
|
return (*(ConstLookRcPtr *) look)->getProcessSpace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OCIOImpl::lookRelease(OCIO_ConstLookRcPtr *look)
|
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((ConstLookRcPtr *) look, ConstLookRcPtr);
|
2013-09-09 09:48:26 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::colorSpaceIsInvertible(OCIO_ConstColorSpaceRcPtr *cs_)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
ConstColorSpaceRcPtr *cs = (ConstColorSpaceRcPtr *) cs_;
|
2012-09-15 10:03:17 +00:00
|
|
|
const char *family = (*cs)->getFamily();
|
|
|
|
|
|
|
|
if (!strcmp(family, "rrt") || !strcmp(family, "display")) {
|
|
|
|
/* assume display and rrt transformations are not invertible
|
|
|
|
* in fact some of them could be, but it doesn't make much sense to allow use them as invertible
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*cs)->isData()) {
|
|
|
|
/* data color spaces don't have transformation at all */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*cs)->getTransform(COLORSPACE_DIR_TO_REFERENCE)) {
|
|
|
|
/* if there's defined transform to reference space, color space could be converted to scene linear */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
int OCIOImpl::colorSpaceIsData(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-19 15:01:36 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstColorSpaceRcPtr *) cs)->isData();
|
2012-09-19 15:01:36 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::colorSpaceRelease(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((ConstColorSpaceRcPtr *) cs, ConstColorSpaceRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessorWithNames(OCIO_ConstConfigRcPtr *config, const char *srcName, const char *dstName)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstProcessorRcPtr *p = OBJECT_GUARDED_NEW(ConstProcessorRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
*p = (*(ConstConfigRcPtr *) config)->getProcessor(srcName, dstName);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
if (*p)
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ConstProcessorRcPtr *) p;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstProcessorRcPtr *OCIOImpl::configGetProcessor(OCIO_ConstConfigRcPtr *config, OCIO_ConstTransformRcPtr *transform)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ConstProcessorRcPtr *p = OBJECT_GUARDED_NEW(ConstProcessorRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
*p = (*(ConstConfigRcPtr *) config)->getProcessor(*(ConstTransformRcPtr *) transform);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
if (*p)
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ConstProcessorRcPtr *) p;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
|
2012-09-18 19:20:26 +00:00
|
|
|
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorApply(OCIO_ConstProcessorRcPtr *processor, OCIO_PackedImageDesc *img)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->apply(*(PackedImageDesc *) img);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorApply_predivide(OCIO_ConstProcessorRcPtr *processor, OCIO_PackedImageDesc *img_)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
2012-10-05 10:05:26 +00:00
|
|
|
PackedImageDesc *img = (PackedImageDesc *) img_;
|
2012-09-15 10:03:17 +00:00
|
|
|
int channels = img->getNumChannels();
|
|
|
|
|
|
|
|
if (channels == 4) {
|
|
|
|
float *pixels = img->getData();
|
|
|
|
|
|
|
|
int width = img->getWidth();
|
|
|
|
int height = img->getHeight();
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
float *pixel = pixels + 4 * (y * width + x);
|
|
|
|
|
2012-10-04 13:39:08 +00:00
|
|
|
processorApplyRGBA_predivide(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->apply(*img);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorApplyRGB(OCIO_ConstProcessorRcPtr *processor, float *pixel)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->applyRGB(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorApplyRGBA(OCIO_ConstProcessorRcPtr *processor, float *pixel)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->applyRGBA(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *processor, float *pixel)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
if (pixel[3] == 1.0f || pixel[3] == 0.0f) {
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->applyRGBA(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float alpha, inv_alpha;
|
|
|
|
|
|
|
|
alpha = pixel[3];
|
|
|
|
inv_alpha = 1.0f / alpha;
|
|
|
|
|
|
|
|
pixel[0] *= inv_alpha;
|
|
|
|
pixel[1] *= inv_alpha;
|
|
|
|
pixel[2] *= inv_alpha;
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ConstProcessorRcPtr *) processor)->applyRGBA(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
pixel[0] *= alpha;
|
|
|
|
pixel[1] *= alpha;
|
|
|
|
pixel[2] *= alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::processorRelease(OCIO_ConstProcessorRcPtr *p)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE(p, ConstProcessorRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::colorSpaceGetName(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstColorSpaceRcPtr *) cs)->getName();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::colorSpaceGetDescription(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstColorSpaceRcPtr *) cs)->getDescription();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *OCIOImpl::colorSpaceGetFamily(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
return (*(ConstColorSpaceRcPtr *)cs)->getFamily();
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_DisplayTransformRcPtr *OCIOImpl::createDisplayTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
DisplayTransformRcPtr *dt = OBJECT_GUARDED_NEW(DisplayTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
*dt = DisplayTransform::Create();
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_DisplayTransformRcPtr *) dt;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetInputColorSpaceName(OCIO_DisplayTransformRcPtr *dt, const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(DisplayTransformRcPtr *) dt)->setInputColorSpaceName(name);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetDisplay(OCIO_DisplayTransformRcPtr *dt, const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(DisplayTransformRcPtr *) dt)->setDisplay(name);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetView(OCIO_DisplayTransformRcPtr *dt, const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(DisplayTransformRcPtr *) dt)->setView(name);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetDisplayCC(OCIO_DisplayTransformRcPtr *dt, OCIO_ConstTransformRcPtr *t)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(DisplayTransformRcPtr *) dt)->setDisplayCC(* (ConstTransformRcPtr *) t);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetLinearCC(OCIO_DisplayTransformRcPtr *dt, OCIO_ConstTransformRcPtr *t)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(DisplayTransformRcPtr *) dt)->setLinearCC(*(ConstTransformRcPtr *) t);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 09:48:26 +00:00
|
|
|
void OCIOImpl::displayTransformSetLooksOverride(OCIO_DisplayTransformRcPtr *dt, const char *looks)
|
|
|
|
{
|
|
|
|
(*(DisplayTransformRcPtr *) dt)->setLooksOverride(looks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OCIOImpl::displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransformRcPtr *dt, bool enabled)
|
|
|
|
{
|
|
|
|
(*(DisplayTransformRcPtr *) dt)->setLooksOverrideEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr *dt)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((DisplayTransformRcPtr *) dt, DisplayTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_PackedImageDesc *OCIOImpl::createOCIO_PackedImageDesc(float *data, long width, long height, long numChannels,
|
2013-01-08 20:55:07 +00:00
|
|
|
long chanStrideBytes, long xStrideBytes, long yStrideBytes)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
void *mem = MEM_mallocN(sizeof(PackedImageDesc), __func__);
|
|
|
|
PackedImageDesc *id = new(mem) PackedImageDesc(data, width, height, numChannels, chanStrideBytes, xStrideBytes, yStrideBytes);
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_PackedImageDesc *) id;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
catch (Exception &exception) {
|
|
|
|
OCIO_reportException(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::OCIO_PackedImageDescRelease(OCIO_PackedImageDesc* id)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((PackedImageDesc *) id, PackedImageDesc);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ExponentTransformRcPtr *OCIOImpl::createExponentTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
ExponentTransformRcPtr *et = OBJECT_GUARDED_NEW(ExponentTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
*et = ExponentTransform::Create();
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_ExponentTransformRcPtr *) et;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::exponentTransformSetValue(OCIO_ExponentTransformRcPtr *et, const float *exponent)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(ExponentTransformRcPtr *) et)->setValue(exponent);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::exponentTransformRelease(OCIO_ExponentTransformRcPtr *et)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((ExponentTransformRcPtr *) et, ExponentTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_MatrixTransformRcPtr *OCIOImpl::createMatrixTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
MatrixTransformRcPtr *mt = OBJECT_GUARDED_NEW(MatrixTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
*mt = MatrixTransform::Create();
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_MatrixTransformRcPtr *) mt;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::matrixTransformSetValue(OCIO_MatrixTransformRcPtr *mt, const float *m44, const float *offset4)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
(*(MatrixTransformRcPtr *) mt)->setValue(m44, offset4);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void OCIOImpl::matrixTransformRelease(OCIO_MatrixTransformRcPtr *mt)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2013-10-09 08:46:02 +00:00
|
|
|
OBJECT_GUARDED_DELETE((MatrixTransformRcPtr *) mt, MatrixTransformRcPtr);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void OCIOImpl::matrixTransformScale(float *m44, float *offset4, const float *scale4f)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
MatrixTransform::Scale(m44, offset4, scale4f);
|
|
|
|
}
|