Class

MPSImageConversion

A filter that performs a conversion of color space, alpha, or pixel format.

Declaration

@interface MPSImageConversion : MPSUnaryImageKernel

Overview

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.

Listing 1 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)

Topics

Methods

- initWithDevice:srcAlpha:destAlpha:backgroundColor:conversionInfo:

Initializes a filter that can convert texture color space, alpha, and pixel format.

MPSAlphaType

Premultiplication description for the color channels of an image.

Properties

sourceAlpha

Premultiplication description for the source texture.

destinationAlpha

Premultiplication description for the destination texture.

Relationships

Inherits From

See Also

Image Manipulation Filters

MPSImageScale

A filter that resizes and changes the aspect ratio of an image.

MPSImageLanczosScale

A filter that resizes and changes the aspect ratio of an image using Lanczos resampling.

MPSImageBilinearScale

A filter that resizes and changes the aspect ratio of an image using Bilinear resampling.

MPSImageTranspose

A filter that transposes an image.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software