Skip to content

Commit

Permalink
Increase gamut compression inversion precision
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-shaw committed Apr 17, 2023
1 parent a0bea4a commit dd940f6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions DaVinci Resolve/ACES Transforms/ODT/hellwig_lib.h
Expand Up @@ -853,8 +853,7 @@ __DEVICE__ inline float3 compressGamut(float3 JMh, int invert)
v = compressPowerP(v, compressionFuncParams.x, lerp(compressionFuncParams.z, compressionFuncParams.y, projectJ / limitJmax), compressionFuncParams.w, invert);
float2 JMcompressed = project_to + v * (JMboundary - project_to);

// return make_float3(JMcompressed.x, JMcompressed.y, JMh.z);
return make_float3(JMboundary.x, JMboundary.y, JMh.z);
return make_float3(JMcompressed.x, JMcompressed.y, JMh.z);
}

__DEVICE__ inline float3 compressGamutAlt(float3 JMh, int invert)
Expand Down Expand Up @@ -890,10 +889,18 @@ __DEVICE__ inline float3 compressGamutAlt(float3 JMh, int invert)
// Compress the out of gamut color along the projection line
float v = project_from.y / JMboundary.y;
v = compressPowerP(v, compressionFuncParams.x, lerp(compressionFuncParams.z, compressionFuncParams.y, projectJ / limitJmax), compressionFuncParams.w, invert);
float2 JMcompressed = project_to + v * (JMboundary - project_to);
float2 JMcompressed;
// Only compress if v is above threshold to remove precision issues with near achromatic values
if (v >= compressionFuncParams.x)
{
JMcompressed = project_to + v * (JMboundary - project_to);
}
else
{
JMcompressed = project_from;
}

// return make_float3(JMcompressed.x, JMcompressed.y, JMh.z);
return make_float3(JMboundary.x, JMboundary.y, JMh.z);
return make_float3(JMcompressed.x, JMcompressed.y, JMh.z);
}

// encode linear values as ST2084 PQ
Expand Down

0 comments on commit dd940f6

Please sign in to comment.