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.
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)
it looks like there is a gamma correction? how to fix this? anyone help
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
orextendedLinearDisplayP3
.