glide icon indicating copy to clipboard operation
glide copied to clipboard

AVIF Image Rendering Issues on Android 12+: Black Backgrounds

Open vignesh-em opened this issue 1 year ago • 5 comments

Glide Version: 4.14.2

Integration libraries: none

Device/Android Version: Samsung Galaxy M52 / Android 13

Use case background:

Android 12 introduces support for AVIF images. So starting Android 12, Glide should be able to decode AVIFs without avif-integration library. However, when used without the avif integration library, the avif images are sometimes not rendered or rendered with a black background (the image has transparent parts).

I also tested this on a Pixel 6 Pro running Android 12. The image did not render.

I am not sure whether this is a platform issue or an issue with the way glide processes avif images but I do see the devices have a decoder that supports video/av01 format.

The sample project can be found here.

food-avif-vs-webp (2)

vignesh-em avatar May 16 '23 08:05 vignesh-em

@vigneshvg, do you think the platform decoder is having trouble decoding AVIF images? Including the glide avif integration library fixes this issue (it is now using the decoder provided by the integration library).

vignesh-em avatar May 16 '23 11:05 vignesh-em

@vigneshvg, do you think the platform decoder is having trouble decoding AVIF images? Including the glide avif integration library fixes this issue (it is now using the decoder provided by the integration library).

The platform decoder does NOT support alpha transparency. The platform decoder also has other limitations (it only supports 8-bit and 10-bit YUV420 AVIF images). Android 14 removes some of those limitations (but transparent images are not supported still).

If you need to use transparent images (or any other AVIF feature not supported by the platform), you would have to use the AVIF Glide Integration library. Also, note that the underlying decoder used by the integration library had a bug with transparent images which was fixed in https://github.com/bumptech/glide/pull/5128.

There hasn't been a Glide release with that patch included yet. So you may want to update your local build.gradle to use the specific version of the libavif dependency. Please see https://bumptech.github.io/glide/int/about.html#how-do-i-use-a-specific-version-of-okhttp-volley-or-other-third-party-library for instructions on how to do this. You will want to include org.aomedia.avif.android:avif:0.11.1.3c786d2.

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

vigneshvg avatar May 16 '23 17:05 vigneshvg

@vigneshvg

Wait, there is an addon-library of loading AVIF via Glide even on old versions of Android? Where? And how do I use it? Does it have a good license that doesn't force me to have all in open source?

AndroidDeveloperLB avatar Aug 28 '23 20:08 AndroidDeveloperLB

@vigneshvg

Wait, there is an addon-library of loading AVIF via Glide even on old versions of Android?

Yes there is! That is exactly what the Glide AVIF integration library does (i.e.) if you use the integration library, it will bundle an AVIF decoder along with your app and it will work the same irrespective of the version of Android that the app is running on.

Where? And how do I use it?

It is fairly straightforward if you are already using Glide. See here for details: https://bumptech.github.io/glide/int/avif.html

Does it have a good license that doesn't force me to have all in open source?

I don't know the exact answer for this. It uses libavif underneath. So you would have to check about the licensing yourself.

vigneshvg avatar Aug 29 '23 22:08 vigneshvg

@vigneshvg Thank you. Hope to check it out some time.

AndroidDeveloperLB avatar Sep 06 '23 09:09 AndroidDeveloperLB