From: Tony Cook Date: Fri, 27 Mar 2020 06:32:30 +0000 (+1100) Subject: ensure alpha channels are initialized for mediancut make_colors X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/7cbdbb3ef7236cd2aee5e0e358d304921d9856a9 ensure alpha channels are initialized for mediancut make_colors This could result in a 4 channel paletted image with some random alpha channel. CPAN #132237 --- diff --git a/quant.c b/quant.c index c798080c..419b81b7 100644 --- a/quant.c +++ b/quant.c @@ -633,6 +633,7 @@ makemap_mediancut(i_quantize *quant, i_img **imgs, int count) { for (ch = 0; ch < 3; ++ch) { quant->mc_colors[i].channel[ch] = colors[i].rgb[ch]; } + quant->mc_colors[i].rgba.a = 255; } quant->mc_count = out; } @@ -720,6 +721,7 @@ makemap_mediancut(i_quantize *quant, i_img **imgs, int count) { for (ch = 0; ch < 3; ++ch) { quant->mc_colors[part_num].channel[ch] = sums[ch] / workpart->pixels; } + quant->mc_colors[part_num].rgba.a = 255; } quant->mc_count = color_count; } diff --git a/t/150-type/040-palette.t b/t/150-type/040-palette.t index 00d8935b..2d50dbbb 100644 --- a/t/150-type/040-palette.t +++ b/t/150-type/040-palette.t @@ -649,6 +649,16 @@ my $psamp_outside_error = "Image position outside of image"; "check error message"); } +{ + # https://rt.cpan.org/Ticket/Display.html?id=132237 + # a 4 channel opaque image with a default to_paletted would + # return palette values with non-max alpha values + my $im = test_image()->convert(preset => 'addalpha')->to_paletted; + my @col = $im->getcolors; + is($im->getchannels, 4, "still 4 channels"); + is($col[0]->alpha, 255, "should have a 255 alpha"); +} + Imager->close_log; done_testing();