Created
October 13, 2017 06:42
-
-
Save NikhilManapure/07e84be835f243f3db5f150d98890dd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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