Description
The number of colours in the palette of GIF output via cgifsave is currently set to one less than it could be due to this line:
libvips/libvips/foreign/cgifsave.c
Line 685 in bae0342
This can be highlighted by setting bitdepth
to 1, resulting in a call to liq_set_max_colors
with the value 1, which is out of the 2-256 range it supports. We currently ignore the error return code so the output GIF has the (default) bitdepth of 8, which is incorrect.
I'm probably to blame here as I originally wrote this code, with the logic of decrementing by 1 to allow space for an extra "colour" for the transparency, if any. However I think with all the recent updates to this code that this logic is no longer required, so the following change should fix this.
- vips__quantise_set_max_colors( cgif->attr, (1 << cgif->bitdepth) - 1 );
+ vips__quantise_set_max_colors( cgif->attr, 1 << cgif->bitdepth );
I'm aware there's more refactoring going on in and around this code so am creating an issue to track it rather than open a PR that may conflict with any work-in-progress.