mm2 / Little-CMS

A free, open source, CMM engine. It provides fast transforms between ICC profiles.
https://www.littlecms.com
MIT License
549 stars 174 forks source link

Fast float plugin clamps values to [0,1] #375

Closed jpownby-es closed 1 year ago

jpownby-es commented 1 year ago

Hello!

My use case is that I want to transform any input image with an embedded ICC profile into linear sRGB values, preserving any negative values and any values greater than one. I have encountered a case where this works with the core LCMS (I get values outside of [0,1] which preserve the chromaticity the way that I need) but where the fast float plugin clamps the values to [0,1], which isn't correct for what I need.

I have attached a source image and target profile. The source image sets every 8 bit channel to either 0 or 255 (i.e. bars of RGB and CYM) and the embedded profile sets the primaries to P3. The target profile should be sRGB but linear, which means that, for example, the red bar should end up with a red channel greater than 1 and the green and blue channels should be slightly less than 0.

When using LCMS I am converting the input data to 32-bit floating point myself and then calling: cmsCreateTransform(sourceProfile, TYPE_RGB_FLT, targetProfile, TYPE_RGB_FLT, INTENT_ABSOLUTE_COLORIMETRIC, cmsFLAGS_HIGHRESPRECALC)

The problem seems to be in MatShaperFloat(): (cmsFloat32Number)rout = flerp(p->Shaper2R, l1); (cmsFloat32Number)gout = flerp(p->Shaper2G, l2); (cmsFloat32Number)bout = flerp(p->Shaper2B, l3); Where flerp() is clamping to [0,1].

As I said before, I get the values that I want when I don't use the fast float plugin. I have also found other images that do give me values outside of [0,1] using the same target profile (in one case that I checked FloatCLUTEval() gets called, which doesn't seem to do the same [0,1] clamping).

Is there any way to get the results I want with the problematic attached image and the fast float plugin?

(The attached example image is something that I generated, but I need to be able to support any images from external sources that I don't have control over. I could change the target profile since I generate that, but I would prefer to be able to just specify the simple linear primaries to change rather than specifying a LUT.)

Thank you!

ICCProfileAndImage.zip

mm2 commented 1 year ago

Auto-closed by github. The commit is b3144b8018a26df755b46a02583ff6ea466f532c