Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Oct 15, 2024
2 parents 1924151 + bb70754 commit e25f473
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

<ImageView
android:id="@+id/imageView"
android:background="#FFFF00"
android:layout_width="250dp"
android:layout_height="250dp"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public class AnimatedAvifDecoder(
),
preheatFrames = preheatFrames,
firstFrameAsPlaceholder = true
)
).apply {
setBounds(0, 0, dstWidth, dstHeight)
}
} else {
BitmapDrawable(
options.context.resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,39 +77,27 @@ public class AnimatedDrawable(

private val measuredTimesStore = mutableListOf<Int>()

private var shouldClearCache = frameStore.framesCount > preheatFrames

private fun makeDecodingRunner(
nextFrameIndex: Int
): Runnable = DecodeFrameRunnable(
syncedFrames = syncedFrames,
frameStore = frameStore,
lock = lock,
nextFrameIndex = nextFrameIndex,
measuredTimesStore = measuredTimesStore,
preheatFrames = preheatFrames,
shouldClearCache = shouldClearCache
measuredTimesStore = measuredTimesStore
)

private class DecodeFrameRunnable(
private val syncedFrames: MutableList<SyncedFrame>,
private val frameStore: AnimatedFrameStore,
private val lock: Any,
private val nextFrameIndex: Int,
private val measuredTimesStore: MutableList<Int>,
private val preheatFrames: Int,
private val shouldClearCache: Boolean
private val measuredTimesStore: MutableList<Int>
) : 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) {
Expand Down Expand Up @@ -226,15 +213,13 @@ public class AnimatedDrawable(
mHandlerThread.post(preheatRunnable)
}

private val matrix = Matrix()
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)

private val rect = Rect()

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)
}
Expand All @@ -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?) {
Expand Down

0 comments on commit e25f473

Please sign in to comment.