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])")
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.
source share