From 905a6fe79f742702b6c9fa6e47a602ee98f6ff80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B6bl?= Date: Sun, 19 Jun 2022 13:16:03 +0200 Subject: [PATCH] cgifsave: limit max number of colours to 255 (#2863) * cgifsave: limit max number of colours to 255 * switch to VIPS_MIN --- libvips/foreign/cgifsave.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libvips/foreign/cgifsave.c b/libvips/foreign/cgifsave.c index b25ad434..c9c58639 100644 --- a/libvips/foreign/cgifsave.c +++ b/libvips/foreign/cgifsave.c @@ -738,7 +738,11 @@ vips_foreign_save_cgif_build( VipsObject *object ) /* Set up libimagequant. */ cgif->attr = vips__quantise_attr_create(); - vips__quantise_set_max_colors( cgif->attr, 1 << cgif->bitdepth ); + /* Limit the number of colours to 255, so there is always one index + * free for the transparency optimization. + */ + vips__quantise_set_max_colors( cgif->attr, + VIPS_MIN( 255, 1 << cgif->bitdepth ) ); vips__quantise_set_quality( cgif->attr, 0, 100 ); vips__quantise_set_speed( cgif->attr, 11 - cgif->effort );