UIColor colorWithDisplayP3RGBA convert to CGColor loses wide gamut

221 Views Asked by At

I am trying to use two UIColors created in the p3 color space in a CAGradientLayer, however when getting the .CGColor from the UIColors the colors appear muted (they are clearly being clipped to a standard gamut).

What is the proper way to get CGColor from UIColor and retain the extra range of P3?

Code below:

gradientColor1 = [UIColor colorWithDisplayP3Red:255.0/255.0 green:146.0/255.0 blue:226.0/255.0 alpha:1.0];
gradientColor2 = [UIColor colorWithDisplayP3Red:248.0/255.0 green:254.0/255.0 blue:190.0/255.0 alpha:1.0];
// these colors look lovely when used as backgrounds for UIViews etc.

gradient.frame = bgColorView.bounds;
gradient.colors = @[(id)gradientColor1.CGColor , (id)gradientColor2.CGColor];

gradient.startPoint = CGPointMake(0.5, 0.41);
gradient.endPoint = CGPointMake(0.5, 0.84);

// the gradient layer now shows muted colors :(
[bgColorView.layer insertSublayer:gradient atIndex:0];

EDIT:

If I set the CGColor as the background color of a CALayer the color is rendered accurately so the problem appears to occur specifically with the CAGradientLayer. I have tried setting just a single color to the CAGradientLayer's colors property and it is rendered incorrectly in the sRGB color space.

Why would the CAGradientLayer exhibit this behaviour?

0

There are 0 best solutions below