3 use Test::More tests => 15;
5 use Imager::Test qw(is_image);
7 -d "testout" or mkdir "testout";
9 { # flood_fill wouldn't fill to the right if the area was just a
11 my $im = Imager->new(xsize => 5, ysize => 3);
12 ok($im, "make flood_fill test image");
13 ok($im->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "white"),
15 ok($im->flood_fill(x => 3, y => 1, color => "blue"),
17 my $cmp = Imager->new(xsize => 5, ysize => 3);
18 ok($cmp, "make test image");
19 ok($cmp->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "blue"),
20 "synthezied filled area");
21 is_image($im, $cmp, "flood_fill filled horizontal line");
25 { # flood_fill won't fill entire line below if line above is shorter
26 my $im = Imager->new(file => "testimg/filltest.ppm");
27 ok($im, "Load test image")
28 or skip("Couldn't load test image: " . Imager->errstr, 3);
30 # fill from first bad place
31 my $fill1 = $im->copy;
32 ok($fill1->flood_fill(x => 8, y => 2, color => "#000000"),
33 "fill from a top most spot");
34 my $cmp = Imager->new(xsize => $im->getwidth, ysize => $im->getheight);
35 is_image($fill1, $cmp, "check it filled the lot");
36 ok($fill1->write(file => "testout/t22fill1.ppm"), "save");
39 my $fill2 = $im->copy;
40 ok($fill2->flood_fill(x => 17, y => 3, color => "#000000"),
41 "fill from not quite top most spot");
42 is_image($fill2, $cmp, "check it filled the lot");
43 ok($fill2->write(file => "testout/t22fill2.ppm"), "save");
47 my $im = vimage("FFFFFF");
48 my $cmp = vimage("FF0000");
50 ok($im->flood_fill(x => 4, y=> 8, color => "FF0000"),
51 "fill at bottom of vertical well");
52 is_image($im, $cmp, "check the result");
55 unless ($ENV{IMAGER_KEEP_FILES}) {
56 unlink "testout/t22fill1.ppm";
57 unlink "testout/t22fill2.ppm";
60 # make a vertical test image
64 my $im = Imager->new(xsize => 10, ysize => 10);
65 $im->line(x1 => 1, y1 => 1, x2 => 8, y2 => 1, color => $c);
66 $im->line(x1 => 4, y1 => 2, x2 => 4, y2 => 8, color => $c);