3 BEGIN { $| = 1; print "1..23\n"; }
4 END {print "not ok 1\n" unless $loaded;}
5 use Imager qw(:all :handy);
8 init_log("testout/t69rubthru.log", 1);
11 my $targ = Imager::ImgRaw::new(100, 100, 3);
12 my $src = Imager::ImgRaw::new(80, 80, 4);
13 my $halfred = NC(255, 0, 0, 128);
14 i_box_filled($src, 20, 20, 60, 60, $halfred);
15 i_rubthru($targ, $src, 10, 10) or print "not ";
17 my $c = Imager::i_get_pixel($targ, 10, 10) or print "not ";
19 color_cmp($c, NC(0, 0, 0)) == 0 or print "not ";
21 $c = Imager::i_get_pixel($targ, 30, 30) or print "not ";
23 color_cmp($c, NC(128, 0, 0)) == 0 or print "not ";
26 my $black = NC(0, 0, 0);
27 # reset the target and try a grey+alpha source
28 i_box_filled($targ, 0, 0, 100, 100, $black);
29 my $gsrc = Imager::ImgRaw::new(80, 80, 2);
30 my $halfwhite = NC(255, 128, 0);
31 i_box_filled($gsrc, 20, 20, 60, 60, $halfwhite);
32 i_rubthru($targ, $gsrc, 10, 10) or print "not ";
34 $c = Imager::i_get_pixel($targ, 15, 15) or print "not ";
36 color_cmp($c, NC(0, 0, 0)) == 0 or print "not ";
38 $c = Imager::i_get_pixel($targ, 30, 30) or print "not ";
40 color_cmp($c, NC(128, 128, 128)) == 0 or print "not ";
43 # try grey target and grey alpha source
44 my $gtarg = Imager::ImgRaw::new(100, 100, 1);
45 i_rubthru($gtarg, $gsrc, 10, 10) or print "not ";
47 $c = Imager::i_get_pixel($gtarg, 10, 10) or print "not ";
49 ($c->rgba)[0] == 0 or print "not ";
51 (Imager::i_get_pixel($gtarg, 30, 30)->rgba)[0] == 128 or print "not ";
54 # an attempt rub a 4 channel image over 1 channel should fail
55 i_rubthru($gtarg, $src, 10, 10) and print "not ";
58 # simple test for 16-bit/sample images
59 my $targ16 = Imager::i_img_16_new(100, 100, 3);
60 i_rubthru($targ16, $src, 10, 10) or print "not ";
62 $c = Imager::i_get_pixel($targ16, 30, 30) or print "not ";
64 color_cmp($c, NC(128, 0, 0)) == 0 or print "not ";
67 # check the OO interface
68 my $ootarg = Imager->new(xsize=>100, ysize=>100);
69 my $oosrc = Imager->new(xsize=>80, ysize=>80, channels=>4);
70 $oosrc->box(color=>$halfred, xmin=>20, ymin=>20, xmax=>60, ymax=>60,
72 $ootarg->rubthrough(src=>$oosrc, tx=>10, ty=>10) or print "not ";
74 color_cmp(Imager::i_get_pixel($ootarg->{IMG}, 10, 10), NC(0, 0, 0)) == 0
77 color_cmp(Imager::i_get_pixel($ootarg->{IMG}, 30, 30), NC(128, 0, 0)) == 0
81 # make sure we fail as expected
82 my $oogtarg = Imager->new(xsize=>100, ysize=>100, channels=>1);
83 $oogtarg->rubthrough(src=>$oosrc) and print "not ";
91 print "# (",join(",", @l[0..2]),") <=> (",join(",", @r[0..2]),")\n";
92 return $l[0] <=> $r[0]