CIColorClamp does not work correctly on OS X El Capitan

I use Swift to process the video. After upgrading to El Capitan (and Swift 2), my code broke. I traced the error to the CIFilter CIColorClamp function. This feature is supposed to pinch pixel values, but actually spoil the image volume.

    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 above code displays the result:

> 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 causes an internal warning also does not give confidence!

Can anyone confirm this behavior? What am I doing wrong?

+4
source share
2 answers

I also ran into this problem. The degree has always been as

-8.98846567431158e + 307, -8.98846567431158e + 307, 1.79769313486232e + 308, 1.79769313486232e + 308

filter.debugDescription , , , .

. , , 'CIColorClamp', , CGImageRef, .

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(...)

Crash, UIImageJPEGRepresentation , .

, , .

+2

. , rect (Objective-C code):

if ([filter.name isEqualToString:@"CIColorClamp"]) {
    image = [image imageByCroppingToRect:sourceImage.extent];
}
+1

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


All Articles