MTKView Displays Gamut P3 Wide Space

I am creating a real-time photo editor based on CIFilters and MetalKit. But I ran into a problem with displaying wide gamma images in MTKView.

Standard sRGB images display very well, but images with P3 images are washed out.

I tried to set the color space CIContext.renderas the color space of the image and am still experiencing a problem.

Here are the code snippets:

 guard let inputImage = CIImage(mtlTexture: sourceTexture!) else { return }
                let outputImage = imageEditor.processImage(inputImage)
                print(colorSpace)
                context.render(outputImage,
                               to: currentDrawable.texture,
                               commandBuffer: commandBuffer,
                               bounds: inputImage.extent,
                               colorSpace: colorSpace)
                commandBuffer?.present(currentDrawable)

let pickedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
        print(pickedImage.cgImage?.colorSpace)
        if let cspace = pickedImage.cgImage?.colorSpace {
            colorSpace = cspace
        }

I found a similar problem on the Apple developer forums, but without answers: https://forums.developer.apple.com/thread/66166

+4
source share
1 answer

, colorPixelFormat MTKView BGRA10_XR bgra10_XR_sRGB. , colorSpace macOS MTKViews iOS, iOS , ( ).

, , . , , .

, P3? UIColor :

UIColor(displayP3Red: 1, green: 0, blue: 0, alpha: 1)

UIButton , . , , sRGB,

    var fRed : CGFloat = 0
    var fGreen : CGFloat = 0
    var fBlue : CGFloat = 0
    var fAlpha : CGFloat = 0
    let c = UIColor(displayP3Red: 1, green: 0, blue: 0, alpha: 1)
    c.getRed(&fRed, green: &fGreen, blue: &fBlue, alpha: &fAlpha)

MacOS Color Sync,

Color Sync Utility

, Extended Range, 0 1.

, , P3 (1, 0, 0) (1.0930, -0.2267, -0.1501) sRGB.

MTKView,

  • colorPixelFormat MTKView .BGRA10_XR, ,

    (1.0930, -0.2267, -0.1501)

  • colorPixelFormat MTKView .bgra10_XR_sRGB, ,

    (1.22486, -0.0420312, -0.0196301)

    RGB, -. , . ,

    let f = {(c: Float) -> Float in
        if fabs(c) <= 0.04045 {
            return c / 12.92
        }
        return sign(c) * powf((fabs(c) + 0.055) / 1.055, 2.4)
    }
    

UIImage. CGColorSpace.displayP3 . , ?

(1, 0, 0)

(65535, 0, 0) 16- ints.

, , .rgba16Unorm displayP3, (1, 0, 0) P3. , UIImage. , , , P3 sRGB (, ) . , - 3x3. .bgra10_XR_sRGB, .

( ),

 1.2249  -0.2247  0
-0.0420   1.0419  0
-0.0197  -0.0786  1.0979

, : display-P3

, UIButtons MTKView, iPhoneX,

Red MTKView

sRGB, displayP3. MTKView, , .

, Green MTKView

, iPhone iPad, , . Mac, , . Windows , , , sRGB , , ... .

, testP3UIColor unit test, : ColorTests.swift,

UIImage: Image.swift,

, : SampleColorPalette

CIImages, , .

, . , , , displayP3 Metal SDK.

+1

Source: https://habr.com/ru/post/1682185/


All Articles