Skip to content

Commit

Permalink
Fix processor and redraw orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Nov 29, 2019
1 parent 7784d52 commit 1eee4a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Sources/Image/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {

return draw(to: size, inverting: true, refImage: KFCrossPlatformImage()) {
fixOrientation(in: $0)
return true
}
}

Expand Down
23 changes: 19 additions & 4 deletions Sources/Image/ImageDrawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
}

base.draw(in: rect, blendMode: blendMode, alpha: alpha)
return false
}
}
#endif
Expand Down Expand Up @@ -94,6 +95,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
rect.fill()
}
base.draw(in: rect, from: .zero, operation: compositingOperation, fraction: alpha)
return false
}
}
#endif
Expand Down Expand Up @@ -140,7 +142,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
#else
guard let context = UIGraphicsGetCurrentContext() else {
assertionFailure("[Kingfisher] Failed to create CG context for image.")
return
return false
}

if let backgroundColor = backgroundColor {
Expand All @@ -158,6 +160,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
context.clip()
base.draw(in: rect)
#endif
return false
}
}

Expand Down Expand Up @@ -194,6 +197,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
#else
base.draw(in: rect)
#endif
return false
}
}

Expand Down Expand Up @@ -364,6 +368,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
base.draw(in: rect, blendMode: .sourceAtop, alpha: fraction)
}
#endif
return false
}
}

Expand Down Expand Up @@ -450,6 +455,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
let size = CGSize(width: CGFloat(imageRef.width) / scale, height: CGFloat(imageRef.height) / scale)
return draw(to: size, inverting: true, scale: scale) { context in
context.draw(imageRef, in: CGRect(origin: .zero, size: size))
return true
}
}
}
Expand Down Expand Up @@ -501,18 +507,26 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
#endif
}

func draw(to size: CGSize, inverting: Bool = false, scale: CGFloat? = nil, refImage: KFCrossPlatformImage? = nil, draw: (CGContext) -> Void) -> KFCrossPlatformImage {
func draw(
to size: CGSize,
inverting: Bool = false,
scale: CGFloat? = nil,
refImage: KFCrossPlatformImage? = nil,
draw: (CGContext) -> Bool // Whether use the refImage (`true`) or ignore image orientation (`false`)
) -> KFCrossPlatformImage
{
let targetScale = scale ?? self.scale
guard let context = beginContext(size: size, scale: targetScale, inverting: inverting) else {
assertionFailure("[Kingfisher] Failed to create CG context for blurring image.")
return base
}
defer { endContext() }
draw(context)
let useRefImage = draw(context)
guard let cgImage = context.makeImage() else {
return base
}
return KingfisherWrapper.image(cgImage: cgImage, scale: targetScale, refImage: refImage ?? base)
let ref = useRefImage ? (refImage ?? base) : nil
return KingfisherWrapper.image(cgImage: cgImage, scale: targetScale, refImage: ref)
}

#if os(macOS)
Expand All @@ -523,6 +537,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {

return draw(to: self.size) { context in
image.draw(in: rect, from: .zero, operation: .copy, fraction: 1.0)
return false
}
}
#endif
Expand Down

0 comments on commit 1eee4a3

Please sign in to comment.