Skip to content

Gif is decoded as 1 frame animation #801

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

Closed
5ALEKSEY opened this issue Jul 8, 2022 · 2 comments
Closed

Gif is decoded as 1 frame animation #801

5ALEKSEY opened this issue Jul 8, 2022 · 2 comments

Comments

@5ALEKSEY
Copy link

5ALEKSEY commented Jul 8, 2022

Hello 😇

I've found an issue on my working project. I have faced with a problem when some of our GIF display incorrectly.

I've investigated and found out that:

  1. SampleSize doesn't work if the value grater then 1 was passed
    (But as I see, you are already know it and even managed to fix 👍 Waiting for the release)
  2. GIF is decoded as 1 frame animation.

Let's talk about second one.

Our GifDrawable creating has next steps:

GifOptions gifOptions = new GifOptions();
gifOptions.setInSampleSize(gifInSampleSize); // 'gifInSampleSize' was calculated before
drawable = new GifDrawableBuilder()
            .from(mContext.getContentResolver(), gifUri)
            .options(gifOptions)
            .build();
drawable.setLoopCount(0);

As the result GifDrawable is: GIF: size: 1999x1999, frames: 1, error: 107

Here we can see 107 error and only 1 fetched frame (but actually it has more frames 😞)

About GIF. Nothing special here except of "why is it so big??? 🙃".
Yes, it is really big. And, btw, gifInSampleSize = 4 here 🤫
It was found during the testing of different sizes.

How was this GIF born:

I request you help in case of at least explanation "why it was decoded as 1 frame". I don't know, probably, online converter made it's own dirty monkey tricks and GIF file become broken. So, I would appreciate any of your help and explanation here.

P.S. I have tested this gif with your sample project and added this 'broken' GIF to drawable resources. Result is the same. You can reproduce it by yourself, I'll attach it.
P.P.S. GIF playing is okey for my PC (more than 1 frame animation)

broken_cat.zip

@koral--
Copy link
Owner

koral-- commented Jul 10, 2022

Frames of that GIF are located outside the canvas.

% gifsicle -I broken_cat.gif
* broken_cat.gif 19 images
  logical screen 3999x3999
  global color table [256]
  background 0
  loop forever
  + image #0 3999x3999
    disposal asis delay 2.00s
  + image #1 3393x3999 at 993,2014 transparent 0
...

The entire canvas has size 3999x3999 px, but eg. image #1 having size 3393x3999 starts at offset 993,2014 so it requires canvas which has at least 4386x6013 px.

Some GIF viewers try to "fix" such issues either by extending the canvas or cropping parts which exceed the bounds.
In this library, currently such cases are treated as errors. In the past there were workarounds but they turns out to be too complicated to support. This library does not buffer the source but reads frames as needed. Sources may be modified in the meantime.
Viewers like desktop apps can buffer entire decoded GIF in memory and may not need to read it from the source again so applying workarounds is easier.

Regarding decoding as 1 frame. In this library (and probably in most viewers) there is a rule that the content successfully decoded (what exactly can be successful depends among the others on workarounds for broken images) so far is kept and after error is encountered then new frames are not decoded. As you can see on the gifsicle output image #0 is correct and the next one is too large, so there is only 1 valid image.

Regarding error reported. In this case it should be 1000 Image not confined. I'll fix that.

@5ALEKSEY
Copy link
Author

Oh, I see 🤔

So, I believe in a future you will manage to find a great and easy approach/way to "support" such frameSize-broken GIFs.

Anyway, thanks a lot for your help, explanation and really quick answer 👍👍👍

koral-- added a commit that referenced this issue Jul 20, 2022
Fixes incorrect error code in #801
@koral-- koral-- closed this as completed Jul 20, 2022
koral-- added a commit that referenced this issue Aug 18, 2022
* Dependency versions bump
* Stop further decoding on error. Fixes incorrect error code in #801
* Sample dependency versions bump
* Stronger suppress warning for workaround in LibraryLoader
* Fix java to kotlin conversion of TexturePlaceholderFragment.kt
* Clear GifTextureView when removing source. Fixes #745
* Fix current position calculation on the subsequent loops on first frame. Fixes #657
* Update NDK to 25.0.8775105
* Release 1.2.25
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

No branches or pull requests

2 participants