Custom Metal CIKernel return fixed color produces different color

238 Views Asked by At

I hava a custom CIKernel by Metal, I found a weird thing that shader return a fixed color, but screen display is different! I use break point to check produced CIImage object, is really different color.

there is my code

float4 test(sample_t s) {
    return float4(16 / 255.0, 16 / 255.0, 16 / 255.0, 1);
}

and this is result in breakpoint.

enter image description here

I want a (16,16,16) color, but it produced a (62,62,62) color.

I tried many times and got this graph, (x axis is input value(shader return), y axis is result)

enter image description here

it looks like there is a gamma correction? how to fix this? anyone help

1

There are 1 best solutions below

5
On

Yes, this is most likely gamma correction.

Core Image uses a linear (not gamma-compressed) sRGB working color space, i.e. all the color values you read and write in your kernel are interpreted as linear, un-corrected light values.
However, most render destinations have a non-linear color space (like sRGB or Display P3), so gamma compression is happening during rendering, which changes how pixel values are stored (but not displayed).

If you want to disable gamma correction for your output, you need to specify a linear output color space, like linearSRGB or extendedLinearDisplayP3.