Created
November 17, 2019 21:27
-
-
Save dmytro-anokhin/d0c1d266cf405d85a18273ec72bd3315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func frameDuration(at index: Int) -> TimeInterval? { | |
| guard let frameProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, index, imageSourceOptions()) as? [CFString: Any] else { | |
| return nil | |
| } | |
| var animationProperties = ImageDecoder.animationProperties(from: frameProperties) | |
| if animationProperties == nil { | |
| if let properties = CGImageSourceCopyProperties(imageSource, imageSourceOptions()) as? [CFString: Any] { | |
| animationProperties = ImageDecoder.animationHEICSProperties(from: properties, at: index) | |
| } | |
| } | |
| let duration: TimeInterval | |
| // Use the unclamped frame delay if it exists. Otherwise use the clamped frame delay. | |
| if let unclampedDelay = animationProperties?["UnclampedDelayTime" as CFString] as? TimeInterval { | |
| duration = unclampedDelay | |
| } | |
| else if let delay = animationProperties?["DelayTime" as CFString] as? TimeInterval { | |
| duration = delay | |
| } | |
| else { | |
| duration = 0.0 | |
| } | |
| // WebCore won't allow frame duration faster than 10ms. | |
| return duration < 0.011 ? 0.1 : duration | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment