mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
35 lines
1.2 KiB
Swift
35 lines
1.2 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import AnimationCache
|
|
import Display
|
|
import RLottieBinding
|
|
import GZip
|
|
|
|
public func cacheLottieAnimation(data: Data, width: Int, height: Int, writer: AnimationCacheItemWriter) {
|
|
writer.queue.async {
|
|
let decompressedData = TGGUnzipData(data, 1 * 1024 * 1024) ?? data
|
|
guard let animation = LottieInstance(data: decompressedData, fitzModifier: .none, colorReplacements: nil, cacheKey: "") else {
|
|
writer.finish()
|
|
return
|
|
}
|
|
|
|
let frameDuration = 1.0 / Double(animation.frameRate)
|
|
for i in 0 ..< animation.frameCount {
|
|
if writer.isCancelled {
|
|
break
|
|
}
|
|
writer.add(with: { surface in
|
|
animation.renderFrame(with: i, into: surface.argb, width: Int32(surface.width), height: Int32(surface.height), bytesPerRow: Int32(surface.bytesPerRow))
|
|
}, proposedWidth: width, proposedHeight: height, duration: frameDuration)
|
|
}
|
|
|
|
writer.finish()
|
|
}
|
|
}
|
|
|
|
public func cacheStillSticker(path: String, width: Int, height: Int, writer: AnimationCacheItemWriter) {
|
|
writer.queue.async {
|
|
writer.finish()
|
|
}
|
|
}
|