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): Brecht van Lommel
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstring>
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "BLI_math_color.h"
|
2016-12-02 15:57:00 +00:00
|
|
|
#include "BLI_math_vector.h"
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2012-10-04 13:39:08 +00:00
|
|
|
#include "ocio_impl.h"
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
using std::max;
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
#define CONFIG_DEFAULT ((OCIO_ConstConfigRcPtr*)1)
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
enum TransformType {
|
|
|
|
TRANSFORM_LINEAR_TO_SRGB,
|
|
|
|
TRANSFORM_SRGB_TO_LINEAR,
|
|
|
|
TRANSFORM_MATRIX,
|
|
|
|
TRANSFORM_EXPONENT,
|
|
|
|
TRANSFORM_UNKNOWN,
|
|
|
|
};
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
#define COLORSPACE_LINEAR ((OCIO_ConstColorSpaceRcPtr*)1)
|
|
|
|
#define COLORSPACE_SRGB ((OCIO_ConstColorSpaceRcPtr*)2)
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
typedef struct OCIO_PackedImageDescription {
|
2012-09-15 10:03:17 +00:00
|
|
|
float *data;
|
|
|
|
long width;
|
|
|
|
long height;
|
|
|
|
long numChannels;
|
|
|
|
long chanStrideBytes;
|
|
|
|
long xStrideBytes;
|
|
|
|
long yStrideBytes;
|
2012-10-05 10:05:26 +00:00
|
|
|
} OCIO_PackedImageDescription;
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
struct FallbackTransform {
|
|
|
|
FallbackTransform()
|
|
|
|
: type(TRANSFORM_UNKNOWN),
|
|
|
|
linear_transform(NULL),
|
|
|
|
display_transform(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~FallbackTransform()
|
|
|
|
{
|
|
|
|
delete linear_transform;
|
|
|
|
delete display_transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyRGB(float *pixel)
|
|
|
|
{
|
|
|
|
if (type == TRANSFORM_LINEAR_TO_SRGB) {
|
|
|
|
applyLinearRGB(pixel);
|
|
|
|
linearrgb_to_srgb_v3_v3(pixel, pixel);
|
|
|
|
applyDisplayRGB(pixel);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_SRGB_TO_LINEAR) {
|
|
|
|
srgb_to_linearrgb_v3_v3(pixel, pixel);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_EXPONENT) {
|
|
|
|
pixel[0] = powf(max(0.0f, pixel[0]), exponent[0]);
|
|
|
|
pixel[1] = powf(max(0.0f, pixel[1]), exponent[1]);
|
|
|
|
pixel[2] = powf(max(0.0f, pixel[2]), exponent[2]);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_MATRIX) {
|
|
|
|
float r = pixel[0];
|
|
|
|
float g = pixel[1];
|
|
|
|
float b = pixel[2];
|
|
|
|
pixel[0] = r*matrix[0] + g*matrix[1] + b*matrix[2];
|
|
|
|
pixel[1] = r*matrix[4] + g*matrix[5] + b*matrix[6];
|
|
|
|
pixel[2] = r*matrix[8] + g*matrix[9] + b*matrix[10];
|
|
|
|
pixel[0] += offset[0];
|
|
|
|
pixel[1] += offset[1];
|
|
|
|
pixel[2] += offset[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyRGBA(float *pixel)
|
|
|
|
{
|
|
|
|
if (type == TRANSFORM_LINEAR_TO_SRGB) {
|
|
|
|
applyLinearRGBA(pixel);
|
|
|
|
linearrgb_to_srgb_v4(pixel, pixel);
|
|
|
|
applyDisplayRGBA(pixel);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_SRGB_TO_LINEAR) {
|
|
|
|
srgb_to_linearrgb_v4(pixel, pixel);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_EXPONENT) {
|
|
|
|
pixel[0] = powf(max(0.0f, pixel[0]), exponent[0]);
|
|
|
|
pixel[1] = powf(max(0.0f, pixel[1]), exponent[1]);
|
|
|
|
pixel[2] = powf(max(0.0f, pixel[2]), exponent[2]);
|
|
|
|
pixel[3] = powf(max(0.0f, pixel[3]), exponent[3]);
|
|
|
|
}
|
|
|
|
else if (type == TRANSFORM_MATRIX) {
|
|
|
|
float r = pixel[0];
|
|
|
|
float g = pixel[1];
|
|
|
|
float b = pixel[2];
|
|
|
|
float a = pixel[3];
|
|
|
|
pixel[0] = r*matrix[0] + g*matrix[1] + b*matrix[2] + a*matrix[3];
|
|
|
|
pixel[1] = r*matrix[4] + g*matrix[5] + b*matrix[6] + a*matrix[7];
|
|
|
|
pixel[2] = r*matrix[8] + g*matrix[9] + b*matrix[10] + a*matrix[11];
|
|
|
|
pixel[3] = r*matrix[12] + g*matrix[13] + b*matrix[14] + a*matrix[15];
|
|
|
|
pixel[0] += offset[0];
|
|
|
|
pixel[1] += offset[1];
|
|
|
|
pixel[2] += offset[2];
|
|
|
|
pixel[3] += offset[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyLinearRGB(float *pixel)
|
|
|
|
{
|
|
|
|
if (linear_transform != NULL) {
|
|
|
|
linear_transform->applyRGB(pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyLinearRGBA(float *pixel)
|
|
|
|
{
|
|
|
|
if (linear_transform != NULL) {
|
|
|
|
linear_transform->applyRGBA(pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyDisplayRGB(float *pixel)
|
|
|
|
{
|
|
|
|
if (display_transform != NULL) {
|
|
|
|
display_transform->applyRGB(pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyDisplayRGBA(float *pixel)
|
|
|
|
{
|
|
|
|
if (display_transform != NULL) {
|
|
|
|
display_transform->applyRGBA(pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TransformType type;
|
|
|
|
FallbackTransform *linear_transform;
|
|
|
|
FallbackTransform *display_transform;
|
|
|
|
/* Exponent transform. */
|
|
|
|
float exponent[4];
|
|
|
|
/* Matrix transform. */
|
|
|
|
float matrix[16];
|
|
|
|
float offset[4];
|
|
|
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("FallbackProcessor");
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FallbackProcessor {
|
|
|
|
FallbackProcessor()
|
|
|
|
: transform(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~FallbackProcessor() {
|
|
|
|
delete transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyRGB(float *pixel)
|
|
|
|
{
|
|
|
|
transform->applyRGB(pixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyRGBA(float *pixel)
|
|
|
|
{
|
|
|
|
transform->applyRGBA(pixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
FallbackTransform *transform;
|
|
|
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("FallbackProcessor");
|
|
|
|
};
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstConfigRcPtr *FallbackImpl::getCurrentConfig(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return CONFIG_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::setCurrentConfig(const OCIO_ConstConfigRcPtr * /*config*/)
|
2012-09-16 15:17:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstConfigRcPtr *FallbackImpl::configCreateFromEnv(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2014-05-23 11:48:05 +00:00
|
|
|
return NULL;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
OCIO_ConstConfigRcPtr *FallbackImpl::configCreateFromFile(const char * /*filename*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return CONFIG_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::configRelease(OCIO_ConstConfigRcPtr * /*config*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
int FallbackImpl::configGetNumColorSpaces(OCIO_ConstConfigRcPtr * /*config*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetColorSpaceNameByIndex(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
return "Linear";
|
|
|
|
else if (index == 1)
|
|
|
|
return "sRGB";
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_ConstColorSpaceRcPtr *FallbackImpl::configGetColorSpace(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
if (strcmp(name, "scene_linear") == 0)
|
|
|
|
return COLORSPACE_LINEAR;
|
|
|
|
else if (strcmp(name, "color_picking") == 0)
|
|
|
|
return COLORSPACE_SRGB;
|
|
|
|
else if (strcmp(name, "texture_paint") == 0)
|
|
|
|
return COLORSPACE_LINEAR;
|
|
|
|
else if (strcmp(name, "default_byte") == 0)
|
|
|
|
return COLORSPACE_SRGB;
|
|
|
|
else if (strcmp(name, "default_float") == 0)
|
|
|
|
return COLORSPACE_LINEAR;
|
|
|
|
else if (strcmp(name, "default_sequencer") == 0)
|
|
|
|
return COLORSPACE_SRGB;
|
|
|
|
else if (strcmp(name, "Linear") == 0)
|
|
|
|
return COLORSPACE_LINEAR;
|
|
|
|
else if (strcmp(name, "sRGB") == 0)
|
|
|
|
return COLORSPACE_SRGB;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
int FallbackImpl::configGetIndexForColorSpace(OCIO_ConstConfigRcPtr *config,
|
|
|
|
const char *name)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstColorSpaceRcPtr *cs = configGetColorSpace(config, name);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
if (cs == COLORSPACE_LINEAR) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return 0;
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
|
|
|
else if (cs == COLORSPACE_SRGB) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return 1;
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
2012-09-15 10:03:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
const char *FallbackImpl::configGetDefaultDisplay(OCIO_ConstConfigRcPtr * /*config*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return "sRGB";
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
int FallbackImpl::configGetNumDisplays(OCIO_ConstConfigRcPtr * /*config*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetDisplay(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-11-30 11:52:48 +00:00
|
|
|
if (index == 0) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return "sRGB";
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetDefaultView(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char * /*display*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return "Default";
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
int FallbackImpl::configGetNumViews(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char * /*display*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetView(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char * /*display*/, int index)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-11-30 11:52:48 +00:00
|
|
|
if (index == 0) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return "Default";
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetDisplayColorSpaceName(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char * /*display*/,
|
|
|
|
const char * /*view*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return "sRGB";
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
float *rgb)
|
2015-03-17 13:15:05 +00:00
|
|
|
{
|
2016-11-30 11:52:48 +00:00
|
|
|
/* Here we simply use the older Blender assumed primaries of
|
|
|
|
* ITU-BT.709 / sRGB, or 0.2126729 0.7151522 0.0721750. Brute
|
|
|
|
* force stupid, but only plausible option given no color management
|
|
|
|
* system in place.
|
|
|
|
*/
|
2015-03-17 13:15:05 +00:00
|
|
|
|
2015-03-23 11:18:42 +00:00
|
|
|
rgb[0] = 0.2126f;
|
|
|
|
rgb[1] = 0.7152f;
|
|
|
|
rgb[2] = 0.0722f;
|
2015-03-17 13:15:05 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 09:48:26 +00:00
|
|
|
int FallbackImpl::configGetNumLooks(OCIO_ConstConfigRcPtr * /*config*/)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
const char *FallbackImpl::configGetLookNameByIndex(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
int /*index*/)
|
2013-09-09 09:48:26 +00:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_ConstLookRcPtr *FallbackImpl::configGetLook(OCIO_ConstConfigRcPtr * /*config*/,
|
|
|
|
const char * /*name*/)
|
2013-09-09 09:48:26 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-27 10:43:47 +00:00
|
|
|
const char *FallbackImpl::lookGetProcessSpace(OCIO_ConstLookRcPtr * /*look*/)
|
2013-09-09 09:48:26 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FallbackImpl::lookRelease(OCIO_ConstLookRcPtr * /*look*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
int FallbackImpl::colorSpaceIsInvertible(OCIO_ConstColorSpaceRcPtr * /*cs*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
int FallbackImpl::colorSpaceIsData(OCIO_ConstColorSpaceRcPtr * /*cs*/)
|
2012-09-19 15:01:36 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::colorSpaceRelease(OCIO_ConstColorSpaceRcPtr * /*cs*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_ConstProcessorRcPtr *FallbackImpl::configGetProcessorWithNames(
|
|
|
|
OCIO_ConstConfigRcPtr *config,
|
|
|
|
const char *srcName,
|
|
|
|
const char *dstName)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ConstColorSpaceRcPtr *cs_src = configGetColorSpace(config, srcName);
|
|
|
|
OCIO_ConstColorSpaceRcPtr *cs_dst = configGetColorSpace(config, dstName);
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = new FallbackTransform();
|
2016-11-30 11:52:48 +00:00
|
|
|
if (cs_src == COLORSPACE_LINEAR && cs_dst == COLORSPACE_SRGB) {
|
2016-12-02 15:57:00 +00:00
|
|
|
transform->type = TRANSFORM_LINEAR_TO_SRGB;
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
|
|
|
else if (cs_src == COLORSPACE_SRGB && cs_dst == COLORSPACE_LINEAR) {
|
2016-12-02 15:57:00 +00:00
|
|
|
transform->type = TRANSFORM_SRGB_TO_LINEAR;
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
2016-12-02 15:57:00 +00:00
|
|
|
else {
|
|
|
|
transform->type = TRANSFORM_UNKNOWN;
|
|
|
|
}
|
|
|
|
FallbackProcessor *processor = new FallbackProcessor();
|
|
|
|
processor->transform = transform;
|
|
|
|
return (OCIO_ConstProcessorRcPtr *)processor;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_ConstProcessorRcPtr *FallbackImpl::configGetProcessor(OCIO_ConstConfigRcPtr * /*config*/,
|
2016-12-02 15:57:00 +00:00
|
|
|
OCIO_ConstTransformRcPtr *transform)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackProcessor *processor = new FallbackProcessor();
|
|
|
|
processor->transform = (FallbackTransform *)transform;
|
|
|
|
return (OCIO_ConstProcessorRcPtr *)processor;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::processorApply(OCIO_ConstProcessorRcPtr *processor,
|
|
|
|
OCIO_PackedImageDesc *img)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
/* OCIO_TODO stride not respected, channels must be 3 or 4 */
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_PackedImageDescription *desc = (OCIO_PackedImageDescription*)img;
|
2012-09-15 10:03:17 +00:00
|
|
|
int channels = desc->numChannels;
|
|
|
|
float *pixels = desc->data;
|
|
|
|
int width = desc->width;
|
|
|
|
int height = desc->height;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
float *pixel = pixels + channels * (y * width + x);
|
|
|
|
|
|
|
|
if (channels == 4)
|
2012-10-04 13:39:08 +00:00
|
|
|
processorApplyRGBA(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
else if (channels == 3)
|
2012-10-04 13:39:08 +00:00
|
|
|
processorApplyRGB(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::processorApply_predivide(OCIO_ConstProcessorRcPtr *processor,
|
|
|
|
OCIO_PackedImageDesc *img)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
/* OCIO_TODO stride not respected, channels must be 3 or 4 */
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_PackedImageDescription *desc = (OCIO_PackedImageDescription*)img;
|
2012-09-15 10:03:17 +00:00
|
|
|
int channels = desc->numChannels;
|
|
|
|
float *pixels = desc->data;
|
|
|
|
int width = desc->width;
|
|
|
|
int height = desc->height;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
float *pixel = pixels + channels * (y * width + x);
|
|
|
|
|
|
|
|
if (channels == 4)
|
2012-10-04 13:39:08 +00:00
|
|
|
processorApplyRGBA_predivide(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
else if (channels == 3)
|
2012-10-04 13:39:08 +00:00
|
|
|
processorApplyRGB(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::processorApplyRGB(OCIO_ConstProcessorRcPtr *processor,
|
|
|
|
float *pixel)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
((FallbackProcessor *)processor)->applyRGB(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::processorApplyRGBA(OCIO_ConstProcessorRcPtr *processor,
|
|
|
|
float *pixel)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
((FallbackProcessor *)processor)->applyRGBA(pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::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-04 13:39:08 +00:00
|
|
|
processorApplyRGBA(processor, 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-04 13:39:08 +00:00
|
|
|
processorApplyRGBA(processor, pixel);
|
2012-09-15 10:03:17 +00:00
|
|
|
|
|
|
|
pixel[0] *= alpha;
|
|
|
|
pixel[1] *= alpha;
|
|
|
|
pixel[2] *= alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::processorRelease(OCIO_ConstProcessorRcPtr *processor)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
delete (FallbackProcessor*)(processor);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
const char *FallbackImpl::colorSpaceGetName(OCIO_ConstColorSpaceRcPtr *cs)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-11-30 11:52:48 +00:00
|
|
|
if (cs == COLORSPACE_LINEAR) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return "Linear";
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
|
|
|
else if (cs == COLORSPACE_SRGB) {
|
2012-09-15 10:03:17 +00:00
|
|
|
return "sRGB";
|
2016-11-30 11:52:48 +00:00
|
|
|
}
|
2012-09-15 10:03:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
const char *FallbackImpl::colorSpaceGetDescription(OCIO_ConstColorSpaceRcPtr * /*cs*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
const char *FallbackImpl::colorSpaceGetFamily(OCIO_ConstColorSpaceRcPtr * /*cs*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_DisplayTransformRcPtr *FallbackImpl::createDisplayTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = new FallbackTransform();
|
|
|
|
transform->type = TRANSFORM_LINEAR_TO_SRGB;
|
|
|
|
return (OCIO_DisplayTransformRcPtr*)transform;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::displayTransformSetInputColorSpaceName(OCIO_DisplayTransformRcPtr * /*dt*/,
|
|
|
|
const char * /*name*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::displayTransformSetDisplay(OCIO_DisplayTransformRcPtr * /*dt*/,
|
|
|
|
const char * /*name*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::displayTransformSetView(OCIO_DisplayTransformRcPtr * /*dt*/,
|
|
|
|
const char * /*name*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::displayTransformSetDisplayCC(OCIO_DisplayTransformRcPtr *dt,
|
|
|
|
OCIO_ConstTransformRcPtr *et)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = (FallbackTransform *)dt;
|
|
|
|
transform->display_transform = (FallbackTransform *)et;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::displayTransformSetLinearCC(OCIO_DisplayTransformRcPtr *dt,
|
|
|
|
OCIO_ConstTransformRcPtr *et)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = (FallbackTransform *)dt;
|
|
|
|
transform->linear_transform = (FallbackTransform *)et;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::displayTransformSetLooksOverride(OCIO_DisplayTransformRcPtr * /*dt*/,
|
|
|
|
const char * /*looks*/)
|
2013-09-09 09:48:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
void FallbackImpl::displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransformRcPtr * /*dt*/,
|
|
|
|
bool /*enabled*/)
|
2013-09-09 09:48:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr * /*dt*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_PackedImageDesc *FallbackImpl::createOCIO_PackedImageDesc(
|
|
|
|
float *data,
|
|
|
|
long width, long height, long numChannels,
|
|
|
|
long chanStrideBytes, long xStrideBytes, long yStrideBytes)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-11-30 11:52:48 +00:00
|
|
|
OCIO_PackedImageDescription *desc =
|
|
|
|
(OCIO_PackedImageDescription*)MEM_callocN(sizeof(OCIO_PackedImageDescription),
|
|
|
|
"OCIO_PackedImageDescription");
|
2012-09-15 10:03:17 +00:00
|
|
|
desc->data = data;
|
|
|
|
desc->width = width;
|
|
|
|
desc->height = height;
|
|
|
|
desc->numChannels = numChannels;
|
|
|
|
desc->chanStrideBytes = chanStrideBytes;
|
|
|
|
desc->xStrideBytes = xStrideBytes;
|
|
|
|
desc->yStrideBytes = yStrideBytes;
|
2012-10-05 10:05:26 +00:00
|
|
|
return (OCIO_PackedImageDesc*)desc;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
void FallbackImpl::OCIO_PackedImageDescRelease(OCIO_PackedImageDesc* id)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
MEM_freeN(id);
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_ExponentTransformRcPtr *FallbackImpl::createExponentTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = new FallbackTransform();
|
|
|
|
transform->type = TRANSFORM_EXPONENT;
|
|
|
|
return (OCIO_ExponentTransformRcPtr *)transform;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::exponentTransformSetValue(OCIO_ExponentTransformRcPtr *et,
|
|
|
|
const float *exponent)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = (FallbackTransform *)et;
|
|
|
|
copy_v4_v4(transform->exponent, exponent);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::exponentTransformRelease(OCIO_ExponentTransformRcPtr * /*et*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-05 10:05:26 +00:00
|
|
|
OCIO_MatrixTransformRcPtr *FallbackImpl::createMatrixTransform(void)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = new FallbackTransform();
|
|
|
|
transform->type = TRANSFORM_MATRIX;
|
|
|
|
return (OCIO_MatrixTransformRcPtr *)transform;
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::matrixTransformSetValue(OCIO_MatrixTransformRcPtr *mt,
|
|
|
|
const float *m44,
|
|
|
|
const float *offset4)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
FallbackTransform *transform = (FallbackTransform *)mt;
|
|
|
|
copy_m4_m4((float (*)[4])transform->matrix, (float (*)[4])m44);
|
|
|
|
copy_v4_v4(transform->offset, offset4);
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::matrixTransformRelease(OCIO_MatrixTransformRcPtr * /*mt*/)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-02 15:57:00 +00:00
|
|
|
void FallbackImpl::matrixTransformScale(float *m44,
|
|
|
|
float *offset4,
|
|
|
|
const float *scale4)
|
2012-09-15 10:03:17 +00:00
|
|
|
{
|
2016-12-02 15:57:00 +00:00
|
|
|
if (scale4 == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m44 != NULL) {
|
|
|
|
memset(m44, 0, 16*sizeof(float));
|
|
|
|
m44[0] = scale4[0];
|
|
|
|
m44[5] = scale4[1];
|
|
|
|
m44[10] = scale4[2];
|
|
|
|
m44[15] = scale4[3];
|
|
|
|
}
|
|
|
|
if (offset4 != NULL) {
|
|
|
|
offset4[0] = 0.0f;
|
|
|
|
offset4[1] = 0.0f;
|
|
|
|
offset4[2] = 0.0f;
|
|
|
|
offset4[3] = 0.0f;
|
|
|
|
}
|
2012-09-15 10:03:17 +00:00
|
|
|
}
|
2013-03-29 16:02:27 +00:00
|
|
|
|
2013-08-30 23:49:35 +00:00
|
|
|
bool FallbackImpl::supportGLSLDraw(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-30 11:52:48 +00:00
|
|
|
bool FallbackImpl::setupGLSLDraw(struct OCIO_GLSLDrawState ** /*state_r*/,
|
|
|
|
OCIO_ConstProcessorRcPtr * /*processor*/,
|
2013-12-13 06:36:45 +00:00
|
|
|
OCIO_CurveMappingSettings * /*curve_mapping_settings*/,
|
2016-11-30 11:52:48 +00:00
|
|
|
float /*dither*/,
|
|
|
|
bool /*predivide*/)
|
2013-03-29 16:02:27 +00:00
|
|
|
{
|
2013-04-02 17:28:29 +00:00
|
|
|
return false;
|
2013-03-29 16:02:27 +00:00
|
|
|
}
|
|
|
|
|
2013-09-07 19:41:46 +00:00
|
|
|
void FallbackImpl::finishGLSLDraw(OCIO_GLSLDrawState * /*state*/)
|
2013-03-29 16:02:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-07 19:44:01 +00:00
|
|
|
void FallbackImpl::freeGLState(struct OCIO_GLSLDrawState * /*state_r*/)
|
2013-03-29 16:02:27 +00:00
|
|
|
{
|
|
|
|
}
|
2013-12-08 09:03:17 +00:00
|
|
|
|
|
|
|
const char *FallbackImpl::getVersionString(void)
|
|
|
|
{
|
|
|
|
return "fallback";
|
|
|
|
}
|
|
|
|
|
|
|
|
int FallbackImpl::getVersionHex(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|