onevcat пре 9 година
родитељ
комит
b3bba01920
1 измењених фајлова са 3 додато и 48 уклоњено
  1. 3 48
      Sources/Image.swift

+ 3 - 48
Sources/Image.swift

@@ -600,13 +600,13 @@ extension Kingfisher where Base: Image {
             return base
             return base
         }
         }
         let colorSpace = CGColorSpaceCreateDeviceRGB()
         let colorSpace = CGColorSpaceCreateDeviceRGB()
-        let bitmapInfo = imageRef.bitmapInfo.fixed
-        
-        guard let context = CGContext(data: nil, width: imageRef.width, height: imageRef.height, bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue) else {
+        guard let context = beginContext() else {
             assertionFailure("[Kingfisher] Decoding fails to create a valid context.")
             assertionFailure("[Kingfisher] Decoding fails to create a valid context.")
             return base
             return base
         }
         }
         
         
+        defer { endContext() }
+        
         let rect = CGRect(x: 0, y: 0, width: imageRef.width, height: imageRef.height)
         let rect = CGRect(x: 0, y: 0, width: imageRef.width, height: imageRef.height)
         context.draw(imageRef, in: rect)
         context.draw(imageRef, in: rect)
         let decompressedImageRef = context.makeImage()
         let decompressedImageRef = context.makeImage()
@@ -706,21 +706,6 @@ extension CGSizeProxy {
     }
     }
 }
 }
 
 
-extension CGBitmapInfo {
-    var fixed: CGBitmapInfo {
-        var fixed = self
-        let alpha = (rawValue & CGBitmapInfo.alphaInfoMask.rawValue)
-        if alpha == CGImageAlphaInfo.none.rawValue {
-            fixed.remove(.alphaInfoMask)
-            fixed = CGBitmapInfo(rawValue: fixed.rawValue | CGImageAlphaInfo.noneSkipFirst.rawValue)
-        } else if !(alpha == CGImageAlphaInfo.noneSkipFirst.rawValue) || !(alpha == CGImageAlphaInfo.noneSkipLast.rawValue) {
-            fixed.remove(.alphaInfoMask)
-            fixed = CGBitmapInfo(rawValue: fixed.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue)
-        }
-        return fixed
-    }
-}
-
 extension Kingfisher where Base: Image {
 extension Kingfisher where Base: Image {
     
     
     func beginContext() -> CGContext? {
     func beginContext() -> CGContext? {
@@ -815,36 +800,6 @@ extension Kingfisher where Base: Image {
     #endif
     #endif
 }
 }
 
 
-
-extension CGContext {
-    static func createARGBContext(from imageRef: CGImage) -> CGContext? {
-        
-        let w = imageRef.width
-        let h = imageRef.height
-        let bytesPerRow = w * 4
-        let colorSpace = CGColorSpaceCreateDeviceRGB()
-        
-        let data = malloc(bytesPerRow * h)
-        defer {
-            free(data)
-        }
-        
-        let bitmapInfo = imageRef.bitmapInfo.fixed
-        
-        // Create the bitmap context. We want pre-multiplied ARGB, 8-bits
-        // per component. Regardless of what the source image format is
-        // (CMYK, Grayscale, and so on) it will be converted over to the format
-        // specified here.
-        return CGContext(data: data,
-                         width: w,
-                         height: h,
-                         bitsPerComponent: imageRef.bitsPerComponent,
-                         bytesPerRow: bytesPerRow,
-                         space: colorSpace,
-                         bitmapInfo: bitmapInfo.rawValue)
-    }
-}
-
 extension Double {
 extension Double {
     var isEven: Bool {
     var isEven: Bool {
         return truncatingRemainder(dividingBy: 2.0) == 0
         return truncatingRemainder(dividingBy: 2.0) == 0