Conversion

Convert an image to a different format.

Overview

Conversion functions change an image from one image format into another. These functions work with the formats supported by vImage (Planar8, PlanarF, ARGB8888, ARGBFFFF, RGBA8888, and RGBAFFFF) but they can also change between a supported format to one that’s not supported by vImage (such as RGB565). Conversion functions can also fill buffers with a color, overwrite channels, permute channels, flatten data, and clip data.

Conversion functions use a vImage buffer structure (vImage_Buffer—see Data Types and Constants) to receive and supply image data. This buffer contains a pointer to image data, the height and width (in pixels) of the image data, and the number of row bytes. You actually pass a pointer to a vImage buffer structure. For some functions, you can provide a pointer to the same vImage buffer structure for the source images and the destination image because the function “works in place”. That is , the source and destination images can occupy the same memory if the they are strictly aligned pixel for pixel.

Topics

Converting Any-to-Any

You use vImage's vImageConvert_AnyToAny(_:_:_:_:_:) function to convert between Core Video or Core Graphics image data of arbitrary color spaces and bit depths. The source and destination images are described by one or more buffers. For example, a Y'CbCr image may be composed of one buffer containing luminance information and one buffer containing chrominance information.

Building a Basic Conversion Workflow

Learn the fundamentals of the convert-any-to-any function by converting a CMYK image to an RGB image.

class vImageConverter

A description of a conversion from one image format to another.

func vImageConverter_GetSourceBufferOrder(vImageConverter) -> UnsafePointer<vImageBufferTypeCode>!

Returns a list of vImage source buffer channel names, specifying the order of planes.

func vImageConverter_GetDestinationBufferOrder(vImageConverter) -> UnsafePointer<vImageBufferTypeCode>!

Returns a list of vImage destination buffer channel names, specifying the order of planes.

vImage Buffer Type Codes

Constants that specify the contents of vImage buffers.

func vImageConverter_GetNumberOfSourceBuffers(vImageConverter) -> UInt

Returns the number of source buffers consumed by the converter.

func vImageConverter_GetNumberOfDestinationBuffers(vImageConverter) -> UInt

Returns the number of destination buffers written to by the converter.

Converting from 8-Bit Format

Converting from 12-Bit Format

Converting from 16-Bit Format

func vImageConvert_16SToF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Float, Float, vImage_Flags) -> vImage_Error

Converts an image in a special planar format—in which each pixel value is a 16-bit signed integer—image to a PlanarF format.

func vImageConvert_16UToF(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Float, Float, vImage_Flags) -> vImage_Error

Converts an image in a special planar format—in which each pixel value is a 16-bit unsigned integer—image to a PlanarF format.

func vImageConvert_16UToPlanar8(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Converts an image in a special planar format—in which each pixel value is a 16-bit unsigned integer—image to a Planar8 image.

Converting from 32-Bit Format

Converting Between Chunky and Planar Formats

These convenience functions allow you to convert between various interleaved (or chunky) formats that vImage does not explicitly support (and that may have less than or more than four channels) and the formats that vImage supports explicitly. You can represent some non-interleaved formats as well. The functions are not fast or vectorized.

Converting from Planar Formats

func vImageConvert_FTo16S(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Float, Float, vImage_Flags) -> vImage_Error

Converts a PlanarF image into a special format in which each pixel is a 16-bit signed integer.

func vImageConvert_FTo16U(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Float, Float, vImage_Flags) -> vImage_Error

Converts a PlanarF image into a special format in which each pixel is a 16-bit unsigned integer.

Converting Between Planar Formats

func vImageConvert_PlanarFtoPlanar8(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Pixel_F, Pixel_F, vImage_Flags) -> vImage_Error

Converts a PlanarF image to a Planar8 image, clipping values to the provided minimum and maximum values.

Converting from ARGB Formats

func vImageConvert_ARGBFFFFtoRGBFFF(UnsafePointer<vImage_Buffer>!, UnsafePointer<vImage_Buffer>!, vImage_Flags) -> vImage_Error

Converts a four-channel ARGBFFFF image to a three-channel RGBFFF image by removing the alpha channel.

func vImageConvert_ARGB8888toRGB888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Converts a four-channel ARGB8888 image to a three-channel RGB888 image by removing the alpha channel..

Converting from XRGB Formats

Converting from BGRA Formats

func vImageConvert_BGRAFFFFtoRGBFFF(UnsafePointer<vImage_Buffer>!, UnsafePointer<vImage_Buffer>!, vImage_Flags) -> vImage_Error

Converts a four-channel BGRAFFFF image to a three-channel RGBFFF image by removing the alpha channel.

func vImageConvert_BGRA8888toRGB888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Converts a four-channel BGRA8888 image to a three-channel RGB888 image by removing the alpha channel.

Converting from RGBA Formats

func vImageConvert_RGBAFFFFtoRGBFFF(UnsafePointer<vImage_Buffer>!, UnsafePointer<vImage_Buffer>!, vImage_Flags) -> vImage_Error

Converts a four-channel RGBAFFFF image to a three-channel RGBFFF image by removing the alpha channel.

func vImageConvert_RGBA8888toRGB888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

Converts a four-channel RGBA8888 image to a three-channel RGB888 image by removing the alpha channel.

Converting from RGB Formats

func vImageConvert_RGB565toRGBA5551(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Int32, vImage_Flags) -> vImage_Error

Converts an RGB565 image to an RGBA5551 image with dithering, setting destination alpha to one.

func vImageConvert_RGB565toARGB1555(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Int32, vImage_Flags) -> vImage_Error

Converts an RGB565 image to an ARGB1555 image with dithering, setting destination alpha to one.

Converting from YUV Formats

struct vImageYpCbCrType

Constants indicating the encoding of a YUV image format type to be used with RGB / Y'CbCr conversions.

struct vImageARGBType

Constants indicating the encoding of an ARGB image format type to be used with RGB / Y'CbCr conversions.

struct vImage_YpCbCrToARGBMatrix

A 3 x 3 matrix for converting Y'CbCr signals to RGB.

struct vImage_YpCbCrToARGB

An opaque representation of a 3 x 3 matrix for converting Y'CbCr signals to RGB.

struct vImage_YpCbCrPixelRange

Range and clamping information for Y'CbCr pixel formats.

Converting to YUV Formats

struct vImageYpCbCrType

Constants indicating the encoding of a YUV image format type to be used with RGB / Y'CbCr conversions.

struct vImageARGBType

Constants indicating the encoding of an ARGB image format type to be used with RGB / Y'CbCr conversions.

struct vImage_ARGBToYpCbCrMatrix

A 3 x 3 matrix for converting RGB to Y'CbCr.

struct vImage_ARGBToYpCbCr

An opaque representation of a 3x3 matrix for converting RGB to Y'CbCr.

struct vImage_YpCbCrPixelRange

Range and clamping information for Y'CbCr pixel formats.