mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Emoji status and reaction improvements
This commit is contained in:
@@ -7,6 +7,7 @@ import CoreMedia
|
||||
import ManagedFile
|
||||
import Accelerate
|
||||
import TelegramCore
|
||||
import WebPBinding
|
||||
|
||||
private let sharedStoreQueue = Queue.concurrentDefaultQueue()
|
||||
|
||||
@@ -282,6 +283,7 @@ final class VideoStickerDirectFrameSource: AnimatedStickerFrameSource {
|
||||
private let width: Int
|
||||
private let height: Int
|
||||
private let cache: VideoStickerFrameSourceCache?
|
||||
private let image: UIImage?
|
||||
private let bytesPerRow: Int
|
||||
var frameCount: Int
|
||||
let frameRate: Int
|
||||
@@ -290,7 +292,11 @@ final class VideoStickerDirectFrameSource: AnimatedStickerFrameSource {
|
||||
private let source: SoftwareVideoSource?
|
||||
|
||||
var frameIndex: Int {
|
||||
return self.currentFrame % self.frameCount
|
||||
if self.frameCount == 0 {
|
||||
return 0
|
||||
} else {
|
||||
return self.currentFrame % self.frameCount
|
||||
}
|
||||
}
|
||||
|
||||
init?(queue: Queue, path: String, width: Int, height: Int, cachePathPrefix: String?, unpremultiplyAlpha: Bool = true) {
|
||||
@@ -307,11 +313,18 @@ final class VideoStickerDirectFrameSource: AnimatedStickerFrameSource {
|
||||
|
||||
if useCache, let cache = self.cache, cache.frameCount > 0 {
|
||||
self.source = nil
|
||||
self.image = nil
|
||||
self.frameRate = Int(cache.frameRate)
|
||||
self.frameCount = Int(cache.frameCount)
|
||||
} else if let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let image = WebP.convert(fromWebP: data) {
|
||||
self.source = nil
|
||||
self.image = image
|
||||
self.frameRate = 1
|
||||
self.frameCount = 1
|
||||
} else {
|
||||
let source = SoftwareVideoSource(path: path, hintVP9: true, unpremultiplyAlpha: unpremultiplyAlpha)
|
||||
self.source = source
|
||||
self.image = nil
|
||||
self.frameRate = min(30, source.getFramerate())
|
||||
self.frameCount = 0
|
||||
}
|
||||
@@ -331,7 +344,15 @@ final class VideoStickerDirectFrameSource: AnimatedStickerFrameSource {
|
||||
|
||||
self.currentFrame += 1
|
||||
if draw {
|
||||
if useCache, let cache = self.cache, let yuvData = cache.readUncompressedYuvaFrame(index: frameIndex) {
|
||||
if let image = self.image {
|
||||
let context = DrawingContext(size: CGSize(width: self.width, height: self.height), scale: 1.0, opaque: false, clear: true, bytesPerRow: self.bytesPerRow)
|
||||
context.withFlippedContext { c in
|
||||
c.draw(image.cgImage!, in: CGRect(origin: CGPoint(), size: context.size))
|
||||
}
|
||||
let frameData = Data(bytes: context.bytes, count: self.bytesPerRow * self.height)
|
||||
|
||||
return AnimatedStickerFrame(data: frameData, type: .argb, width: self.width, height: self.height, bytesPerRow: self.bytesPerRow, index: frameIndex, isLastFrame: frameIndex == self.frameCount - 1, totalFrames: self.frameCount, multiplyAlpha: true)
|
||||
} else if useCache, let cache = self.cache, let yuvData = cache.readUncompressedYuvaFrame(index: frameIndex) {
|
||||
return AnimatedStickerFrame(data: yuvData, type: .yuva, width: self.width, height: self.height, bytesPerRow: self.width * 2, index: frameIndex, isLastFrame: frameIndex == self.frameCount - 1, totalFrames: self.frameCount)
|
||||
} else if let source = self.source {
|
||||
let frameAndLoop = source.readFrame(maxPts: nil)
|
||||
|
||||
Reference in New Issue
Block a user