Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Source/UIImageEffects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ public extension UIImage {
print("*** error: image must be backed by a CGImage: \(self)")
return nil
}
if maskImage != nil && maskImage!.cgImage == nil {
guard let maskCGImage = maskImage?.cgImage else {
print("*** error: maskImage must be backed by a CGImage: \(String(describing: maskImage))")
return nil
}

let __FLT_EPSILON__ = CGFloat(Float.ulpOfOne)
let __FLT_EPSILON__ = CGFloat.ulpOfOne
let screenScale = UIScreen.main.scale
let imageRect = CGRect(origin: CGPoint.zero, size: size)
let imageRect = CGRect(origin: .zero, size: size)
var effectImage = self

let hasBlur = blurRadius > __FLT_EPSILON__
Expand All @@ -183,13 +183,11 @@ public extension UIImage {

var effectInBuffer = createEffectBuffer(effectInContext)


UIGraphicsBeginImageContextWithOptions(size, false, screenScale)

guard let effectOutContext = UIGraphicsGetCurrentContext() else { return nil }
var effectOutBuffer = createEffectBuffer(effectOutContext)


if hasBlur {
// A description of how to compute the box kernel width from the Gaussian
// radius (aka standard deviation) appears in the SVG spec:
Expand Down Expand Up @@ -226,7 +224,7 @@ public extension UIImage {
0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
0, 0, 0, 1
0, 0, 0, 1
]

let divisor: CGFloat = 256
Expand Down Expand Up @@ -272,9 +270,7 @@ public extension UIImage {
// Draw effect image.
if hasBlur {
outputContext.saveGState()
if let maskCGImage = maskImage?.cgImage {
outputContext.clip(to: imageRect, mask: maskCGImage);
}
outputContext.clip(to: imageRect, mask: maskCGImage);
outputContext.draw(effectImage.cgImage!, in: imageRect)
outputContext.restoreGState()
}
Expand Down