简体   繁体   English

"使用 DOD 的 Metal Core Image Kernel"

[英]Metal Core Image Kernel use of DOD

I wrote the following Metal Core Image Kernel to produce constant red color.我编写了以下 Metal Core Image Kernel 来产生恒定的红色。

extern "C" float4 redKernel(coreimage::sampler inputImage, coreimage::destination dest)
{
  return float4(1.0, 0.0, 0.0, 1.0);
}

With the extent<\/code> parameter of the kernel call you signal the region for which the kernel produces meaningful results—or, as you correctly named it, the domain of definition<\/em> .使用内核调用的extent<\/code>参数,您可以向内核产生有意义结果的区域发出信号,或者,正如您正确命名的那样,定义域<\/em>。 However, this also means that whatever it produces outside this region is basically undefined and up to you as the kernel developer to decide.然而,这也意味着它在这个区域之外产生的任何东西基本上都是未定义的,由内核开发人员来决定。

A generator kernel like the one you wrote usually has an infinite<\/em> domain of definition since it just produces a red color, regardless of the input.像您编写的那样的生成器内核通常具有无限<\/em>的定义域,因为它只会产生红色,而与输入无关。 To restrict the output to a specific area, you can apply a crop to it:要将输出限制在特定区域,您可以对其应用裁剪:

let dod = inputImage.extent
let result = CIMetalTestRenderer.kernel.apply(extent: .infinite, roiCallback: { index, rect in
    return rect
}, arguments: [inputImage])
return result.cropped(to: dod)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM