Skip to content

Commit

Permalink
Add a configuration option to disable ImageDecoder. (#2823)
Browse files Browse the repository at this point in the history
* Add a configuration option to disable ImageDecoder.

* Docs.
  • Loading branch information
colinrtwhite authored Jan 31, 2025
1 parent 7b09b4c commit f8f16d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions coil-core/api/android/coil-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public final class coil3/ImageLoadersKt {
public final class coil3/ImageLoaders_androidKt {
public static final fun bitmapFactoryExifOrientationStrategy (Lcoil3/ImageLoader$Builder;Lcoil3/decode/ExifOrientationStrategy;)Lcoil3/ImageLoader$Builder;
public static final fun bitmapFactoryMaxParallelism (Lcoil3/ImageLoader$Builder;I)Lcoil3/ImageLoader$Builder;
public static final fun imageDecoderEnabled (Lcoil3/ImageLoader$Builder;Z)Lcoil3/ImageLoader$Builder;
}

public final class coil3/ImageLoaders_nonJsCommonKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private fun enableStaticImageDecoder(options: RealImageLoader.Options): Boolean
// Require API 29 for ImageDecoder support as API 28 has framework bugs:
// https://github.com/element-hq/element-android/pull/7184
return SDK_INT >= 29 &&
options.imageDecoderEnabled &&
// ImageDecoder always rotates the image according to its EXIF data.
options.bitmapFactoryExifOrientationStrategy.let { it == RESPECT_PERFORMANCE || it == RESPECT_ALL }
}
17 changes: 17 additions & 0 deletions coil-core/src/androidMain/kotlin/coil3/imageLoaders.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import coil3.decode.BitmapFactoryDecoder
import coil3.decode.BitmapFactoryDecoder.Companion.DEFAULT_MAX_PARALLELISM
import coil3.decode.Decoder
import coil3.decode.ExifOrientationStrategy
import coil3.decode.ExifOrientationStrategy.Companion.RESPECT_PERFORMANCE

Expand Down Expand Up @@ -42,3 +43,19 @@ internal val RealImageLoader.Options.bitmapFactoryExifOrientationStrategy: ExifO
private val bitmapFactoryExifOrientationStrategyKey = Extras.Key(default = RESPECT_PERFORMANCE)

// endregion
// region imageDecoderEnabled

/**
* Enables using [ImageDecoder] as this image loader's main [Decoder] on API 29 and above.
* If false, [BitmapFactory] is used on all API levels.
*/
fun ImageLoader.Builder.imageDecoderEnabled(enabled: Boolean) = apply {
extras[imageDecoderEnabledKey] = enabled
}

internal val RealImageLoader.Options.imageDecoderEnabled: Boolean
get() = defaults.extras.getOrDefault(imageDecoderEnabledKey)

private val imageDecoderEnabledKey = Extras.Key(default = true)

// endregion

0 comments on commit f8f16d0

Please sign in to comment.