|
@@ -63,6 +63,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
base.draw(in: rect, blendMode: blendMode, alpha: alpha)
|
|
base.draw(in: rect, blendMode: blendMode, alpha: alpha)
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -94,6 +95,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
rect.fill()
|
|
rect.fill()
|
|
|
}
|
|
}
|
|
|
base.draw(in: rect, from: .zero, operation: compositingOperation, fraction: alpha)
|
|
base.draw(in: rect, from: .zero, operation: compositingOperation, fraction: alpha)
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -140,7 +142,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
#else
|
|
#else
|
|
|
guard let context = UIGraphicsGetCurrentContext() else {
|
|
guard let context = UIGraphicsGetCurrentContext() else {
|
|
|
assertionFailure("[Kingfisher] Failed to create CG context for image.")
|
|
assertionFailure("[Kingfisher] Failed to create CG context for image.")
|
|
|
- return
|
|
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if let backgroundColor = backgroundColor {
|
|
if let backgroundColor = backgroundColor {
|
|
@@ -158,6 +160,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
context.clip()
|
|
context.clip()
|
|
|
base.draw(in: rect)
|
|
base.draw(in: rect)
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -194,6 +197,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
#else
|
|
#else
|
|
|
base.draw(in: rect)
|
|
base.draw(in: rect)
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -364,6 +368,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
base.draw(in: rect, blendMode: .sourceAtop, alpha: fraction)
|
|
base.draw(in: rect, blendMode: .sourceAtop, alpha: fraction)
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -450,6 +455,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
let size = CGSize(width: CGFloat(imageRef.width) / scale, height: CGFloat(imageRef.height) / scale)
|
|
let size = CGSize(width: CGFloat(imageRef.width) / scale, height: CGFloat(imageRef.height) / scale)
|
|
|
return draw(to: size, inverting: true, scale: scale) { context in
|
|
return draw(to: size, inverting: true, scale: scale) { context in
|
|
|
context.draw(imageRef, in: CGRect(origin: .zero, size: size))
|
|
context.draw(imageRef, in: CGRect(origin: .zero, size: size))
|
|
|
|
|
+ return true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -501,18 +507,26 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
#endif
|
|
#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
|
|
let targetScale = scale ?? self.scale
|
|
|
guard let context = beginContext(size: size, scale: targetScale, inverting: inverting) else {
|
|
guard let context = beginContext(size: size, scale: targetScale, inverting: inverting) else {
|
|
|
assertionFailure("[Kingfisher] Failed to create CG context for blurring image.")
|
|
assertionFailure("[Kingfisher] Failed to create CG context for blurring image.")
|
|
|
return base
|
|
return base
|
|
|
}
|
|
}
|
|
|
defer { endContext() }
|
|
defer { endContext() }
|
|
|
- draw(context)
|
|
|
|
|
|
|
+ let useRefImage = draw(context)
|
|
|
guard let cgImage = context.makeImage() else {
|
|
guard let cgImage = context.makeImage() else {
|
|
|
return base
|
|
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)
|
|
#if os(macOS)
|
|
@@ -523,6 +537,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
|
|
|
|
|
|
|
|
return draw(to: self.size) { context in
|
|
return draw(to: self.size) { context in
|
|
|
image.draw(in: rect, from: .zero, operation: .copy, fraction: 1.0)
|
|
image.draw(in: rect, from: .zero, operation: .copy, fraction: 1.0)
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|