1

I want to render a CIImage into a pixel buffer of type kCVPixelFormatType_128RGBAFloat. But CIContext.render() fails saying "unsupported format". I tested on the iPhone 7 Plus running iOS 11.

Here's my code:

let context = CIContext()
var buffer: CVPixelBuffer? = nil
let buffer = CVPixelBufferCreate(nil,
                                 width,
                                 height,
                                 kCVPixelFormatType_128RGBAFloat,
                                 nil,
                                 &buffer)
assert(buffer != nil, "Couldn't create buffer")
context.render(ciImage, to: buffer)

The buffer is created successfully — the assertion doesn't fire. It's only the rendering in the last line that fails saying "unsupported format".

I also tried creating an IOSurface-backed CVPixelBuffer by replacing the second nil with [kCVPixelBufferIOSurfacePropertiesKey: [:]] as CFDictionary, but it didn't help.

How do I get this to work?

The format needs to be kCVPixelFormatType_128RGBAFloat, for reason that are too complex to get into here, the short version being that the pixel values have a greater range than 0-255, including fractional values that cannot be rounded.

I tried some more things:

None of these worked. Is rendering to 32-bits per channel floats or 16 bits per channel ints not supported by Core Image?

Kartick Vaddadi
  • 4,818
  • 6
  • 39
  • 55

1 Answers1

0

If 16 bits per channel is enough, you can render using kCVPixelFormatType_64RGBAHalf.

gemedet
  • 1
  • 1