CIColorClamp在OS X El Capitan中无法正常工作

Har*_*rry 5 macos cocoa core-image swift osx-elcapitan

我正在使用Swift进行一些视频处理.升级到El Capitan(和Swift 2)后,我的代码破了.我将错误追溯到CIFilter函数CIColorClamp.该函数应该用于钳制像素值,但实际上会影响图像范围.

    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)")
Run Code Online (Sandbox Code Playgroud)

上面的代码产生输出:

> 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)
Run Code Online (Sandbox Code Playgroud)

此调用产生内部警告的事实也不会灌输信心!

谁能证实这种行为?我究竟做错了什么?

tet*_*uss 2

我也遇到了这个问题。范围总是这样设置的

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

但后来我尝试打电话filter.debugDescription并认识到在 sourceImage 中给出的范围是正确的。

这是我的解决方法。因为我使用不同的过滤器,所以我询问过滤器名称是否为'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(...)
Run Code Online (Sandbox Code Playgroud)

在修复之前,我总是遇到崩溃,因为UIImageJPEGRepresentation无法创建错误的范围值。

所以看起来范围没有转移到过滤后的图像上。