From 95b9922f0bef150a10368b54d97dfbf009f5b200 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sun, 26 Sep 2010 02:28:40 +0000 Subject: [PATCH] fix flood_fill some more --- Changes | 6 ++++- MANIFEST | 1 + draw.c | 2 +- t/t21draw.t | 16 +------------ t/t22flood.t | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 t/t22flood.t diff --git a/Changes b/Changes index 416427c7..bfda5780 100644 --- 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 ============== diff --git a/MANIFEST b/MANIFEST index dc9d06ef..4fca21b6 100644 --- 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 0dfd7578..1c04efbf 100644 --- 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--; } diff --git a/t/t21draw.t b/t/t21draw.t index 28b62bbb..eed43e63 100644 --- a/t/t21draw.t +++ b/t/t21draw.t @@ -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 index 00000000..9224090e --- /dev/null +++ b/t/t22flood.t @@ -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; +} -- 2.30.2