fix flood_fill some more
authorTony Cook <tony@develop=help.com>
Sun, 26 Sep 2010 02:28:40 +0000 (02:28 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 26 Sep 2010 02:28:40 +0000 (02:28 +0000)
Changes
MANIFEST
draw.c
t/t21draw.t
t/t22flood.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 416427c7c48e068e7b804aa863249f24cc7f6cf7..bfda578028100914d45e121717caf719df485889 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,7 +3,7 @@ Imager release history.  Older releases can be found in Changes.old
 Imager 0.77_02 - unreleased
 ==============
 
- - moved Win32 font support into a sub-module.
+ - moved Win32, FreeType 2 font support into sub-modules.
    https://rt.cpan.org/Ticket/Display.html?id=49616 (partial)
    Uses Imager::Probe now.
    https://rt.cpan.org/Public/Bug/Display.html?id=61328
@@ -20,6 +20,10 @@ Bug fixes:
    fill area.
    Thanks to Nicolas Roggli for reporting this.
 
+ - flood_fill wouldn't fill to the left edge of the image if the
+   starting line didn't reach the left edge.
+   Thanks to Nicolas Roggli for reporting this.
+
 Imager 0.77_01 - 13 Sep 2010
 ==============
 
index dc9d06ef88440b494b753999b8eaed23a12db0a0..4fca21b63dd7eb4f67de2e5e5a6fc9af5db6de3f 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -337,6 +337,7 @@ t/t15color.t
 t/t16matrix.t           Tests Imager::Matrix2d
 t/t20fill.t             Tests fills
 t/t21draw.t             Basic drawing tests
+t/t22flood.t           Flood fill tests
 t/t30t1font.t
 t/t35ttfont.t
 t/t36oofont.t
diff --git a/draw.c b/draw.c
index 0dfd75783b78503f7dcf994c6bc1a1f9b7931d2f..1c04efbf9be2861ef18011470ea3dfa031e3d17d 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -1678,7 +1678,7 @@ i_flood_fill_low(i_img *im,int seedx,int seedy,
     if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
       SET(lx, y);
       lx--;
-      while(INSIDE(lx, y, seed) && lx > 0) {
+      while(lx >= 0 && INSIDE(lx, y, seed)) {
        SET(lx,y);
        lx--;
       }
index 28b62bbb74cc16e04f8c7aab906d37229ae14350..eed43e63369cea5022b287b2188867b51fb123b9 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 250;
+use Test::More tests => 244;
 use Imager ':all';
 use Imager::Test qw(is_color3 is_image);
 use constant PI => 3.14159265358979;
@@ -295,20 +295,6 @@ my $white = '#FFFFFF';
   }
 }
 
-{ # flood_fill wouldn't fill to the right if the area was just a 
-  # single scan-line
-  my $im = Imager->new(xsize => 5, ysize => 3);
-  ok($im, "make flood_fill test image");
-  ok($im->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "white"),
-     "create fill area");
-  ok($im->flood_fill(x => 3, y => 1, color => "blue"),
-     "fill it");
-  my $cmp = Imager->new(xsize => 5, ysize => 3);
-  ok($cmp, "make test image");
-  ok($cmp->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "blue"),
-     "synthezied filled area");
-  is_image($im, $cmp, "flood_fill filled horizontal line");
-}
 
 malloc_state();
 
diff --git a/t/t22flood.t b/t/t22flood.t
new file mode 100644 (file)
index 0000000..9224090
--- /dev/null
@@ -0,0 +1,67 @@
+#!perl -w
+use strict;
+use Test::More tests => 13;
+use Imager;
+use Imager::Test qw(is_image);
+
+{ # flood_fill wouldn't fill to the right if the area was just a
+  # single scan-line
+  my $im = Imager->new(xsize => 5, ysize => 3);
+  ok($im, "make flood_fill test image");
+  ok($im->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "white"),
+     "create fill area");
+  ok($im->flood_fill(x => 3, y => 1, color => "blue"),
+     "fill it");
+  my $cmp = Imager->new(xsize => 5, ysize => 3);
+  ok($cmp, "make test image");
+  ok($cmp->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "blue"),
+     "synthezied filled area");
+  is_image($im, $cmp, "flood_fill filled horizontal line");
+}
+
+SKIP:
+{ # flood_fill won't fill entire line below if line above is shorter
+  my $im = Imager->new(file => "testimg/filltest.ppm");
+  ok($im, "Load test image")
+    or skip("Couldn't load test image: " . Imager->errstr, 3);
+
+  # fill from first bad place
+  my $fill1 = $im->copy;
+  ok($fill1->flood_fill(x => 8, y => 2, color => "#000000"),
+     "fill from a top most spot");
+  my $cmp = Imager->new(xsize => $im->getwidth, ysize => $im->getheight);
+  is_image($fill1, $cmp, "check it filled the lot");
+  ok($fill1->write(file => "testout/t22fill1.ppm"), "save");
+
+  # second bad place
+  my $fill2 = $im->copy;
+  ok($fill2->flood_fill(x => 17, y => 3, color => "#000000"),
+     "fill from not quite top most spot");
+  is_image($fill2, $cmp, "check it filled the lot");
+  ok($fill2->write(file => "testout/t22fill2.ppm"), "save");
+}
+
+{ # verticals
+  my $im = vimage("FFFFFF");
+  my $cmp = vimage("FF0000");
+
+  ok($im->flood_fill(x => 4, y=> 8, color => "FF0000"),
+     "fill at bottom of vertical well");
+  is_image($im, $cmp, "check the result");
+}
+
+unless ($ENV{IMAGER_KEEP_FILES}) {
+  unlink "testout/t22fill1.ppm";
+  unlink "testout/t22fill2.ppm";
+}
+
+# make a vertical test image
+sub vimage {
+  my $c = shift;
+
+  my $im = Imager->new(xsize => 10, ysize => 10);
+  $im->line(x1 => 1, y1 => 1, x2 => 8, y2 => 1, color => $c);
+  $im->line(x1 => 4, y1 => 2, x2 => 4, y2 => 8, color => $c);
+
+  return $im;
+}