added POD to trans2.c
[imager.git] / t / t58trans2.t
CommitLineData
bf94b653 1BEGIN { $| = 1; print "1..12\n"; }
02d1d628
AMH
2END {print "not ok 1\n" unless $loaded;}
3use Imager;
4
bf94b653
TC
5sub ok($$$);
6
02d1d628
AMH
7$loaded = 1;
8print "ok 1\n";
9
10#$Imager::DEBUG=1;
11
12Imager::init('log'=>'testout/t56trans2.log');
13
14my $im1 = Imager->new();
15$im1->open(file=>'testimg/penguin-base.ppm', type=>'pnm')
16 || die "Cannot read image";
17my $im2 = Imager->new();
18$im2->open(file=>'testimg/scale.ppm',type=>'pnm')
19 || die "Cannot read testimg/scale.ppm";
20
21# error handling
22my $opts = { rpnexpr=>'x x 10 / sin 10 * y + get1' };
23my $im3 = Imager::transform2($opts);
bf94b653
TC
24ok(2, !$im3, "returned an image on error");
25ok(3, defined($Imager::ERRSTR), "No error message on failure");
02d1d628
AMH
26
27# image synthesis
28my $im4 = Imager::transform2({
29 width=>300, height=>300,
30 rpnexpr=>'x y cx cy distance !d y cy - x cx - atan2 !a @d 10 / @a + 3.1416 2 * % !a2 @a2 cy * 3.1416 / 1 @a2 sin 1 + 2 / hsv'});
bf94b653 31ok(4, $im4, "synthesis failed");
02d1d628
AMH
32
33if ($im4) {
34 $im4->write(type=>'pnm', file=>'testout/t56a.ppm')
35 || die "Cannot write testout/t56a.ppm";
36}
37
38# image distortion
39my $im5 = Imager::transform2({
40 rpnexpr=>'x x 10 / sin 10 * y + getp1'
41}, $im1);
bf94b653 42ok(5, $im5, "image distortion");
02d1d628
AMH
43if ($im5) {
44 $im5->write(type=>'pnm', file=>'testout/t56b.ppm')
45 || die "Cannot write testout/t56b.ppm";
46}
47
48# image combination
49$opts = {
50rpnexpr=>'x h / !rat x w2 % y h2 % getp2 !pat x y getp1 @rat * @pat 1 @rat - * +'
51};
52my $im6 = Imager::transform2($opts,$im1,$im2);
bf94b653 53ok(6, $im6, "image combination");
02d1d628
AMH
54if ($im6) {
55 $im6->write(type=>'pnm', file=>'testout/t56c.ppm')
56 || die "Cannot write testout/t56c.ppm";
57}
faa9b3e7
TC
58
59use Imager::Transform;
60
61# some simple tests
62my @funcs = Imager::Transform->list or print "not ";
63print "ok 7\n";
64my $tran = Imager::Transform->new($funcs[0]) or print "not ";
65print "ok 8\n";
66$tran->describe() eq Imager::Transform->describe($funcs[0]) or print "not ";
67print "ok 9\n";
68# look for a function that takes inputs (at least one does)
69my @needsinputs = grep Imager::Transform->new($_)->inputs, @funcs;
70# make sure they're
71my @inputs = Imager::Transform->new($needsinputs[0])->inputs;
72$inputs[0]{desc} or print "not ";
73print "ok 10\n";
74# at some point I might want to test the actual transformations
bf94b653
TC
75
76# check lower level error handling
77my $im7 = Imager::transform2({rpnexpr=>'x y getp2', width=>100, height=>100});
78ok(11, !$im7, "expected failure on accessing invalid image");
79print "# ", Imager->errstr, "\n";
80ok(12, Imager->errstr =~ /not enough images/, "didn't get expected error");
81
82sub ok ($$$) {
83 my ($num, $test, $desc) = @_;
84
85 if ($test) {
86 print "ok $num\n";
87 }
88 else {
89 print "not ok $num # $desc\n";
90 }
91 $test;
92}
93