Skip to content

cgifsave: number of colours in palette is one less than it could/should be #2852

Closed
@lovell

Description

@lovell

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:

vips__quantise_set_max_colors( cgif->attr, (1 << cgif->bitdepth) - 1 );

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions