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

[4.13.2] Transparent layer is not working with Avif #4807

Open
mezentsev opened this issue May 27, 2022 · 3 comments
Open

[4.13.2] Transparent layer is not working with Avif #4807

mezentsev opened this issue May 27, 2022 · 3 comments
Labels

Comments

@mezentsev
Copy link

mezentsev commented May 27, 2022

I use glide 4.13.2 with avif support

implementation("com.github.bumptech.glide:glide:4.13.2")
implementation("com.github.bumptech.glide:avif-integration:4.13.2")
implementation("com.github.bumptech.glide:annotations:4.13.2")
annotationProcessor("com.github.bumptech.glide:compiler:4.13.2")

but I am stuck with transparent layer. All images got problems with background: green, black or problems with displaying.

Example avifs with device output
All avifs and device output screens

How Glide renders it on my Pixel 5

  1. Black background instead of transparancy

car1-device

  1. Black background instead of transparancy

shade-device

  1. No image, bu transparancy :)

mask-device

  1. Green background instead of transparancy

car2-device

  1. Black background instead of transparancy

burger-device

You can find all avifs by link above.

Device: Pixel 5 Android 12

Is it a known problem? I saw the similar problem in #4751

@vigneshvg
Copy link
Contributor

Hi,

Thanks for the detailed bug report. The AVIF integration supports images with alpha channel.

Do you have an AppGlideModule to activate the AVIF integration? Without the AppGlideModule, Glide will try to decode the AVIF images using the platform's AVIF decoder (it will be available on android versions >= 12). The platform decoder does NOT support alpha channel and would result in images being rendered as you have shared.

A sample empty app glide module:

@GlideModule
public final class YourAppGlideModule extends AppGlideModule {}

I am able to reproduce this on my pixel 3. Without the app glide module, i see images rendered similar to yours. With the app glide module, i see the images rendered correctly with transparency based on whether or not dark mode is enabled in the system settings.

Here is how it renders on my Pixel 3 with the correct app glide module.

Light Mode:

burger
car1
car2
mask
shade

Dark Mode:

burger
car1
car2
mask
shade

Hope that helps. Please let me know if you have any further questions.

@yvonnelyf
Copy link

yvonnelyf commented Jul 20, 2022

same problem with this file,on system version below android 12
051b5f213ab01a4c.png.avif.zip

@mezentsev
Copy link
Author

mezentsev commented Sep 14, 2022

@vigneshvg
Thanks for answer. It helps for main purposes but not for Targets.
I found a problem with loading via CustomViewTarget. I'd share an example:

      // ...
      val target = glideTarget(tariffImage) ?: object : CustomViewTarget<ImageView, Drawable>(myImageView) {
        override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
          getView().setImageDrawable(resource)
        }

        override fun onLoadFailed(errorDrawable: Drawable?) {
          // no-op
        }

        override fun onResourceCleared(placeholder: Drawable?) {
          // no-op
        }
      }
      saveTarget(tariffImage, target)

      Glide.with(myImageView)
        .load(iconUrl)
        .into(target)
    }
    // ...

  private fun saveTarget(view: View, glideTarget: Target<Drawable>) {
    view.setTag(R.id.image_view_tag_glide_target, glideTarget)
  }

  private fun glideTarget(view: View): Target<Drawable>? {
    return view.getTag(R.id.image_view_tag_glide_target) as? Target<Drawable>
  }

That example shows white background for AVIF.

But I watched througth the source code and found interesting moment with ImageView:
glideContext.buildImageViewTarget(view, transcodeClass)
that helps

@sjudd sjudd added the AVIF label Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants