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

Coil3 ImageLoader set bitmap config not work #2221

Closed
Caij opened this issue Apr 29, 2024 · 0 comments · Fixed by #2223
Closed

Coil3 ImageLoader set bitmap config not work #2221

Caij opened this issue Apr 29, 2024 · 0 comments · Fixed by #2223

Comments

@Caij
Copy link

Caij commented Apr 29, 2024

version:3.0.0-alpha6

init

 ImageLoader.Builder(this).bitmapConfig(Bitmap.Config.RGB_565)

EngineInterceptor

val options = requestService.options(request, size)

private fun ImageRequest.resolveExtras(size: Size): Extras {
        var bitmapConfig = bitmapConfig //RGB_565
        var allowRgb565 = allowRgb565

        // Fall back to ARGB_8888 if the requested bitmap config does not pass the checks.
        if (!isBitmapConfigValidMainThread(this, size)) {
            bitmapConfig = Bitmap.Config.ARGB_8888
        }

        // Disable allowRgb565 if there are transformations or the requested config is ALPHA_8.
        // ALPHA_8 is a mask config where each pixel is 1 byte so it wouldn't make sense to use
        // RGB_565 as an optimization in that case.
        allowRgb565 = allowRgb565 &&
            transformations.isEmpty() &&
            bitmapConfig != Bitmap.Config.ALPHA_8

        var builder: Extras.Builder? = null
        if (bitmapConfig != this.bitmapConfig) {  // **not reset**
            builder = extras.newBuilder().set(Extras.Key.bitmapConfig, bitmapConfig)
        }
        if (allowRgb565 != this.allowRgb565) {
            builder = (builder ?: extras.newBuilder()).set(Extras.Key.allowRgb565, allowRgb565)
        }
        return builder?.build() ?: extras
    }

val options = requestService.options(request, size)

there are return request.extras, options.extras is empty, request.defaults.extras have init config value
so new decode read options bitmap config is DEFAULT_BITMAP_CONFIG

BitmapFactoryDecoder

private fun BitmapFactory.Options.configureConfig(exifData: ExifData) {
        var config = options.bitmapConfig

        // Disable hardware bitmaps if we need to perform EXIF transformations.
        if (exifData.isFlipped || exifData.isRotated) {
            config = config.toSoftware()
        }

        // Decode the image as RGB_565 as an optimization if allowed.
        if (options.allowRgb565 && config == Bitmap.Config.ARGB_8888 && outMimeType == MIME_TYPE_JPEG) {
            config = Bitmap.Config.RGB_565
        }

        // High color depth images must be decoded as either RGBA_F16 or HARDWARE.
        if (SDK_INT >= 26 && outConfig == Bitmap.Config.RGBA_F16 && config != Bitmap.Config.HARDWARE) {
            config = Bitmap.Config.RGBA_F16
        }

        inPreferredConfig = config
    }
@Caij Caij changed the title Coil3 reset bitmap config not work Coil3 ImageLoader set bitmap config not work Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant