Fresco: Issue with adding APNG support

Created on 25 Apr 2020  路  4Comments  路  Source: facebook/fresco

APNG Image is always recognized as PNG

I am trying to add a custom decoder for APNG but running into an interesting issue. Because the headers start with the same sequence in APNG as PNG, Fresco always recognizes this as a PNG. In DefaultImageDecoder.decode(), you can see Fresco first checks for a default image format match before checking the custom decoders for a match. Because of this, an apng will always get seen as a png, even if all the format checkers and drawable factories are setup properly. Can you think of a way around this issue? (simply getting Fresco to check custom image formats first)

  • Fresco version: 2.0.0
  • Platform version: All Android versions
enhancement

Most helpful comment

I was able to successfully add APNG from this, thanks guys! Might open source it or PR it someday.

All 4 comments

I think you mean that in ImageFormatChecker#determineImageFormat Fresco first checks for default formats? After the format is determined it tries to find a custom decoder that supports the format first.

We should consider switching order so that custom image format checkers will be run first before the default checker. Another option would be to detect APNG natively and then treat it as PNG if a custom APNG decoder is not present.

As a workaround I suggest setting a custom decoder to image decode options per each APNG image request.

Hey!

That's interesting... This should work even if it's recognized as PNG and not APNG since you can override built-in formats (we check for that here: https://github.com/facebook/fresco/blob/5bb253afc0b5399dd0cfe4a1c6e20a9657ac034a/imagepipeline/src/main/java/com/facebook/imagepipeline/decoder/DefaultImageDecoder.java#L116 )

You have to use this API to override, I verified that this works in our sample app:

ImageDecoderConfig config = ImageDecoderConfig.newBuilder()
    .overrideDecoder(DefaultImageFormats.PNG, yourDecoder)
    .build();

Your decoder would have to handle both the PNG and APNG case though.

You can set the config for the ImagePipelineConfig.Builder when Fresco is initialized, see https://github.com/facebook/fresco/blob/31a36d7291388e5e2b1cc6d7091368d839a30430/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/ShowcaseApplication.kt#L75

I was able to successfully add APNG from this, thanks guys! Might open source it or PR it someday.

Awesome, sounds good.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cococool picture cococool  路  4Comments

hanhmh1203 picture hanhmh1203  路  4Comments

bigfreeZhou picture bigfreeZhou  路  4Comments

kingty picture kingty  路  4Comments

zewenwang picture zewenwang  路  4Comments