]> git.imager.perl.org - imager.git/commitdiff
- mixing qtype scaling now sets all channels of a pixel to zero if
authorTony Cook <tony@develop=help.com>
Tue, 1 Apr 2008 10:12:17 +0000 (10:12 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 1 Apr 2008 10:12:17 +0000 (10:12 +0000)
   the pixel has zero coverage (zero alpha).  This should produce more
   compressible output files.
   http://rt.cpan.org/Ticket/Display.html?id=32324

Changes
scale.im
t/t40scale.t

diff --git a/Changes b/Changes
index 9b32bd5275f2058b7e65a79bc5e946baaa9cf248..0364f99e889e7a457971c0e31313e7d20379fd22 100644 (file)
--- 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
 ===========
 
index dbfb2d11ecaa9dff4ab53f8dad5869ed46669529..36ed2a56bc26ac2b78437207f2086080c4458ea4 100644 (file)
--- 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 {
index 8bd0e8b0d880fad329a15149941af23e69073340..f4de640804145bb5e49bbc589aff0c12ab5a7926 100644 (file)
@@ -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