I am using Swift to do some video processing. After upgrading to El Capitan (and Swift 2) my code broke. I traced an error down to the CIFilter function CIColorClamp. This function is supposed to clamp the pixel values, but in fact messes up the image extent.
let _c:CGFloat = 0.05
let minComp = CIVector(x:_c, y:_c, z:_c, w: 1)
let maxComp = CIVector(x:1, y:1, z:1, w: 1)
let clamp: CIFilter = CIFilter(name: "CIColorClamp")!
print("clamp-in \(image.extent)")
clamp.setDefaults()
clamp.setValue(image, forKey: kCIInputImageKey)
clamp.setValue(minComp, forKey: "inputMinComponents")
clamp.setValue(maxComp, forKey: "inputMaxComponents")
print("clamp-out \(clamp.outputImage!.extent)")
The code above produces the output:
> clamp-in (6.0, 6.0, 1268.0, 708.0)
CoreAnimation: Warning! CAImageQueueSetOwner() is deprecated and does nothing. Please stop calling this method.
> clamp-out (-8.98846567431158e+307, -8.98846567431158e+307, 1.79769313486232e+308, 1.79769313486232e+308)
The fact that this call produces an internal warning does not instill confidence either!
Can anyone confirm this behavior? What am I doing wrong?
I also ran into this Problem. The extent was always set like this
-8.98846567431158e+307, -8.98846567431158e+307, 1.79769313486232e+308, 1.79769313486232e+308
but then I tried calling filter.debugDescription
and recognized that in the extent in the sourceImage is given properly.
Here's my workaround. Because I use different filters, I ask if the filters name is 'CIColorClamp'
and then I set the extent used in the CGImageRef
to the values from the original image.
var extent = filteredImage.extent
if filter.name == "CIColorClamp" {
extent = sourceImage.extent
}
let cgImage:CGImageRef = context.createCGImage(filteredImage, fromRect: extent)
UIImageJPEGRepresentation(UIImage(CGImage: cgImage), 1.0).writeToFile(...)
Before that fix I always had an Crash cause the UIImageJPEGRepresentation
could not be created, cause of the wrong extent values.
So it looks like that the extent is not transferred to the filtered image.
I had exactly the problem. I fixed it simply by cropping the returned image to the original image rect (Objective-C code):
if ([filter.name isEqualToString:@"CIColorClamp"]) {
image = [image imageByCroppingToRect:sourceImage.extent];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With