Silence-GitHub / BBMetalImage

A high performance Swift library for GPU-accelerated image/video processing based on Metal.
MIT License
985 stars 125 forks source link

Can not use BBMetalGaussianBlurFilter when apply filter asynchronously? #48

Closed lygialiem closed 4 years ago

lygialiem commented 4 years ago

HI team.

I'm facing some problem. I have an iOS app that let user custom their image. I apply all the filter which include the BBMetalGaussianBlurFilter at first open app and user will slide the slider to change the param of filter. Other filters work fine except the BBMetalGaussianBlurFilter. It didn't have any effect. Could you guys check this problem.

lygialiem commented 4 years ago

I have customed BBMetalGaussianBlurFilter with "var" sigma property so that i can change this property with slider and it did not work. But at first time, I saw you set it with "let". Could you have any explain for it? Hope to see your response soon.

Silence-GitHub commented 4 years ago

Good issue! I use "let" because MPSImageGaussianBlur can not set sigma. I try to use "var" sigma in the filter, and update kernel after setting sigma. It works. Do you do it in this way? Thanks for issuing. Would you like to create a pull request?

lygialiem commented 4 years ago

Hi Silence-Github

I'm sorry for wrong texting. "... so that i can change this property with slider and IT DID NOT WORK. ...". Although I have customed with "var" and apply Blur to chain asynchronously, It still did not works.

Silence-GitHub commented 4 years ago

Please try version 1.1.4

lygialiem commented 4 years ago

Hi Hi Silence-Github

Thank you for your support. It seems like that BBMetalGaussianBlurFilter still doesn't work.

Silence-GitHub commented 4 years ago

The code below works.

var imageView: UIImageView!
var imageSource: BBMetalStaticImageSource!
var filter: BBMetalGaussianBlurFilter!

override func viewDidLoad() {
    ...

    imageView = ...

    let slider = UISlider(frame: ...)
    slider.minimumValue = 0
    slider.maximumValue = 5
    slider.value = 0
    slider.addTarget(self, action: #selector(slide(_:)), for: .valueChanged)
    view.addSubview(slider)

    imageSource = BBMetalStaticImageSource(image: image)
    filter = BBMetalGaussianBlurFilter(sigma: 0)
    imageSource.add(consumer: filter)
        .addCompletedHandler { [weak self] _ in
            guard let self = self  else { return }
            DispatchQueue.main.async {
                self.imageView.image = self.filter.outputTexture?.bb_image
            }
    }
}

@objc private func slide(_ slider: UISlider) {
    filter.sigma = slider.value
    imageSource.transmitTexture()
}
lygialiem commented 4 years ago

Hi Silence-Github

Thank you very much for your support. It worked!!!. We can close this topic.