Sfoglia il codice sorgente

New blur support for macOS

onevcat 1 anno fa
parent
commit
14a28029cb
1 ha cambiato i file con 12 aggiunte e 3 eliminazioni
  1. 12 3
      Sources/Image/ImageDrawing.swift

+ 12 - 3
Sources/Image/ImageDrawing.swift

@@ -344,7 +344,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
             // Next inBuffer should be the outButter of current iteration
             // Next inBuffer should be the outButter of current iteration
             (inBuffer, outBuffer) = (outBuffer, inBuffer)
             (inBuffer, outBuffer) = (outBuffer, inBuffer)
         }
         }
-        let outContext = CGContext(
+        guard let outContext = CGContext(
             data: outBuffer.data,
             data: outBuffer.data,
             width: Int(outBuffer.width),
             width: Int(outBuffer.width),
             height: Int(outBuffer.height),
             height: Int(outBuffer.height),
@@ -352,10 +352,19 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
             bytesPerRow: outBuffer.rowBytes,
             bytesPerRow: outBuffer.rowBytes,
             space: colorSpace,
             space: colorSpace,
             bitmapInfo: cgImage.bitmapInfo.rawValue
             bitmapInfo: cgImage.bitmapInfo.rawValue
-        )
-        let result = outContext?.makeImage().flatMap {
+        ) else {
+            assertionFailure("[Kingfisher] Creating CG context failed.")
+            return base
+        }
+        #if os(macOS)
+        let result = outContext.makeImage().flatMap {
+            fixedForRetinaPixel(cgImage: $0, to: size)
+        }
+        #else
+        let result = outContext.makeImage().flatMap {
             KFCrossPlatformImage(cgImage: $0, scale: base.scale, orientation: base.imageOrientation)
             KFCrossPlatformImage(cgImage: $0, scale: base.scale, orientation: base.imageOrientation)
         }
         }
+        #endif
         guard let blurredImage = result else {
         guard let blurredImage = result else {
             return base
             return base
         }
         }