1 Imager::init("log"=>'testout/t67convert.log');
3 use Imager qw(:all :handy);
7 my $imbase = Imager::ImgRaw::new(200,300,3);
9 # first a basic test, make sure the basic things happen ok
10 # make a 1 channel image from the above (black) image
11 # but with 1 as the 'extra' value
12 my $imnew = Imager::i_img_new();
13 unless (i_convert($imnew, $imbase, [ [ 0, 0, 0, 1 ] ])) {
14 print "not ok 1 # call failed\n";
15 print "ok 2 # skipped\n";
16 print "ok 3 # skipped\n";
20 my ($w, $h, $ch) = i_img_info($imnew);
22 # the output image should now have one channel
27 print "not ok 2 # $ch channels in output\n";
29 # should have the same width and height
30 if ($w == 200 && $h == 300) {
34 print "not ok 3 # output image is the wrong size!\n";
36 # should be a white image now, let's check
37 my $c = Imager::i_get_pixel($imnew, 20, 20);
40 if (($c->rgba())[0] == 255) {
44 print "not ok 4 # wrong colour in output image",($c->rgba())[0],"\n";
48 # test the highlevel interface
49 # currently this requires visual inspection of the output files
51 if ($im->read(file=>'testimg/scale.ppm')) {
54 $out = $im->convert(preset=>'gray')
57 if ($out->write(file=>'testout/t67_gray.ppm', type=>'pnm')) {
61 print "not ok 7 # Cannot save testout/t67_gray.ppm:", $out->errstr,"\n";
63 $out = $im->convert(preset=>'blue')
67 if ($out->write(file=>'testout/t67_blue.ppm', type=>'pnm')) {
71 print "not ok 9 # Cannot save testout/t67_blue.ppm:", $out->errstr, "\n";
75 print "not ok 5 # could not load testout/scale.ppm\n";
76 print map "ok $_ # skipped\n", 6..9;
79 # test against 16-bit/sample images
80 my $im16targ = Imager::i_img_16_new(200, 300, 3);
81 unless (i_convert($im16targ, $imbase, [ [ 0, 0, 0, 1 ],
84 print "not ok 10 # call failed\n";
85 print map "ok $_ # skipped\n", 11..12;
90 # image should still be 16-bit
91 Imager::i_img_bits($im16targ) == 16
94 # make sure that it's roughly red
95 my $c = Imager::i_gpixf($im16targ, 0, 0);
97 abs($ch[0] - 1) <= 0.0001 && abs($ch[1]) <= 0.0001 && abs($ch[2]) <= 0.0001
102 # test against palette based images
103 my $impal = Imager::i_img_pal_new(200, 300, 3, 256);
104 my $black = NC(0, 0, 0);
105 my $blackindex = Imager::i_addcolors($impal, $black)
109 Imager::i_ppal($impal, 0, $y, ($black) x 200);
111 my $impalout = Imager::i_img_pal_new(200, 300, 3, 256);
112 if (i_convert($impalout, $impal, [ [ 0, 0, 0, 0 ],
115 Imager::i_img_type($impalout) == 1 or print "not ";
117 Imager::i_colorcount($impalout) == 1 or print "not ";
119 my $c = Imager::i_getcolors($impalout, $blackindex) or print "not ";
123 $ch[0] == 0 && $ch[1] == 255 && $ch[2] == 0
128 print "not ok 14 # could not convert paletted image\n";
129 print map "ok $_ # skipped\n", 15..17;