Files
Pocket-Poster/Pocket Poster/Packages/GIFImage/Sources/extension/CGImageSource+GIFImage.swift
T
2025-07-19 08:58:08 -04:00

40 lines
1.1 KiB
Swift

//
// File.swift
//
//
// Created by Igor Ferreira on 05/04/2022.
//
import Foundation
import ImageIO
extension CGImageSource {
func intervalAtIndex(_ index: Int) -> TimeInterval? {
guard let properties = CGImageSourceCopyPropertiesAtIndex(self, index, nil) else {
return nil
}
guard let gifProperties = CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary.asKey) else {
return nil
}
let dictionary = unsafeBitCast(gifProperties, to: CFDictionary.self)
let pointer: UnsafeRawPointer
if let delay = CFDictionaryGetValue(dictionary, kCGImagePropertyGIFDelayTime.asKey) {
pointer = delay
} else if let unclampedDelay = CFDictionaryGetValue(dictionary, kCGImagePropertyGIFUnclampedDelayTime.asKey) {
pointer = unclampedDelay
} else {
return nil
}
let interval = unsafeBitCast(pointer, to: AnyObject.self).doubleValue ?? 0.0
if interval > 0.0 {
return interval
} else {
return nil
}
}
}