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

CGImage fix seems not necessary #461

Merged
merged 1 commit into from
Sep 28, 2016
Merged
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
27 changes: 2 additions & 25 deletions Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ extension Kingfisher where Base: Image {
/// - Note: This method only works for CG-based image.
public func resize(to size: CGSize) -> Image {

guard let cgImage = cgImage?.fixed else {
guard let cgImage = cgImage else {
assertionFailure("[Kingfisher] Resize only works for CG-based image.")
return base
}
Expand Down Expand Up @@ -537,7 +537,7 @@ extension Kingfisher where Base: Image {
/// - Note: This method only works for CG-based image.
public func overlaying(with color: Color, fraction: CGFloat) -> Image {

guard let cgImage = cgImage?.fixed else {
guard let cgImage = cgImage else {
assertionFailure("[Kingfisher] Overlaying only works for CG-based image.")
return base
}
Expand Down Expand Up @@ -721,29 +721,6 @@ extension CGSizeProxy {
}
}


extension CGImage {
var isARGB8888: Bool {
return bitsPerPixel == 32 && bitsPerComponent == 8 && bitmapInfo.contains(.alphaInfoMask)
}

var fixed: CGImage {
if isARGB8888 { return self }

// Convert to ARGB if it isn't
guard let context = CGContext.createARGBContext(from: self) else {
assertionFailure("[Kingfisher] Failed to create CG context when converting non ARGB image.")
return self
}
context.draw(self, in: CGRect(x: 0, y: 0, width: width, height: height))
guard let r = context.makeImage() else {
assertionFailure("[Kingfisher] Failed to create CG image when converting non ARGB image.")
return self
}
return r
}
}

extension CGBitmapInfo {
var fixed: CGBitmapInfo {
var fixed = self
Expand Down