diff --git a/coil-gif/api/coil-gif.api b/coil-gif/api/coil-gif.api index de841cbef4..df3d600c75 100644 --- a/coil-gif/api/coil-gif.api +++ b/coil-gif/api/coil-gif.api @@ -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 (Lcoil3/decode/ImageSource;Lcoil3/request/Options;Z)V public synthetic fun (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 ()V public fun (Z)V diff --git a/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt b/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt index c5a64c163a..5de226161a 100644 --- a/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt +++ b/coil-gif/src/main/java/coil3/gif/AnimatedImageDecoder.kt @@ -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 @@ -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 + } } diff --git a/coil-gif/src/main/java/coil3/gif/GifDecoder.kt b/coil-gif/src/main/java/coil3/gif/GifDecoder.kt index eb4704173d..28de76f08e 100644 --- a/coil-gif/src/main/java/coil3/gif/GifDecoder.kt +++ b/coil-gif/src/main/java/coil3/gif/GifDecoder.kt @@ -4,6 +4,7 @@ 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 @@ -11,6 +12,7 @@ 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 @@ -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 diff --git a/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt b/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt index b2b716782e..c7bb5fb710 100644 --- a/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt +++ b/coil-gif/src/main/java/coil3/gif/MovieDrawable.kt @@ -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 } @@ -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 } } diff --git a/coil-gif/src/main/java/coil3/gif/imageRequests.kt b/coil-gif/src/main/java/coil3/gif/imageRequests.kt index 3265e5fa9d..17940a4e15 100644 --- a/coil-gif/src/main/java/coil3/gif/imageRequests.kt +++ b/coil-gif/src/main/java/coil3/gif/imageRequests.kt @@ -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 @@ -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" }