Skip to content

Commit

Permalink
Remove unnecessary code and ENCODED_LOOP_COUNT not to be applied when…
Browse files Browse the repository at this point in the history
… using GifDecoder
  • Loading branch information
tgyuuAn committed Nov 11, 2024
1 parent 5b302b6 commit 6ed462e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions coil-gif/api/coil-gif.api
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
public final class coil3/gif/AnimatedImageDecoder : coil3/decode/Decoder {
public static final field Companion Lcoil3/gif/AnimatedImageDecoder$Companion;
public static final field ENCODED_LOOP_COUNT I
public fun <init> (Lcoil3/decode/ImageSource;Lcoil3/request/Options;Z)V
public synthetic fun <init> (Lcoil3/decode/ImageSource;Lcoil3/request/Options;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun decode (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class coil3/gif/AnimatedImageDecoder$Companion {
}

public final class coil3/gif/AnimatedImageDecoder$Factory : coil3/decode/Decoder$Factory {
public fun <init> ()V
public fun <init> (Z)V
Expand Down
11 changes: 10 additions & 1 deletion coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import coil3.decode.Decoder
import coil3.decode.ImageSource
import coil3.decode.toImageDecoderSourceOrNull
import coil3.fetch.SourceFetchResult
import coil3.gif.MovieDrawable.Companion.ENCODED_LOOP_COUNT
import coil3.gif.internal.animatable2CallbackOf
import coil3.gif.internal.asPostProcessor
import coil3.gif.internal.maybeWrapImageSourceToRewriteFrameDelay
import coil3.gif.internal.squashToDirectByteBuffer
import coil3.request.ImageRequest
import coil3.request.Options
import coil3.request.allowRgb565
import coil3.request.bitmapConfig
Expand Down Expand Up @@ -162,4 +162,13 @@ class AnimatedImageDecoder(
(SDK_INT >= 30 && DecodeUtils.isAnimatedHeif(source))
}
}

companion object {
/**
* Pass this to [ImageRequest.Builder.repeatCount] to repeat according to encoded LoopCount metadata.
* This only applies when using [AnimatedImageDecoder].
*/
@RequiresApi(28)
const val ENCODED_LOOP_COUNT = -2
}
}
6 changes: 5 additions & 1 deletion coil-gif/src/main/java/coil3/gif/GifDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ package coil3.gif

import android.graphics.Bitmap
import android.graphics.Movie
import android.os.Build
import coil3.ImageLoader
import coil3.asImage
import coil3.decode.DecodeResult
import coil3.decode.DecodeUtils
import coil3.decode.Decoder
import coil3.decode.ImageSource
import coil3.fetch.SourceFetchResult
import coil3.gif.AnimatedImageDecoder.Companion.ENCODED_LOOP_COUNT
import coil3.gif.internal.animatable2CompatCallbackOf
import coil3.gif.internal.maybeWrapImageSourceToRewriteFrameDelay
import coil3.request.Options
Expand Down Expand Up @@ -49,7 +51,9 @@ class GifDecoder(
scale = options.scale,
)

drawable.setRepeatCount(options.repeatCount)
if (options.repeatCount != ENCODED_LOOP_COUNT) {
drawable.setRepeatCount(options.repeatCount)
}

// Set the start and end animation callbacks if any one is supplied through the request.
val onStart = options.animationStartCallback
Expand Down
13 changes: 1 addition & 12 deletions coil-gif/src/main/java/coil3/gif/MovieDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ class MovieDrawable @JvmOverloads constructor(
* Default: [REPEAT_INFINITE]
*/
fun setRepeatCount(repeatCount: Int) {
if (SDK_INT >= 28) {
require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" }
} else {
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" }
}
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" }
this.repeatCount = repeatCount
}

Expand Down Expand Up @@ -290,12 +286,5 @@ class MovieDrawable @JvmOverloads constructor(
companion object {
/** Pass this to [setRepeatCount] to repeat infinitely. */
const val REPEAT_INFINITE = -1

/**
* Pass this to [setRepeatCount] to repeat according to encoded LoopCount metadata.
* This only applies when using [AnimatedImageDecoder].
*/
@RequiresApi(28)
const val ENCODED_LOOP_COUNT = -2
}
}
6 changes: 3 additions & 3 deletions coil-gif/src/main/java/coil3/gif/imageRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package coil3.gif
import android.graphics.ImageDecoder
import android.graphics.drawable.AnimatedImageDrawable
import android.graphics.drawable.Drawable
import android.os.Build.VERSION.SDK_INT
import android.os.Build
import coil3.Extras
import coil3.annotation.ExperimentalCoilApi
import coil3.getExtra
import coil3.gif.MovieDrawable.Companion.ENCODED_LOOP_COUNT
import coil3.gif.AnimatedImageDecoder.Companion.ENCODED_LOOP_COUNT
import coil3.gif.MovieDrawable.Companion.REPEAT_INFINITE
import coil3.request.ImageRequest
import coil3.request.Options
Expand All @@ -19,7 +19,7 @@ import coil3.request.Options
* @see AnimatedImageDrawable.setRepeatCount
*/
fun ImageRequest.Builder.repeatCount(repeatCount: Int) = apply {
if (SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= 28) {
require(repeatCount >= ENCODED_LOOP_COUNT) { "Invalid repeatCount: $repeatCount" }
} else {
require(repeatCount >= REPEAT_INFINITE) { "Invalid repeatCount: $repeatCount" }
Expand Down

0 comments on commit 6ed462e

Please sign in to comment.