-
-
Notifications
You must be signed in to change notification settings - Fork 698
cgifsave: reuse global palette, if possible #2797
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
Conversation
... if there are no local colour tables. See libvips#2576
Oh very cool, I hadn't thought of using the palette as an image source. @DarthSim, do you have an opinion on the best way to initialise the quantisation result from an existing palette? On new switches to control behaviour:
|
That's exactly want I'd do :) |
I think we should reuse by default. The most common case must be GIF -> GIF resize, and that should reuse with no extra parameters. How about something like |
@jcupitt Good point. I'll introduce a
For now, I would prefer to keep the current method of determining palettes (in case no palette has been attached or |
OK, sounds reasonable. |
Ready for review from my side. Additional notes:
The issue is gone with the latest |
Hi again, could you explain the motivation behind the |
While testing this change with a dataset of GIFs, I noticed that about 25% of the animated GIFs we process have at least one local colour table (might be because some of the GIFs come from libvips originally). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two tiny comments.
25% is higher than I expected! Sure, let's do that in another PR. |
Sounds good 👍 |
Great! It seems to work well, this is a nice improvement. Good job! |
With
And with this patch:
So in many cases: smaller GIFs, lower CPU load, same memory use. |
For reference: 2576#comment
Reuse the global palette in
gifsave
if it has been attached duringgifload
.This should both improve the file size and processing time for many GIF -> GIF operations.
@jcupitt Notes / Questions:
VipsQuantiseResult
feels a bit hacky. Maybe there is a better way to do it?gifsave
to enable/disable global palette reuse?$ vipsthumbnail --size 200x phone.gif[n=-1] -o out.gif
Results:
GIF used: earth.gif
Before:
$ time vipsthumbnail --size 200x earth.gif[n=-1] -o old.gif
518ms total
After:
$ time vipsthumbnail --size 200x earth.gif[n=-1] -o new.gif
219ms total
$ du -h old.gif new.gif
580K old.gif
456K new.gif