Bladeren bron

Calculate Image cost accounting for number of image frames

When we calculate the Image cost for cache purposes, we should take into account how many frames make up the Image to get an accurate cost.
Aron Springfield 4 jaren geleden
bovenliggende
commit
592b9c9f50
1 gewijzigde bestanden met toevoegingen van 5 en 1 verwijderingen
  1. 5 1
      Sources/Image/Image.swift

+ 5 - 1
Sources/Image/Image.swift

@@ -103,7 +103,11 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
         guard let cgImage = cgImage else {
             return pixel * 4
         }
-        return pixel * cgImage.bitsPerPixel / 8
+        let bytesPerPixel = cgImage.bitsPerPixel / 8
+        guard let imageCount = images?.count else {
+            return pixel * bytesPerPixel
+        }
+        return pixel * bytesPerPixel * imageCount
     }
 }