Skip to content

Add libnsgif support #1709

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

Merged
merged 28 commits into from
Mar 27, 2021
Merged

Add libnsgif support #1709

merged 28 commits into from
Mar 27, 2021

Conversation

jcupitt
Copy link
Member

@jcupitt jcupitt commented Jul 7, 2020

See this issue for notes on this PR: #1084

This is probably too late for 8.10. Let's look at this again during the 8.11 cycle.

@jcupitt
Copy link
Member Author

jcupitt commented Feb 28, 2021

I moved the libnsgif source into the tree and removed the old giflib code, so we now have no external dependencies for GIF load.

I added a --without-nsgif flag to configure to disable GIF load.

though unfortunately libnsgif seems to have broken DISPOSE_PREVIOUS
handling again
@jcupitt
Copy link
Member Author

jcupitt commented Feb 28, 2021

Unfortunately it seems libnsgif has non-functioning DISPOSE_PREVIOUS handling again, I'll investigate.

to linnsgif, trying to find the GIF decode bug
@jcupitt jcupitt added this to the 8.11 milestone Mar 6, 2021
@jcupitt jcupitt marked this pull request as draft March 6, 2021 11:57
@jcupitt jcupitt marked this pull request as ready for review March 7, 2021 15:17
@tlsa
Copy link
Contributor

tlsa commented Mar 8, 2021

@jcupitt Thanks for the patch, I have appied it upstream.

http://git.netsurf-browser.org/libnsgif.git/commit/?id=3665353c4da1dfb7b4a1d9fa412f0dec2cb673d2

@jcupitt
Copy link
Member Author

jcupitt commented Mar 8, 2021

Hi @tlsa, thanks for applying the patch! Hopefully I didn't break some other case :( GIF has to be the worst image format ever :(

@jcupitt jcupitt merged commit 9cbb4c2 into master Mar 27, 2021
@lovell
Copy link
Member

lovell commented Mar 27, 2021

Apologies for not being able to test this earlier, before merging.

Using rotating-squares.gif as sample input shows a difference in the reported metadata.

Before:

$ vipsheader -a rotating-squares.gif 
...
n-pages: 30
loop: 0
delay: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 

After:

$ vipsheader -a rotating-squares.gif 
...
n-pages: 30
delay: 30

@lovell
Copy link
Member

lovell commented Mar 27, 2021

The missing loop property can be fixed with the following diff, but I'm less sure about the right approach for delay:

--- a/libvips/foreign/nsgifload.c
+++ b/libvips/foreign/nsgifload.c
@@ -285,6 +285,7 @@ vips_foreign_load_nsgif_set_header( VipsForeignLoadNsgif *gif,
        vips_image_set_int( image, VIPS_META_N_PAGES, 
                gif->frame_count_displayable );
        vips_image_set_int( image, "gif-loop", gif->anim->loop_count );
+       vips_image_set_int( image, "loop", gif->anim->loop_count );
 
        vips_image_set_array_int( image, "delay", gif->delay, gif->n );

@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2021

Drat, sorry Lovell, I should have tested more carefully.

I think it's all fixed with 89c12b0 if you have time to test.

@lovell
Copy link
Member

lovell commented Mar 28, 2021

@jcupitt Your fix looks good, thank you.

@lovell
Copy link
Member

lovell commented Mar 28, 2021

@jcupitt Is it possible to recover from GIF_INSUFFICIENT_FRAME_DATA? There are ~25 places in libnsgif.c that can return this status, which makes it feel more like something that should always fail fast.

@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2021

Oh interesting, I'm not sure. Do you have an example gif which behaves badly?

@lovell
Copy link
Member

lovell commented Mar 28, 2021

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32607 is a 23 byte GIF file that claims to be 16448x73536.

@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2021

Oh wow OK that's bad.

I'm planning to work on jp2k compression in tiff today, so if anyone else has time to fix this, please go ahead!

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 this pull request may close these issues.

3 participants