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