a75c6 / JWAnimatedImage

A animated GIF&APNG engine for iOS in Swift. Optimized for Multi-Image case.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cover Language Build Status CocoaPods Compatible Carthage compatible Pod License

An animated GIF&APNG engine for iOS in Swift with low memory & cpu usage.

video

##Features

  • Add APNG support.[NEW]
  • Using asynchronous image decoding to reduce the main thread CPU usage.
  • Optimized for Multi-Image case.
  • As UIImage and UIImageView extension,easy to use.
  • Have a great performance on memory usage by using producer/consumer pattern.
  • Have a great performance on CPU usage by using asynchronous loading.
  • Allow to control display quality by using factor 'level of Integrity'
  • Allow to control memory usage by using factor 'memoryLimit'

##Installation ######With CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'JWAnimatedImage'

######With Carthage

github "wangjwchn/JWAnimatedImage"

##How to Use

let manager = JWAnimationManager(memoryLimit:20)
        
let url = NSBundle.mainBundle().URLForResource(“imagename”, withExtension: "gif")!
let imageData = NSData(contentsOfURL:url)
        
let image = UIImage(animatedImage:imageData!)
let imageview = UIImageView(animatedImage: image, manager:manager,loopTime: -1)
imageview.frame = CGRect(x: 7.0, y: 50.0, width: 400.0, height: 224.0)
view.addSubview(imageview)

##Benchmark ###Display GIF:Compared with FLAnimatedImage #####1.Display 1 Image

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 6% ~ 14% [8%] 7.5 ~ 8.4 [8.2]
FLAnimatedImage 8% ~ 24% [11%] 7.3 ~ ??? [???]

#####2.Display 3 Images

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 31% ~ 44% [38%] 12.4 ~ 13.4 [12.9]
FLAnimatedImage 36% ~ 62% [54%] 11.0 ~ 12.4 [11.3]

#####3.Display 30 Images

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage 38% ~ 81% [53%] 59.3 ~ 82.4 [63.3]
FLAnimatedImage 126% ~ 185% [143%] 58.4 ~ 98.9 [74.2]

###Display APNG:Compared with APNGKit

#####1.Display 1 Image

CPU Usage[average] Memory Usage[average]/MB
JWAnimatedImage (Cache) 2% ~ 44% [3%] 43.2 ~ 43.2 [43.2]
JWAnimatedImage (noCache) 20% ~ 49% [33%] 6.6 ~ 8.3 [7.5]
APNGKit (Cache) 1% ~ 42% [1%] 95.6 ~ 95.6 [95.6]
APNGKit (noCache) 1% ~ 26% [1%] 95.9 ~ 95.9 [95.9]

Measurement Factors:

  • Last updated: April 26, 2016

  • Measurement device: iPhone6 with iOS 9.3

  • Measurement tool: Profile in Xcode 7.3

  • Measurement image: See it in repository, all the parameters are default.

  • Raw data are here.

##Architecture Architecture

####UIImageView State:

LifeCycle

JWAnimationManager:

Inital class 'JWAnimationManager' with memory limit. JWAnimationManager will manage all the GIF image views in it.

CheckForCache:

When adding a new GIF image view to 'JWAnimationManager',it estimate memory usage of new GIF,and add to 'totalGifSize' as a new valuation.When new valuation is greater than memory limit, JWAnimationManager changes all GIF image views to no-cache mode.

#####ImageView's life cycle: ImageView will be suspended if function 'isDisplayedInScreen' returns false. ImageView will be deleted from 'JWAnimationManager' if function 'isDiscarded' returns false.

##Licence JWAnimatedImage is released under the MIT license. See LICENSE for details.

About

A animated GIF&APNG engine for iOS in Swift. Optimized for Multi-Image case.

License:MIT License


Languages

Language:Swift 97.5%Language:Ruby 2.5%