Skip to content

Commit

Permalink
Merge pull request onevcat#461 from onevcat/fix/remove-cgimage-fix
Browse files Browse the repository at this point in the history
CGImage fix seems not necessary
  • Loading branch information
onevcat authored Sep 28, 2016
2 parents 9bd765c + b61cb6c commit fc99c94
Showing 1 changed file with 2 additions and 25 deletions.
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

0 comments on commit fc99c94

Please sign in to comment.