Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix processor and redraw orientation #1358

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
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
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