ios - 如何将 CISampler 传递给基于 Metal 的 CIColorKernel?

标签 ios metal cifilter

我正在尝试制作基于 Metal 的 CIFilter,因为 Apple 似乎更喜欢您使用它,但我遇到了问题,因为我需要合并多个可能大小不同的图像。这意味着我必须使用标准化坐标和采样器来“拉伸(stretch)”各种输入图像。

这是一个示例内核:

extern "C" { namespace coreimage {
    float4 stretchKernel(
                         sampler image
                         ) {
        return image.sample(image.coord());
    }
}}

...我像这样实现它:
    let arguments: [Any] = [
        CISampler(image: startingImage, options: samplerOptions)
    ]

    return kernel.apply(extent: startingImage.extent, arguments: arguments)

现在奇怪的一点。如果我运行它,我会收到以下错误:
Argument info count 1 for function composition does not match argument count 4 in declaration of function
就好像采样器在内核函数中被视为四个单独的参数,但我只能将它们作为一个传递。我是否使用正确的类将图像传递到内核?内核声明有问题吗?我是否可以使用其他方法为我的各种图像获取标准化坐标和采样器?

最佳答案

好吧,我不知道为什么我无法从文档中找到这个,但原因似乎是 filter类型与 CIColorKernel 不兼容.我敢说有一个很好的理由,但我不知道为什么没有更明确地说明。解决方法是使用普通的CIKernel反而。

关于ios - 如何将 CISampler 传递给基于 Metal 的 CIColorKernel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54460317/

相关文章:

ios - 如何打开特定联系人的编辑联系人屏幕

ios - CKSubscriptionOptionsFiresOnRecordUpdate 类型的 CKSubscription 不起作用

objective-c - 将 ObjC id<Protocol> 和类型对象转换为 C 指针 (void *) 然后将其转换回去是否安全?

ios - 来自 CMSampleBuffer 的 MTLTexture 有 0 bytesPerRow

ios - 带有 GLSL 的 CIKernel 白色像素

ios - 带有 CIQRCodeGenerator 的 CIFilter 导致崩溃

ios - 条件绑定(bind)的初始化程序必须具有 Optional 类型,而不是 '[AVCaptureDevice]'

ios - 使用 Navigationcontroller 在 Tabbarcontroller 中构建层次结构

ios - 如何在 Metal 中组合使用不同着色器的渲染命令编码器

swift - CIFilter 中的图像不会显示