MPSImageConversion
A filter that performs a conversion of color space, alpha, or pixel format.
Declaration
class MPSImageConversionOverview
An MPSImageConversion filter allows you to change the alpha encoding or color space of an image. For example, you can convert an image with a premultiplied alpha to non-premultiplied, or change the color space from one variant to another.
As with all Metal Performance Shaders filters, the conversion filter allows for source and destination textures with different pixel formats and, in that case, will convert the source texture’s format to the destination texture’s format. See Supported Pixel Formats for Image Kernels for a list of supported pixel formats.
The following listing shows how you can create an image conversion filter to map the color intensity from the sRGB color space to a linear gamma curve.
Listing 1. Mapping color intensity from the sRGB color space to a linear gamma curve.
guard let srcColorSpace = CGColorSpace(name: CGColorSpace.sRGB),
let dstColorSpace = CGColorSpace(name: CGColorSpace.linearSRGB),
let device = MTLCreateSystemDefaultDevice() else {
return
}
let conversionInfo = CGColorConversionInfo(src: srcColorSpace,
dst: dstColorSpace)
let conversion = MPSImageConversion(device: device,
srcAlpha: .alphaIsOne,
destAlpha: .alphaIsOne,
backgroundColor: nil,
conversionInfo: conversionInfo)