Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created November 17, 2019 21:27
Show Gist options
  • Select an option

  • Save dmytro-anokhin/d0c1d266cf405d85a18273ec72bd3315 to your computer and use it in GitHub Desktop.

Select an option

Save dmytro-anokhin/d0c1d266cf405d85a18273ec72bd3315 to your computer and use it in GitHub Desktop.
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