BBMetalImage icon indicating copy to clipboard operation
BBMetalImage copied to clipboard

Live filtering with slider

Open agruchala opened this issue 4 years ago • 4 comments

Is there an option to change filter values in fly, with slider or other control?

agruchala avatar Dec 21 '20 12:12 agruchala

For camera and video, just change the filter value.

contrastFilter.contrast = slider.value

For static image, change the filter value and transmit texture.

contrastFilter.contrast = slider.value
imageSource.transmitTexture()

Silence-GitHub avatar Dec 21 '20 17:12 Silence-GitHub

Hi It's not working, what I was doing wrong??

@objc func sliderValueDidChange(_ sender:UISlider!){
        let roundedStepValue = Float(round(sender.value / step) * step)
        sender.value = roundedStepValue
       
        var contrastFilter = BBMetalContrastFilter(contrast: roundedStepValue)
        contrastFilter.contrast = roundedStepValue
        
        if let filter = self.filter {
           camera.add(consumer: filter).add(consumer: filterView)
            filter.add(consumer: videoWriter)
            if let source = imageSource {
                camera.willTransmitTexture = { [weak self] _, _ in
                    guard self != nil else { return }
                    source.transmitTexture()
                }
                source.add(consumer: filter)
            }

        } else {
            camera.add(consumer: filterView)
            camera.willTransmitTexture = nil
            imageSource = nil
            camera.add(consumer: videoWriter)
         
        }
        
    }

niraj547 avatar Feb 15 '21 10:02 niraj547

@niraj547 Hi, the problem is the contrastFilter (local variable) is not in the filter chain.

Set up filter chain before changing the slider value. When changing the slider value, do not change the filter chain. Please try the code below.

// Call this function before changing the slider value
func setupFilterChain() {
    if let filter = self.filter {
        camera.add(consumer: filter).add(consumer: filterView)
        ...
    } else {
        camera.add(consumer: filterView)
        ...
    }
}

@objc func sliderValueDidChange(_ sender:UISlider!) {
    self.filter.contrast = ...
}

Silence-GitHub avatar Feb 15 '21 17:02 Silence-GitHub

Hi It doesn't work and also I think I have multiple filter buttons and each of them has a slider, doing this freeze the whole screen that might be the reason?

Also 1 quick question can we chain multiple filters in a single video recording or do I have to join all the video after each filter has been applied?? For example: filter1 applied 32sec + filter2 applied 32sec = final Video something like this

Sorry for asking a dumb question, I'm really new in ios Thanks

niraj547 avatar Feb 28 '21 08:02 niraj547