]> git.imager.perl.org - imager.git/blob - t/t66paste.t
- attempt to work around the test failure at
[imager.git] / t / t66paste.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 23;
4
5 BEGIN { use_ok("Imager") }
6
7 #$Imager::DEBUG=1;
8
9 Imager::init('log'=>'testout/t66paste.log');
10
11 # the original smoke tests
12 my $img=Imager->new() || die "unable to create image object\n";
13
14 ok($img->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img");
15
16 my $nimg=Imager->new() or die "Unable to create image object\n";
17 ok($nimg->open(file=>'testimg/scale.ppm',type=>'pnm'), "load test img again");
18
19 ok($img->paste(img=>$nimg, top=>30, left=>30), "paste it")
20   or print "# ", $img->errstr, "\n";;
21
22 ok($img->write(type=>'pnm',file=>'testout/t66.ppm'), "save it")
23   or print "# ", $img->errstr, "\n";
24
25 # more stringent tests
26 {
27   my $src = Imager->new(xsize => 100, ysize => 110);
28   $src->box(filled=>1, color=>'FF0000');
29
30   $src->box(filled=>1, color=>'0000FF', xmin => 20, ymin=>20,
31             xmax=>79, ymax=>79);
32
33   my $targ = Imager->new(xsize => 100, ysize => 110);
34   $targ->box(filled=>1, color =>'00FFFF');
35   $targ->box(filled=>1, color=>'00FF00', xmin=>20, ymin=>20, xmax=>79,
36              ymax=>79);
37   my $work = $targ->copy;
38   ok($work->paste(src=>$src, left => 15, top => 10), "paste whole image");
39   # build comparison image
40   my $cmp = $targ->copy;
41   $cmp->box(filled=>1, xmin=>15, ymin => 10, color=>'FF0000');
42   $cmp->box(filled=>1, xmin=>35, ymin => 30, xmax=>94, ymax=>89, 
43             color=>'0000FF');
44
45   is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
46      "compare pasted and expected");
47
48   $work = $targ->copy;
49   ok($work->paste(src=>$src, left=>2, top=>7, src_minx => 10, src_miny => 15),
50      "paste from inside src");
51   $cmp = $targ->copy;
52   $cmp->box(filled=>1, xmin=>2, ymin=>7, xmax=>91, ymax=>101, color=>'FF0000');
53   $cmp->box(filled=>1, xmin=>12, ymin=>12, xmax=>71, ymax=>71, 
54             color=>'0000FF');
55   is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
56      "compare pasted and expected");
57
58   # paste part source
59   $work = $targ->copy;
60   ok($work->paste(src=>$src, left=>15, top=>20, 
61                   src_minx=>10, src_miny=>15, src_maxx=>80, src_maxy =>70),
62      "paste src cropped all sides");
63   $cmp = $targ->copy;
64   $cmp->box(filled=>1, xmin=>15, ymin=>20, xmax=>84, ymax=>74, 
65             color=>'FF0000');
66   $cmp->box(filled=>1, xmin=>25, ymin=>25, xmax=>84, ymax=>74,
67             color=>'0000FF');
68   is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
69      "compare pasted and expected");
70
71   # go by width instead
72   $work = $targ->copy;
73   ok($work->paste(src=>$src, left=>15, top=>20,
74                   src_minx=>10, src_miny => 15, width => 70, height => 55),
75      "same but specify width/height instead");
76   is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
77      "compare pasted and expected");
78
79   # use src_coords
80   $work = $targ->copy;
81   ok($work->paste(src=>$src, left => 15, top => 20,
82                   src_coords => [ 10, 15, 80, 70 ]),
83      "using src_coords");
84   is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
85      "compare pasted and expected");
86
87   {
88     # Issue #18712
89     # supplying just src_maxx would set the internal maxy to undef
90     # supplying just src_maxy would be ignored
91     # src_maxy (or it's derived value) was being bounds checked against 
92     # the image width instead of the image height
93     $work = $targ->copy;
94     my @warns;
95     local $SIG{__WARN__} = sub { push @warns, "@_"; print "# @_"; };
96     
97     ok($work->paste(src=>$src, left => 15, top => 20,
98                     src_maxx => 50),
99        "paste with just src_maxx");
100     ok(!@warns, "shouldn't warn");
101     my $cmp = $targ->copy;
102     $cmp->box(filled=>1, color => 'FF0000', xmin => 15, ymin => 20,
103               xmax => 64, ymax => 109);
104     $cmp->box(filled=>1, color => '0000FF', xmin => 35, ymin => 40,
105               xmax => 64, ymax => 99);
106     is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
107        "check correctly pasted");
108
109     $work = $targ->copy;
110     @warns = ();
111     ok($work->paste(src=>$src, left=>15, top=>20,
112                     src_maxy => 60),
113        "paste with just src_maxy");
114     ok(!@warns, "shouldn't warn");
115     $cmp = $targ->copy;
116     $cmp->box(filled => 1, color => 'FF0000', xmin => 15, ymin => 20,
117               xmax => 99, ymax => 79);
118     $cmp->box(filled => 1, color => '0000FF', xmin => 35, ymin => 40,
119               xmax => 94, ymax => 79);
120     is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
121        "check pasted correctly");
122
123     $work = $targ->copy;
124     @warns = ();
125     ok($work->paste(src=>$src, left=>15, top=>20,
126                     src_miny => 20, src_maxy => 105),
127        "paste with src_maxy > source width");
128
129     $cmp = $targ->copy;
130     $cmp->box(filled => 1, color => 'FF0000', xmin => 15, ymin => 20,
131               ymax => 104);
132     $cmp->box(filled => 1, color => '0000FF', xmin => 35, ymin => 20,
133               xmax => 94, ymax => 79);
134     is(Imager::i_img_diff($work->{IMG}, $cmp->{IMG}), 0,
135        "check pasted correctly");
136   }
137 }