BradLarson / GPUImage3

GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.
BSD 3-Clause "New" or "Revised" License
2.68k stars 331 forks source link

Could you add a extension for TwoInputOperation? #80

Open JinjunHan opened 4 years ago

JinjunHan commented 4 years ago

Did I write the right code? `public extension Array where Element == PlatformImageType {

func filterWithOperation<T:ImageProcessingOperation>(_ operation:T) -> PlatformImageType {
    return filterWithPipeline{ inputs, output in
        inputs.forEach { (input) in
            input --> operation
        }
        operation --> output
    }
}

func filterWithPipeline(_ pipeline:([PictureInput], PictureOutput) -> ()) -> PlatformImageType {
    let pictures = self.map { (image) -> PictureInput in
        PictureInput(image: image)
    }
    var outputImage:PlatformImageType?
    let pictureOutput = PictureOutput()
    pictureOutput.onlyCaptureNextFrame = true
    pictureOutput.imageAvailableCallback = {image in
        outputImage = image
    }
    pipeline(pictures, pictureOutput)
    pictures.forEach { (input) in
        input.processImage(synchronously: true)
    }
    return outputImage!
}

}`