Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created October 13, 2017 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikhilManapure/07e84be835f243f3db5f150d98890dd7 to your computer and use it in GitHub Desktop.
Save NikhilManapure/07e84be835f243f3db5f150d98890dd7 to your computer and use it in GitHub Desktop.
let blur = GPUImageGaussianSelectiveBlurFilter()
func addBlur() {
gpuImage?.removeAllTargets()
blur.blurRadiusInPixels = 20.0
blur.excludeBlurSize = 0.0
blur.excludeCircleRadius = 0.0
blur.excludeCirclePoint = CGPoint(x: 0.5, y: 0.5)
blur.aspectRatio = 1.3
gpuImage?.addTarget(blur)
blur.addTarget(gpuImageView)
gpuImage?.processImage()
}
let minimumZoom: CGFloat = 0.0
let maximumZoom: CGFloat = 4.0
var lastZoomFactor: CGFloat = 0.3
@IBAction func pinched(_ pinch: UIPinchGestureRecognizer) {
func minMaxZoom(_ factor: CGFloat) -> CGFloat {
return min(min(max(factor, minimumZoom), maximumZoom), 1)
}
func update(scale factor: CGFloat) {
blur.excludeBlurSize = factor / 3
blur.excludeCircleRadius = factor
gpuImage?.processImage()
}
let newScaleFactor = minMaxZoom(pinch.scale * lastZoomFactor)
switch pinch.state {
case .began: fallthrough
case .changed: update(scale: newScaleFactor)
case .ended:
lastZoomFactor = minMaxZoom(newScaleFactor)
update(scale: lastZoomFactor)
default: break
}
}
@IBAction func tapHandler(_ gestureRecognizer: UITapGestureRecognizer) {
let location = gestureRecognizer.location(in: currentImageView)
blur.excludeCirclePoint = CGPoint(x: location.x / currentImageView.bounds.width, y: location.y / currentImageView.bounds.height)
gpuImage?.processImage()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment