<!--
{
  "documentType" : "article",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/building-a-basic-image-conversion-workflow",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Building a basic image conversion workflow"
}
-->

# Building a basic image conversion workflow

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

## Discussion

The functions in the vImage library that perform image-processing operations are specific to properties such as bit-depth, the number of channels, and channel ordering. For example, the [`vImageAlphaBlend_ARGB8888(_:_:_:_:)`](/documentation/Accelerate/vImageAlphaBlend_ARGB8888(_:_:_:_:)) function works with 8-bit-per-channel, ARGB image data. The convert-any-to-any functionality allows you to convert images with formats you know at runtime to a format you define at compile time.

You can use the vImage convert-any-to-any functionality to convert image data between different bit depths, different channel counts, and different color spaces. In this example, the code converts a 16-bit-per-channel CMYK source image to an 8-bit-per-channel RGB destination image. In some cases, working in a non-RGB color space simplifies image-processing tasks. For an example of using convert-any-to-any to work in L*a*b* color space, see <doc://com.apple.documentation/documentation/Accelerate/adjusting-the-hue-of-an-image>.

### Create the source and destination image formats

A [`vImageConverter`](/documentation/Accelerate/vImageConverter) instance – that contains the information to perform image conversion – requires two [`vImage_CGImageFormat`](/documentation/Accelerate/vImage_CGImageFormat) structures that describe the source and destination formats. The code below defines the CMYK source format and the RGB destination format:

```swift
let cmykSourceImageFormat = vImage_CGImageFormat(
    bitsPerComponent: 16,
    bitsPerPixel: 16 * 4,
    colorSpace: CGColorSpaceCreateDeviceCMYK(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!

let rgbDestinationImageFormat = vImage_CGImageFormat(
    bitsPerComponent: 8,
    bitsPerPixel: 8 * 3,
    colorSpace: CGColorSpaceCreateDeviceRGB(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!
```

### Create the converter

The Swift [`make(sourceFormat:destinationFormat:flags:)`](/documentation/Accelerate/vImageConverter/make(sourceFormat:destinationFormat:flags:)-8tbym) method calls the underlying [`vImageConverter_CreateWithCGImageFormat(_:_:_:_:_:)`](/documentation/Accelerate/vImageConverter_CreateWithCGImageFormat(_:_:_:_:_:)) function and returns a new any-to-any converter instance.

```swift
let cmykToRgbConverter = try vImageConverter.make(
    sourceFormat: cmykSourceImageFormat,
    destinationFormat: rgbDestinationImageFormat)
```

### Perform the conversion using pixel buffers

The code below converts the CMYK image data that `cmykSourceBuffer` contains and writes the RGB result to `rgbDestinationBuffer`. In this example, `cmykSourceBuffer` is a [`vImage.PixelBuffer`](/documentation/Accelerate/vImage/PixelBuffer) structure with a [`vImage.Interleaved16Ux4`](/documentation/Accelerate/vImage/Interleaved16Ux4) format.

The Swift [`convert(from:to:)`](/documentation/Accelerate/vImageConverter/convert(from:to:)-9s7p7) method calls the underlying [`vImageConvert_AnyToAny(_:_:_:_:_:)`](/documentation/Accelerate/vImageConvert_AnyToAny(_:_:_:_:_:)) function.

```swift
let rgbDestinationBuffer = vImage.PixelBuffer<vImage.Interleaved8x3>(
    size: cmykSourceBuffer.size)

try cmykToRgbConverter.convert(from: cmykSourceBuffer,
                               to: rgbDestinationBuffer)
```

On return, `rgbDestinationBuffer` contains the RGB representation of the CMYK source image.

### Perform the conversion using vImage buffers

If you’re creating apps for older operating systems that don’t support the [`vImage.PixelBuffer`](/documentation/Accelerate/vImage/PixelBuffer) API, the following code performs the same conversion using [`vImage_Buffer`](/documentation/Accelerate/vImage_Buffer) structures.

The Swift [`convert(source:destination:flags:)`](/documentation/Accelerate/vImageConverter/convert(source:destination:flags:)) method calls the underlying [`vImageConvert_AnyToAny(_:_:_:_:_:)`](/documentation/Accelerate/vImageConvert_AnyToAny(_:_:_:_:_:)) function

```swift
var rgbDestinationBuffer = try vImage_Buffer(
    size: cmykSourceBuffer.size,
    bitsPerPixel: rgbDestinationImageFormat.bitsPerPixel)

try cmykToRgbConverter.convert(source: cmykSourceBuffer,
                               destination: &rgbDestinationBuffer)
```

On return, `rgbDestinationBuffer` contains the RGB representation of the CMYK source image.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)