From 2757bad050d6a50f125b1e553eec784be1257db6 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Tue, 1 Apr 2008 10:12:17 +0000 Subject: [PATCH] - mixing qtype scaling now sets all channels of a pixel to zero if the pixel has zero coverage (zero alpha). This should produce more compressible output files. http://rt.cpan.org/Ticket/Display.html?id=32324 --- Changes | 5 +++++ scale.im | 23 +++++++++++++++++++++++ t/t40scale.t | 8 ++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 9b32bd52..0364f99e 100644 --- a/Changes +++ b/Changes @@ -62,6 +62,11 @@ Bug fixes: parameters. http://rt.cpan.org/Ticket/Display.html?id=29937 + - mixing qtype scaling now sets all channels of a pixel to zero if + the pixel has zero coverage (zero alpha). This should produce more + compressible output files. + http://rt.cpan.org/Ticket/Display.html?id=32324 + Imager 0.62 - 10 December 2007 =========== diff --git a/scale.im b/scale.im index dbfb2d11..36ed2a56 100644 --- a/scale.im +++ b/scale.im @@ -178,6 +178,17 @@ i_scale_mixing(i_img *src, int x_out, int y_out) { xscale_row[x].channel[ch] = IM_LIMIT(val); } } + else { + /* rather than leaving any color data as whatever was + originally in the buffer, set it to black. This isn't + any more correct, but it gives us more compressible + image data. + RT #32324 + */ + for (ch = 0; ch < alpha_chan; ++ch) { + xscale_row[x].channel[ch] = 0; + } + } xscale_row[x].channel[alpha_chan] = IM_LIMIT(accum_row[x].channel[alpha_chan]+0.5); } } @@ -275,6 +286,12 @@ IM_SUFFIX(horizontal_scale)(IM_COLOR *out, int out_width, out[out_x].channel[ch] = IM_LIMIT(val); } } + else { + for (ch = 0; ch < alpha_chan; ++ch) { + /* See RT #32324 (and mention above) */ + out[out_x].channel[ch] = 0; + } + } out[out_x].channel[alpha_chan] = IM_LIMIT(IM_ROUND(accum[alpha_chan])); } else { @@ -315,6 +332,12 @@ IM_SUFFIX(horizontal_scale)(IM_COLOR *out, int out_width, out[out_x].channel[ch] = IM_LIMIT(val); } } + else { + for (ch = 0; ch < alpha_chan; ++ch) { + /* See RT #32324 (and mention above) */ + out[out_x].channel[ch] = 0; + } + } out[out_x].channel[alpha_chan] = IM_LIMIT(IM_ROUND(accum[alpha_chan])); } else { diff --git a/t/t40scale.t b/t/t40scale.t index 8bd0e8b0..f4de6408 100644 --- a/t/t40scale.t +++ b/t/t40scale.t @@ -1,9 +1,9 @@ #!perl -w use strict; -use Test::More tests => 227; +use Test::More tests => 228; BEGIN { use_ok(Imager=>':all') } -use Imager::Test qw(is_image); +use Imager::Test qw(is_image is_color4); #require "t/testtools.pl"; @@ -194,6 +194,10 @@ SKIP: my $cmp = $out->copy; $out->rubthrough(src => $sc); is_image($out, $cmp, "check we get the right image after scaling"); + + # we now set alpha=0 pixels to zero on scaling + is_color4($sc->getpixel('x' => 39, 'y' => 39), 0, 0, 0, 0, + "check we set alpha=0 pixels to zero on scaling"); } { # scale_calculate -- 2.39.5