Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a configuration option to disable ImageDecoder. #2823

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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