Skip to content

Commit 0f87ece

Browse files
committed
-
1 parent d1baf10 commit 0f87ece

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
<ImageView
2020
android:id="@+id/imageView"
21+
android:background="#FFFF00"
2122
android:layout_width="250dp"
2223
android:layout_height="250dp"
23-
android:scaleType="fitCenter"
24+
android:scaleType="centerCrop"
2425
app:layout_constraintBottom_toBottomOf="parent"
2526
app:layout_constraintEnd_toEndOf="parent"
2627
app:layout_constraintStart_toStartOf="parent"

avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedAvifDecoder.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public class AnimatedAvifDecoder(
8383
)
8484
}
8585

86-
val dstWidth = options.size.width.pxOrElse { 0 }
87-
val dstHeight = options.size.height.pxOrElse { 0 }
86+
val dstWidth = options.size.width.pxOrElse { 0 } / 2
87+
val dstHeight = options.size.height.pxOrElse { 0 } / 2
8888
val scaleMode = when (options.scale) {
8989
Scale.FILL -> ScaleMode.FILL
9090
Scale.FIT -> ScaleMode.FIT
@@ -123,7 +123,9 @@ public class AnimatedAvifDecoder(
123123
),
124124
preheatFrames = preheatFrames,
125125
firstFrameAsPlaceholder = true
126-
)
126+
).apply {
127+
setBounds(0, 0, dstWidth, dstHeight)
128+
}
127129
} else {
128130
BitmapDrawable(
129131
options.context.resources,

avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/animation/AnimatedDrawable.kt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ package com.github.awxkee.avifcoil.decoder.animation
3131
import android.graphics.Bitmap
3232
import android.graphics.Canvas
3333
import android.graphics.ColorFilter
34-
import android.graphics.Matrix
3534
import android.graphics.Paint
3635
import android.graphics.Rect
3736
import android.graphics.drawable.Animatable
@@ -78,39 +77,27 @@ public class AnimatedDrawable(
7877

7978
private val measuredTimesStore = mutableListOf<Int>()
8079

81-
private var shouldClearCache = frameStore.framesCount > preheatFrames
82-
8380
private fun makeDecodingRunner(
8481
nextFrameIndex: Int
8582
): Runnable = DecodeFrameRunnable(
8683
syncedFrames = syncedFrames,
8784
frameStore = frameStore,
8885
lock = lock,
8986
nextFrameIndex = nextFrameIndex,
90-
measuredTimesStore = measuredTimesStore,
91-
preheatFrames = preheatFrames,
92-
shouldClearCache = shouldClearCache
87+
measuredTimesStore = measuredTimesStore
9388
)
9489

9590
private class DecodeFrameRunnable(
9691
private val syncedFrames: MutableList<SyncedFrame>,
9792
private val frameStore: AnimatedFrameStore,
9893
private val lock: Any,
9994
private val nextFrameIndex: Int,
100-
private val measuredTimesStore: MutableList<Int>,
101-
private val preheatFrames: Int,
102-
private val shouldClearCache: Boolean
95+
private val measuredTimesStore: MutableList<Int>
10396
) : Runnable {
10497
override fun run() {
10598
val measureTime = measureTimeMillis {
10699
val syncedNextFrame = syncedFrames.firstOrNull { it.frameIndex == nextFrameIndex }
107100
if (syncedNextFrame == null) {
108-
if (shouldClearCache) {
109-
val firstFromNext = nextFrameIndex - preheatFrames
110-
if (syncedFrames.firstOrNull { it.frameIndex == firstFromNext } != null) {
111-
syncedFrames.removeIf { it.frameIndex == firstFromNext }
112-
}
113-
}
114101
val nextFrame = frameStore.getFrame(nextFrameIndex)
115102
val nextFrameDuration = frameStore.getFrameDuration(nextFrameIndex)
116103
synchronized(lock) {
@@ -226,15 +213,13 @@ public class AnimatedDrawable(
226213
mHandlerThread.post(preheatRunnable)
227214
}
228215

229-
private val matrix = Matrix()
230216
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
231217

232218
private val rect = Rect()
233219

234220
override fun draw(canvas: Canvas) {
235221
val bmp = currentBitmap
236222
if (bmp != null) {
237-
matrix.reset()
238223
rect.set(0, 0, bmp.width, bmp.height)
239224
canvas.drawBitmap(bmp, rect, bounds, paint)
240225
}
@@ -245,11 +230,11 @@ public class AnimatedDrawable(
245230
}
246231

247232
override fun getIntrinsicHeight(): Int {
248-
return frameStore.height
233+
return bounds.height()
249234
}
250235

251236
override fun getIntrinsicWidth(): Int {
252-
return frameStore.width
237+
return bounds.width()
253238
}
254239

255240
override fun setColorFilter(colorFilter: ColorFilter?) {

0 commit comments

Comments
 (0)