Fix bytesPerRow

This commit is contained in:
Ali 2021-11-05 17:36:45 +04:00
parent 3989b4887d
commit 37148c70d4
2 changed files with 5 additions and 1 deletions

View File

@ -81,6 +81,7 @@ public final class AnimatedStickerFrame {
self.type = type self.type = type
self.width = width self.width = width
self.height = height self.height = height
assert(bytesPerRow > 0)
self.bytesPerRow = bytesPerRow self.bytesPerRow = bytesPerRow
self.index = index self.index = index
self.isLastFrame = isLastFrame self.isLastFrame = isLastFrame
@ -687,7 +688,7 @@ private final class AnimatedStickerDirectFrameSource: AnimatedStickerFrameSource
self.currentFrame += 1 self.currentFrame += 1
if draw { if draw {
if let cache = self.cache, let yuvData = cache.readUncompressedYuvFrame(index: frameIndex) { if let cache = self.cache, let yuvData = cache.readUncompressedYuvFrame(index: frameIndex) {
return AnimatedStickerFrame(data: yuvData, type: .yuva, width: self.width, height: self.height, bytesPerRow: 0, index: frameIndex, isLastFrame: frameIndex == self.frameCount - 1, totalFrames: self.frameCount) 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 { } else {
var frameData = Data(count: self.bytesPerRow * self.height) var frameData = Data(count: self.bytesPerRow * self.height)
frameData.withUnsafeMutableBytes { buffer -> Void in frameData.withUnsafeMutableBytes { buffer -> Void in
@ -1135,6 +1136,8 @@ public final class AnimatedStickerNode: ASDisplayNode {
return return
} }
assert(frame.bytesPerRow != 0)
strongSelf.renderer?.render(queue: strongSelf.queue, width: frame.width, height: frame.height, bytesPerRow: frame.bytesPerRow, data: frame.data, type: frame.type, completion: { strongSelf.renderer?.render(queue: strongSelf.queue, width: frame.width, height: frame.height, bytesPerRow: frame.bytesPerRow, data: frame.data, type: frame.type, completion: {
guard let strongSelf = self else { guard let strongSelf = self else {
return return

View File

@ -10,6 +10,7 @@ final class SoftwareAnimationRenderer: ASDisplayNode, AnimationRenderer {
private var highlightedColor: UIColor? private var highlightedColor: UIColor?
func render(queue: Queue, width: Int, height: Int, bytesPerRow: Int, data: Data, type: AnimationRendererFrameType, completion: @escaping () -> Void) { func render(queue: Queue, width: Int, height: Int, bytesPerRow: Int, data: Data, type: AnimationRendererFrameType, completion: @escaping () -> Void) {
assert(bytesPerRow > 0)
queue.async { [weak self] in queue.async { [weak self] in
switch type { switch type {
case .argb: case .argb: