]> git.imager.perl.org - imager.git/commitdiff
- Regression: filling a greyscale image with a hatch used the wrong
authorTony Cook <tony@develop=help.com>
Tue, 22 Apr 2008 04:10:06 +0000 (04:10 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 22 Apr 2008 04:10:06 +0000 (04:10 +0000)
   color channels from the supplied fg/bg colors.
   https://rt.cpan.org/Ticket/Display.html?id=35278

Changes
fills.c
t/t20fill.t

diff --git a/Changes b/Changes
index e6ef2bfd4af3b4489b5c59ae7e4139085e899062..e9eb06fec49b6f6825d0d02821c3e2b2114261f1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -18,6 +18,10 @@ Bug fixes:
    scale size parameters are a reference.
    http://rt.cpan.org/Ticket/Display.html?id=35172
 
+ - Regression: filling a greyscale image with a hatch used the wrong
+   color channels from the supplied fg/bg colors.
+   https://rt.cpan.org/Ticket/Display.html?id=35278
+
 Imager 0.63 - 7 April 2008
 ===========
 
diff --git a/fills.c b/fills.c
index 55139ed092eceac57d01c73aa56822bc623de318..973b2f96140df503d71057c01f98860a55bc4862 100644 (file)
--- a/fills.c
+++ b/fills.c
@@ -650,12 +650,20 @@ static void fill_hatch(i_fill_t *fill, int x, int y, int width, int channels,
   int byte = f->hatch[(y + f->dy) & 7];
   int xpos = (x + f->dx) & 7;
   int mask = 128 >> xpos;
+  i_color fg = f->fg;
+  i_color bg = f->bg;
+  int want_channels = channels > 2 ? 4 : 2;
+
+  if (channels < 3) {
+    i_adapt_colors(2, 4, &fg, 1);
+    i_adapt_colors(2, 4, &bg, 1);
+  }
 
   while (width-- > 0) {
     if (byte & mask)
-      *data++ = f->fg;
+      *data++ = fg;
     else
-      *data++ = f->bg;
+      *data++ = bg;
     
     if ((mask >>= 1) == 0)
       mask = 128;
@@ -675,12 +683,19 @@ static void fill_hatchf(i_fill_t *fill, int x, int y, int width, int channels,
   int byte = f->hatch[(y + f->dy) & 7];
   int xpos = (x + f->dx) & 7;
   int mask = 128 >> xpos;
+  i_fcolor fg = f->ffg;
+  i_fcolor bg = f->fbg;
+
+  if (channels < 3) {
+    i_adapt_fcolors(2, 4, &fg, 1);
+    i_adapt_fcolors(2, 4, &bg, 1);
+  }
   
   while (width-- > 0) {
     if (byte & mask)
-      *data++ = f->ffg;
+      *data++ = fg;
     else
-      *data++ = f->fbg;
+      *data++ = bg;
     
     if ((mask >>= 1) == 0)
       mask = 128;
index 5cc253ec971da6f31e8dba76cef74b7467163a97..f42dc49a5a3cd9fcabb431ffa55d34f6658ec06b 100644 (file)
@@ -1,10 +1,11 @@
 #!perl -w
 use strict;
-use Test::More tests => 121;
+use Test::More tests => 123;
 
 use Imager ':handy';
 use Imager::Fill;
 use Imager::Color::Float;
+use Imager::Test qw(is_image);
 use Config;
 
 Imager::init_log("testout/t20fill.log", 1);
@@ -413,6 +414,27 @@ SKIP:
   cmp_ok(Imager->errstr, '=~', 'No color named', "check error message");
 }
 
+{ # RT #35278
+  # hatch fills on a grey scale image don't adapt colors
+  for my $bits (8, 'double') {
+    my $im_g = Imager->new(xsize => 10, ysize => 10, channels => 1, bits => $bits);
+    $im_g->box(filled => 1, color => 'FFFFFF');
+    my $fill = Imager::Fill->new
+      (
+       combine => 'normal', 
+       hatch => 'weave', 
+       fg => '000000', 
+       bg => 'FFFFFF'
+      );
+    $im_g->box(fill => $fill);
+    my $im_c = Imager->new(xsize => 10, ysize => 10, channels => 3, bits => $bits);
+    $im_c->box(filled => 1, color => 'FFFFFF');
+    $im_c->box(fill => $fill);
+    my $im_cg = $im_g->convert(preset => 'rgb');
+    is_image($im_c, $im_cg, "check hatch is the same between color and greyscale");
+  }
+}
+
 sub color_close {
   my ($c1, $c2) = @_;