【问题标题】:CIColorClamp not working correctly in OS X El CapitanCIColorClamp 在 OS X El Capitan 中无法正常工作
【发布时间】:2016-01-01 10:03:08
【问题描述】:

我正在使用 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)")

上面的代码产生了输出:

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

此调用会产生内部警告这一事实也不能增强信心!

谁能确认这种行为?我做错了什么?

【问题讨论】:

    标签: macos swift cocoa core-image osx-elcapitan


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      我确实遇到了问题。我只是通过将返回的图像裁剪为原始图像矩形来修复它(Objective-C 代码):

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

      【讨论】:

        猜你喜欢
        • 2016-01-07
        • 2016-01-11
        • 1970-01-01
        • 1970-01-01
        • 2016-01-27
        • 1970-01-01
        • 2016-10-24
        • 2017-02-27
        • 2015-11-05
        相关资源
        最近更新 更多