iOS Development

ios – [[stitchable]] Metallic core picture CIKernel fails

It appears to be like like [[stitchable]] Metallic Core Picture kernels fail to get added within the default metallic library. Right here is my code:

import CoreImage

class FilterTwo: CIFilter {
var inputImage: CIImage?
var inputParam: Float = 0.0

static var kernel: CIKernel = { () -> CIKernel in
   let url = Bundle.fundamental.url(forResource: "default",
                            withExtension: "metallib")!
   let knowledge = attempt! Knowledge(contentsOf: url)

    let kernelNames = CIKernel.kernelNames(fromMetalLibraryData: knowledge)
    NSLog("Kernels (kernelNames)")
   return attempt! CIKernel(functionName: "secondFilter", fromMetalLibraryData: knowledge) //<-- This fails!

override var outputImage : CIImage? {
    guard let inputImage = inputImage else {
        return nil
    return FilterTwo.kernel.apply(extent: inputImage.extent, roiCallback: { (index, rect) in
        return rect }, arguments: [inputImage])


Right here is the Metallic file:

 #embrace <CoreImage/CoreImage.h> // contains CIKernelMetalLib.h

 utilizing namespace metallic;

 [[ stitchable ]] half4 secondFilter (coreimage::sampler inputImage, coreimage::vacation spot dest)
   float2 srcCoord = inputImage.coord();
   half4 coloration =  half4(inputImage.pattern(srcCoord));

   return coloration;

And right here is the utilization:

       class ViewController: UIViewController {

override func viewDidLoad() {
    // Do any further setup after loading the view.
    let filter = FilterTwo()
    filter.inputImage = CIImage(coloration: CIColor.purple)
    let outputImage = filter.outputImage!
    NSLog("Output (outputImage)")


And the output:

     StitchableKernelsTesting/FilterTwo.swift:15: Deadly error: 'attempt!' expression unexpectedly raised an error: Error Area=CIKernel Code=1 "(null)" UserInfo={CINonLocalizedDescriptionKey=Operate doesn't exist in library knowledge. …•∆}
   Kernels []

   mirror Operate 'secondFilter' doesn't exist.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button