From 0f87ece3491de69ce1b8301c161b57442f4ec271 Mon Sep 17 00:00:00 2001 From: T8RIN Date: Tue, 15 Oct 2024 01:42:16 +0300 Subject: [PATCH 1/2] - --- app/src/main/res/layout/activity_main.xml | 3 ++- .../decoder/animation/AnimatedAvifDecoder.kt | 8 ++++--- .../decoder/animation/AnimatedDrawable.kt | 23 ++++--------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bb68bbb..c0a3a78 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,9 +18,10 @@ ScaleMode.FILL Scale.FIT -> ScaleMode.FIT @@ -123,7 +123,9 @@ public class AnimatedAvifDecoder( ), preheatFrames = preheatFrames, firstFrameAsPlaceholder = true - ) + ).apply { + setBounds(0, 0, dstWidth, dstHeight) + } } else { BitmapDrawable( options.context.resources, diff --git a/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedDrawable.kt b/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedDrawable.kt index 45297c6..ad1f426 100644 --- a/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedDrawable.kt +++ b/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedDrawable.kt @@ -31,7 +31,6 @@ package com.github.awxkee.avifcoil.decoder.animation import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.ColorFilter -import android.graphics.Matrix import android.graphics.Paint import android.graphics.Rect import android.graphics.drawable.Animatable @@ -78,8 +77,6 @@ public class AnimatedDrawable( private val measuredTimesStore = mutableListOf() - private var shouldClearCache = frameStore.framesCount > preheatFrames - private fun makeDecodingRunner( nextFrameIndex: Int ): Runnable = DecodeFrameRunnable( @@ -87,9 +84,7 @@ public class AnimatedDrawable( frameStore = frameStore, lock = lock, nextFrameIndex = nextFrameIndex, - measuredTimesStore = measuredTimesStore, - preheatFrames = preheatFrames, - shouldClearCache = shouldClearCache + measuredTimesStore = measuredTimesStore ) private class DecodeFrameRunnable( @@ -97,20 +92,12 @@ public class AnimatedDrawable( private val frameStore: AnimatedFrameStore, private val lock: Any, private val nextFrameIndex: Int, - private val measuredTimesStore: MutableList, - private val preheatFrames: Int, - private val shouldClearCache: Boolean + private val measuredTimesStore: MutableList ) : Runnable { override fun run() { val measureTime = measureTimeMillis { val syncedNextFrame = syncedFrames.firstOrNull { it.frameIndex == nextFrameIndex } if (syncedNextFrame == null) { - if (shouldClearCache) { - val firstFromNext = nextFrameIndex - preheatFrames - if (syncedFrames.firstOrNull { it.frameIndex == firstFromNext } != null) { - syncedFrames.removeIf { it.frameIndex == firstFromNext } - } - } val nextFrame = frameStore.getFrame(nextFrameIndex) val nextFrameDuration = frameStore.getFrameDuration(nextFrameIndex) synchronized(lock) { @@ -226,7 +213,6 @@ public class AnimatedDrawable( mHandlerThread.post(preheatRunnable) } - private val matrix = Matrix() private val paint = Paint(Paint.ANTI_ALIAS_FLAG) private val rect = Rect() @@ -234,7 +220,6 @@ public class AnimatedDrawable( override fun draw(canvas: Canvas) { val bmp = currentBitmap if (bmp != null) { - matrix.reset() rect.set(0, 0, bmp.width, bmp.height) canvas.drawBitmap(bmp, rect, bounds, paint) } @@ -245,11 +230,11 @@ public class AnimatedDrawable( } override fun getIntrinsicHeight(): Int { - return frameStore.height + return bounds.height() } override fun getIntrinsicWidth(): Int { - return frameStore.width + return bounds.width() } override fun setColorFilter(colorFilter: ColorFilter?) { From b75237bff6ea708ead532cd2d9452eaf6c12f4c6 Mon Sep 17 00:00:00 2001 From: T8RIN Date: Tue, 15 Oct 2024 01:45:22 +0300 Subject: [PATCH 2/2] remove /2 --- .../awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt b/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt index bea5371..c1458e9 100644 --- a/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt +++ b/avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt @@ -83,8 +83,8 @@ public class AnimatedAvifDecoder( ) } - val dstWidth = options.size.width.pxOrElse { 0 } / 2 - val dstHeight = options.size.height.pxOrElse { 0 } / 2 + val dstWidth = options.size.width.pxOrElse { 0 } + val dstHeight = options.size.height.pxOrElse { 0 } val scaleMode = when (options.scale) { Scale.FILL -> ScaleMode.FILL Scale.FIT -> ScaleMode.FIT