Search code examples
iosimage-processingcolorsshadermetal

Equations for converting linear to Apple Display P3 color space and vice versa


I'm developing an app that does image processing. In this app I need to apply Linear to Apple Display P3 color conversion to my texture (Linear). The operation will have to be done using shaders, I have already created a shader using these equations from Apple documentation archive that convert from Linear to sRGB and vice versa:

rgb = mix(rgb.0.0774, pow(rgb*0.9479 + 0.05213, 2.4), step(0.04045, rgb))
rgb = mix(rgb12.92, pow(rgb*0.4167) * 1.055 - 0.055, step(0.00313, rgb))

My question is what would the equation be for converting linear to Apple Display P3 color space and vice versa?


Solution

  • The conversion between linear and encoded RGB in the Display P3 color space is the same as for sRGB.

    Note that DCI-P3 and Display P3 are not the same color space, even though they use the same red, green, and blue points (the former uses a simple power function for conversion between linear and encoded RGB; for example, pow(rgb, 2.2) for conversion to linear).

    Note also that "linear RGB" is an incomplete description of a texture's colors. Rather, the texture has to be in some known color space (such as sRGB or DCI-P3); this is often sRGB if the texture has no embedded color profile. In many cases, "linear RGB" simply means that the corresponding color space's transfer function was not applied to the texture's RGB colors.