Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2021-01-31 21:35:00 +0300
committerBrecht Van Lommel <brecht@blender.org>2021-02-12 21:06:35 +0300
commit1b4961b318f14064bc3c915da7206a74146af95d (patch)
treefd8168e60333efad3dd0433b5229e2f7f9d97131 /intern/opencolorio/fallback_impl.cc
parent6b40ee608c5a1dbe67870fab4b83cce4cc4b54f5 (diff)
OpenColorIO: upgrade to version 2.0.0
Ref T84819 Build System ============ This is an API breaking new version, and the updated code only builds with OpenColorIO 2.0 and later. Adding backwards compatibility was too complicated. * Tinyxml was replaced with Expat, adding a new dependency. * Yaml-cpp is now built as a dependency on Unix, as was already done on Windows. * Removed currently unused LCMS code. * Pystring remains built as part of OCIO itself, since it has no good build system. * Linux and macOS check for the OpenColorIO verison, and disable it if too old. Ref D10270 Processors and Transforms ========================= CPU processors now need to be created to do CPU processing. These are cached internally, but the cache lookup is not fast enough to execute per pixel or texture sample, so for performance these are now also exposed in the C API. The C API for transforms will no longer be needed afer all changes, so remove it to simplify the API and fallback implementation. Ref D10271 Display Transforms ================== Needs a bit more manual work constructing the transform. LegacyViewingPipeline could also have been used, but isn't really any simpler and since it's legacy we better not rely on it. We moved more logic into the opencolorio module, to simplify the API. There is no need to wrap a dozen functions just to be able to do this in C rather than C++. It's also tightly coupled to the GPU shader logic, and so should be in the same module. Ref D10271 GPU Display Shader ================== To avoid baking exposure and gamma into the GLSL shader and requiring slow recompiles when tweaking, we manually apply them in the shader. This leads to some logic duplicaton between the CPU and GPU display processor, but it seems unavoidable. Caching was also changed. Previously this was done both on the imbuf and opencolorio module levels. Now it's all done in the opencolorio module by simply matching color space names. We no longer use cacheIDs from OpenColorIO since computing them is expensive, and they are unlikely to match now that more is baked into the shader code. Shaders can now use multiple 2D textures, 3D textures and uniforms, rather than a single 3D texture. So allocating and binding those adds some code. Color space conversions for blending with overlays is now hardcoded in the shader. This was using harcoded numbers anyway, if this every becomes a general OpenColorIO transform it can be changed, but for now there is no point to add code complexity. Ref D10273 CIE XYZ ======= We need standard CIE XYZ values for rendering effects like blackbody emission. The relation to the scene linear role is based on OpenColorIO configuration. In OpenColorIO 2.0 configs roles can no longer have the same name as color spaces, which means our XYZ role and colorspace in the configuration give an error. Instead use the new standard aces_interchange role, which relates scene linear to a known scene referred color space. Compatibility with the old XYZ role is preserved, if the configuration file has no conflicting names. Also includes a non-functional change to the configuraton file to use an XYZ-to-ACES matrix instead of REC709-to-ACES, makes debugging a little easier since the matrix is the same one we have in the code now and that is also found easily in the ACES specs. Ref D10274
Diffstat (limited to 'intern/opencolorio/fallback_impl.cc')
-rw-r--r--intern/opencolorio/fallback_impl.cc366
1 files changed, 71 insertions, 295 deletions
diff --git a/intern/opencolorio/fallback_impl.cc b/intern/opencolorio/fallback_impl.cc
index a6b93ac4959..9bbc9843e9d 100644
--- a/intern/opencolorio/fallback_impl.cc
+++ b/intern/opencolorio/fallback_impl.cc
@@ -34,7 +34,7 @@ using std::max;
enum TransformType {
TRANSFORM_LINEAR_TO_SRGB,
TRANSFORM_SRGB_TO_LINEAR,
- TRANSFORM_MATRIX,
+ TRANSFORM_SCALE,
TRANSFORM_EXPONENT,
TRANSFORM_UNKNOWN,
};
@@ -53,147 +53,72 @@ typedef struct OCIO_PackedImageDescription {
} OCIO_PackedImageDescription;
struct FallbackTransform {
- FallbackTransform() : type(TRANSFORM_UNKNOWN), linear_transform(NULL), display_transform(NULL)
+ FallbackTransform() : type(TRANSFORM_UNKNOWN), scale(1.0f), exponent(1.0f)
{
}
virtual ~FallbackTransform()
{
- delete linear_transform;
- delete display_transform;
}
void applyRGB(float *pixel)
{
if (type == TRANSFORM_LINEAR_TO_SRGB) {
- applyLinearRGB(pixel);
+ pixel[0] *= scale;
+ pixel[1] *= scale;
+ pixel[2] *= scale;
+
linearrgb_to_srgb_v3_v3(pixel, pixel);
- applyDisplayRGB(pixel);
+
+ pixel[0] = powf(max(0.0f, pixel[0]), exponent);
+ pixel[1] = powf(max(0.0f, pixel[1]), exponent);
+ pixel[2] = powf(max(0.0f, pixel[2]), exponent);
}
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]);
+ pixel[0] = powf(max(0.0f, pixel[0]), exponent);
+ pixel[1] = powf(max(0.0f, pixel[1]), exponent);
+ pixel[2] = powf(max(0.0f, pixel[2]), exponent);
}
- 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];
+ else if (type == TRANSFORM_SCALE) {
+ pixel[0] *= scale;
+ pixel[1] *= scale;
+ pixel[2] *= scale;
}
}
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);
- }
+ applyRGB(pixel);
}
TransformType type;
- FallbackTransform *linear_transform;
- FallbackTransform *display_transform;
+ /* Scale transform. */
+ float scale;
/* Exponent transform. */
- float exponent[4];
- /* Matrix transform. */
- float matrix[16];
- float offset[4];
+ float exponent;
MEM_CXX_CLASS_ALLOC_FUNCS("FallbackTransform");
};
-struct FallbackGroupTransform : FallbackTransform {
- ~FallbackGroupTransform()
- {
- for (auto transform : list) {
- delete transform;
- }
- }
- std::vector<FallbackTransform *> list;
-};
-
struct FallbackProcessor {
- FallbackProcessor() : transform(NULL)
+ FallbackProcessor(const FallbackTransform &transform) : transform(transform)
{
}
- ~FallbackProcessor()
- {
- delete transform;
- }
-
void applyRGB(float *pixel)
{
- transform->applyRGB(pixel);
+ transform.applyRGB(pixel);
}
void applyRGBA(float *pixel)
{
- transform->applyRGBA(pixel);
+ transform.applyRGBA(pixel);
}
- FallbackTransform *transform;
+ FallbackTransform transform;
MEM_CXX_CLASS_ALLOC_FUNCS("FallbackProcessor");
};
@@ -403,30 +328,35 @@ OCIO_ConstProcessorRcPtr *FallbackImpl::configGetProcessorWithNames(OCIO_ConstCo
{
OCIO_ConstColorSpaceRcPtr *cs_src = configGetColorSpace(config, srcName);
OCIO_ConstColorSpaceRcPtr *cs_dst = configGetColorSpace(config, dstName);
- FallbackTransform *transform = new FallbackTransform();
+ FallbackTransform transform;
if (cs_src == COLORSPACE_LINEAR && cs_dst == COLORSPACE_SRGB) {
- transform->type = TRANSFORM_LINEAR_TO_SRGB;
+ transform.type = TRANSFORM_LINEAR_TO_SRGB;
}
else if (cs_src == COLORSPACE_SRGB && cs_dst == COLORSPACE_LINEAR) {
- transform->type = TRANSFORM_SRGB_TO_LINEAR;
+ transform.type = TRANSFORM_SRGB_TO_LINEAR;
}
else {
- transform->type = TRANSFORM_UNKNOWN;
+ transform.type = TRANSFORM_UNKNOWN;
}
- FallbackProcessor *processor = new FallbackProcessor();
- processor->transform = transform;
- return (OCIO_ConstProcessorRcPtr *)processor;
+ return (OCIO_ConstProcessorRcPtr *)new FallbackProcessor(transform);
+}
+
+OCIO_ConstCPUProcessorRcPtr *FallbackImpl::processorGetCPUProcessor(
+ OCIO_ConstProcessorRcPtr *processor)
+{
+ /* Just make a copy of the processor so that we are compatible with OCIO
+ * which does need it as a separate object. */
+ FallbackProcessor *fallback_processor = (FallbackProcessor *)processor;
+ return (OCIO_ConstCPUProcessorRcPtr *)new FallbackProcessor(*fallback_processor);
}
-OCIO_ConstProcessorRcPtr *FallbackImpl::configGetProcessor(OCIO_ConstConfigRcPtr * /*config*/,
- OCIO_ConstTransformRcPtr *transform)
+void FallbackImpl::processorRelease(OCIO_ConstProcessorRcPtr *processor)
{
- FallbackProcessor *processor = new FallbackProcessor();
- processor->transform = (FallbackTransform *)transform;
- return (OCIO_ConstProcessorRcPtr *)processor;
+ delete (FallbackProcessor *)(processor);
}
-void FallbackImpl::processorApply(OCIO_ConstProcessorRcPtr *processor, OCIO_PackedImageDesc *img)
+void FallbackImpl::cpuProcessorApply(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
+ OCIO_PackedImageDesc *img)
{
/* OCIO_TODO stride not respected, channels must be 3 or 4 */
OCIO_PackedImageDescription *desc = (OCIO_PackedImageDescription *)img;
@@ -441,15 +371,15 @@ void FallbackImpl::processorApply(OCIO_ConstProcessorRcPtr *processor, OCIO_Pack
float *pixel = pixels + channels * (y * width + x);
if (channels == 4)
- processorApplyRGBA(processor, pixel);
+ cpuProcessorApplyRGBA(cpu_processor, pixel);
else if (channels == 3)
- processorApplyRGB(processor, pixel);
+ cpuProcessorApplyRGB(cpu_processor, pixel);
}
}
}
-void FallbackImpl::processorApply_predivide(OCIO_ConstProcessorRcPtr *processor,
- OCIO_PackedImageDesc *img)
+void FallbackImpl::cpuProcessorApply_predivide(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
+ OCIO_PackedImageDesc *img)
{
/* OCIO_TODO stride not respected, channels must be 3 or 4 */
OCIO_PackedImageDescription *desc = (OCIO_PackedImageDescription *)img;
@@ -464,27 +394,28 @@ void FallbackImpl::processorApply_predivide(OCIO_ConstProcessorRcPtr *processor,
float *pixel = pixels + channels * (y * width + x);
if (channels == 4)
- processorApplyRGBA_predivide(processor, pixel);
+ cpuProcessorApplyRGBA_predivide(cpu_processor, pixel);
else if (channels == 3)
- processorApplyRGB(processor, pixel);
+ cpuProcessorApplyRGB(cpu_processor, pixel);
}
}
}
-void FallbackImpl::processorApplyRGB(OCIO_ConstProcessorRcPtr *processor, float *pixel)
+void FallbackImpl::cpuProcessorApplyRGB(OCIO_ConstCPUProcessorRcPtr *cpu_processor, float *pixel)
{
- ((FallbackProcessor *)processor)->applyRGB(pixel);
+ ((FallbackProcessor *)cpu_processor)->applyRGB(pixel);
}
-void FallbackImpl::processorApplyRGBA(OCIO_ConstProcessorRcPtr *processor, float *pixel)
+void FallbackImpl::cpuProcessorApplyRGBA(OCIO_ConstCPUProcessorRcPtr *cpu_processor, float *pixel)
{
- ((FallbackProcessor *)processor)->applyRGBA(pixel);
+ ((FallbackProcessor *)cpu_processor)->applyRGBA(pixel);
}
-void FallbackImpl::processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *processor, float *pixel)
+void FallbackImpl::cpuProcessorApplyRGBA_predivide(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
+ float *pixel)
{
if (pixel[3] == 1.0f || pixel[3] == 0.0f) {
- processorApplyRGBA(processor, pixel);
+ cpuProcessorApplyRGBA(cpu_processor, pixel);
}
else {
float alpha, inv_alpha;
@@ -496,7 +427,7 @@ void FallbackImpl::processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *proces
pixel[1] *= inv_alpha;
pixel[2] *= inv_alpha;
- processorApplyRGBA(processor, pixel);
+ cpuProcessorApplyRGBA(cpu_processor, pixel);
pixel[0] *= alpha;
pixel[1] *= alpha;
@@ -504,9 +435,9 @@ void FallbackImpl::processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *proces
}
}
-void FallbackImpl::processorRelease(OCIO_ConstProcessorRcPtr *processor)
+void FallbackImpl::cpuProcessorRelease(OCIO_ConstCPUProcessorRcPtr *cpu_processor)
{
- delete (FallbackProcessor *)(processor);
+ delete (FallbackProcessor *)(cpu_processor);
}
const char *FallbackImpl::colorSpaceGetName(OCIO_ConstColorSpaceRcPtr *cs)
@@ -530,54 +461,20 @@ const char *FallbackImpl::colorSpaceGetFamily(OCIO_ConstColorSpaceRcPtr * /*cs*/
return "";
}
-OCIO_DisplayTransformRcPtr *FallbackImpl::createDisplayTransform(void)
-{
- FallbackTransform *transform = new FallbackTransform();
- transform->type = TRANSFORM_LINEAR_TO_SRGB;
- return (OCIO_DisplayTransformRcPtr *)transform;
-}
-
-void FallbackImpl::displayTransformSetInputColorSpaceName(OCIO_DisplayTransformRcPtr * /*dt*/,
- const char * /*name*/)
-{
-}
-
-void FallbackImpl::displayTransformSetDisplay(OCIO_DisplayTransformRcPtr * /*dt*/,
- const char * /*name*/)
-{
-}
-
-void FallbackImpl::displayTransformSetView(OCIO_DisplayTransformRcPtr * /*dt*/,
- const char * /*name*/)
-{
-}
-
-void FallbackImpl::displayTransformSetDisplayCC(OCIO_DisplayTransformRcPtr *dt,
- OCIO_ConstTransformRcPtr *et)
-{
- FallbackTransform *transform = (FallbackTransform *)dt;
- transform->display_transform = (FallbackTransform *)et;
-}
-
-void FallbackImpl::displayTransformSetLinearCC(OCIO_DisplayTransformRcPtr *dt,
- OCIO_ConstTransformRcPtr *et)
-{
- FallbackTransform *transform = (FallbackTransform *)dt;
- transform->linear_transform = (FallbackTransform *)et;
-}
-
-void FallbackImpl::displayTransformSetLooksOverride(OCIO_DisplayTransformRcPtr * /*dt*/,
- const char * /*looks*/)
-{
-}
-
-void FallbackImpl::displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransformRcPtr * /*dt*/,
- bool /*enabled*/)
+OCIO_ConstProcessorRcPtr *FallbackImpl::createDisplayProcessor(OCIO_ConstConfigRcPtr * /*config*/,
+ const char * /*input*/,
+ const char * /*view*/,
+ const char * /*display*/,
+ const char * /*look*/,
+ const float scale,
+ const float exponent)
{
-}
+ FallbackTransform transform;
+ transform.type = TRANSFORM_LINEAR_TO_SRGB;
+ transform.scale = scale;
+ transform.exponent = exponent;
-void FallbackImpl::displayTransformRelease(OCIO_DisplayTransformRcPtr * /*dt*/)
-{
+ return (OCIO_ConstProcessorRcPtr *)new FallbackProcessor(transform);
}
OCIO_PackedImageDesc *FallbackImpl::createOCIO_PackedImageDesc(float *data,
@@ -605,127 +502,6 @@ void FallbackImpl::OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *id)
MEM_freeN(id);
}
-OCIO_GroupTransformRcPtr *FallbackImpl::createGroupTransform(void)
-{
- FallbackTransform *transform = new FallbackGroupTransform();
- transform->type = TRANSFORM_UNKNOWN;
- return (OCIO_GroupTransformRcPtr *)transform;
-}
-
-void FallbackImpl::groupTransformSetDirection(OCIO_GroupTransformRcPtr * /*gt*/,
- const bool /*forward */)
-{
-}
-
-void FallbackImpl::groupTransformPushBack(OCIO_GroupTransformRcPtr *gt,
- OCIO_ConstTransformRcPtr *transform)
-{
- FallbackGroupTransform *group = (FallbackGroupTransform *)gt;
- group->list.push_back((FallbackTransform *)transform);
-}
-
-void FallbackImpl::groupTransformRelease(OCIO_GroupTransformRcPtr * /*gt*/)
-{
-}
-
-OCIO_ColorSpaceTransformRcPtr *FallbackImpl::createColorSpaceTransform(void)
-{
- FallbackTransform *transform = new FallbackTransform();
- transform->type = TRANSFORM_UNKNOWN;
- return (OCIO_ColorSpaceTransformRcPtr *)transform;
-}
-
-void FallbackImpl::colorSpaceTransformSetSrc(OCIO_ColorSpaceTransformRcPtr * /*ct*/,
- const char * /*name*/)
-{
-}
-
-void FallbackImpl::colorSpaceTransformRelease(OCIO_ColorSpaceTransformRcPtr * /*ct*/)
-{
-}
-
-OCIO_ExponentTransformRcPtr *FallbackImpl::createExponentTransform(void)
-{
- FallbackTransform *transform = new FallbackTransform();
- transform->type = TRANSFORM_EXPONENT;
- return (OCIO_ExponentTransformRcPtr *)transform;
-}
-
-void FallbackImpl::exponentTransformSetValue(OCIO_ExponentTransformRcPtr *et,
- const float *exponent)
-{
- FallbackTransform *transform = (FallbackTransform *)et;
- copy_v4_v4(transform->exponent, exponent);
-}
-
-void FallbackImpl::exponentTransformRelease(OCIO_ExponentTransformRcPtr * /*et*/)
-{
-}
-
-OCIO_MatrixTransformRcPtr *FallbackImpl::createMatrixTransform(void)
-{
- FallbackTransform *transform = new FallbackTransform();
- transform->type = TRANSFORM_MATRIX;
- return (OCIO_MatrixTransformRcPtr *)transform;
-}
-
-void FallbackImpl::matrixTransformSetValue(OCIO_MatrixTransformRcPtr *mt,
- const float *m44,
- const float *offset4)
-{
- FallbackTransform *transform = (FallbackTransform *)mt;
- copy_m4_m4((float(*)[4])transform->matrix, (float(*)[4])m44);
- copy_v4_v4(transform->offset, offset4);
-}
-
-void FallbackImpl::matrixTransformRelease(OCIO_MatrixTransformRcPtr * /*mt*/)
-{
-}
-
-void FallbackImpl::matrixTransformScale(float *m44, float *offset4, const float *scale4)
-{
- 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;
- }
-}
-
-bool FallbackImpl::supportGLSLDraw(void)
-{
- return false;
-}
-
-bool FallbackImpl::setupGLSLDraw(struct OCIO_GLSLDrawState ** /*state_r*/,
- OCIO_ConstProcessorRcPtr * /*ocio_processor_scene_to_ui*/,
- OCIO_ConstProcessorRcPtr * /*ocio_processor_ui_to_display*/,
- OCIO_CurveMappingSettings * /*curve_mapping_settings*/,
- float /*dither*/,
- bool /*predivide*/,
- bool /*overlay*/)
-{
- return false;
-}
-
-void FallbackImpl::finishGLSLDraw(OCIO_GLSLDrawState * /*state*/)
-{
-}
-
-void FallbackImpl::freeGLState(struct OCIO_GLSLDrawState * /*state_r*/)
-{
-}
-
const char *FallbackImpl::getVersionString(void)
{
return "fallback";