How to use kCIFormatRGBAh to get half float on iOS with Core Image?

I am trying to get RGBA pixel values ​​per pixel for CIImage in floating point.

I expect the following to work using CIContext and rendering as kCIFormatRGBAh , but the output will be zero. Otherwise, my next step will be to completely convert the full floats.

What am I doing wrong? I also tried this in Objective-C and got the same result.

 let image = UIImage(named: "test")! let sourceImage = CIImage(CGImage: image.CGImage) let context = CIContext(options: [kCIContextWorkingColorSpace: NSNull()]) let colorSpace = CGColorSpaceCreateDeviceRGB() let bounds = sourceImage.extent() let bytesPerPixel: UInt = 8 let format = kCIFormatRGBAh let rowBytes = Int(bytesPerPixel * UInt(bounds.size.width)) let totalBytes = UInt(rowBytes * Int(bounds.size.height)) var bitmap = calloc(totalBytes, UInt(sizeof(UInt8))) context.render(sourceImage, toBitmap: bitmap, rowBytes: rowBytes, bounds: bounds, format: format, colorSpace: colorSpace) let bytes = UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(bitmap), count: Int(totalBytes)) for (var i = 0; i < Int(totalBytes); i += 2) { println("half float :: left: \(bytes[i]) / right: \(bytes[i + 1])") // prints all zeroes! } free(bitmap) 

Here's a related question about getting CIAreaHistogram output, so I want floating point values, not integers, but I can't get kCIFormatRGBAh to work with any CIImage regardless of its origin, filter output, or otherwise.

+2
source share
1 answer

There are two limitations to using RGBAh with [CIContext render:toBitmap:rowBytes:bounds:format:colorSpace:] on iOS

  • rowBytes must be a multiple of 8 bytes
  • a call under the simulator is not supported

These limitations are related to OpenGLES behavior from RGBAh on iOS.

+1
source

Source: https://habr.com/ru/post/1208083/


All Articles