mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Hashtag search improvements
This commit is contained in:
@@ -544,59 +544,3 @@ extension CATransform3D {
|
||||
return (t, r, s)
|
||||
}
|
||||
}
|
||||
|
||||
public extension UIImage {
|
||||
class func animatedImageFromData(data: Data) -> DrawingAnimatedImage? {
|
||||
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let count = CGImageSourceGetCount(source)
|
||||
var images = [UIImage]()
|
||||
var duration = 0.0
|
||||
|
||||
for i in 0..<count {
|
||||
if let cgImage = CGImageSourceCreateImageAtIndex(source, i, nil) {
|
||||
let image = UIImage(cgImage: cgImage)
|
||||
images.append(image)
|
||||
|
||||
let delaySeconds = UIImage.delayForImageAtIndex(Int(i),
|
||||
source: source)
|
||||
duration += delaySeconds
|
||||
}
|
||||
}
|
||||
|
||||
return DrawingAnimatedImage(images: images, duration: duration)
|
||||
}
|
||||
|
||||
class func delayForImageAtIndex(_ index: Int, source: CGImageSource!) -> Double {
|
||||
var delay = 0.0
|
||||
|
||||
let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil)
|
||||
let gifPropertiesPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 0)
|
||||
if CFDictionaryGetValueIfPresent(cfProperties, Unmanaged.passUnretained(kCGImagePropertyGIFDictionary).toOpaque(), gifPropertiesPointer) == false {
|
||||
return delay
|
||||
}
|
||||
|
||||
let gifProperties:CFDictionary = unsafeBitCast(gifPropertiesPointer.pointee, to: CFDictionary.self)
|
||||
|
||||
var delayObject: AnyObject = unsafeBitCast(CFDictionaryGetValue(gifProperties, Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()), to: AnyObject.self)
|
||||
if delayObject.doubleValue == 0 {
|
||||
delayObject = unsafeBitCast(CFDictionaryGetValue(gifProperties, Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
|
||||
}
|
||||
|
||||
delay = delayObject as? Double ?? 0
|
||||
|
||||
return delay
|
||||
}
|
||||
}
|
||||
|
||||
public final class DrawingAnimatedImage {
|
||||
public let images: [UIImage]
|
||||
public let duration: Double
|
||||
|
||||
init(images: [UIImage], duration: Double) {
|
||||
self.images = images
|
||||
self.duration = duration
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user