3 BEGIN { $| = 1; print "1..29\n"; }
5 END {print "not ok 1\n" unless $loaded;}
6 use Imager qw(:all :handy);
10 init_log("testout/t022double.log", 1);
12 use Imager::Color::Float;
14 my $im_g = Imager::i_img_double_new(100, 101, 1);
16 ok(2, Imager::i_img_getchannels($im_g) == 1,
17 "1 channel image channel count mismatch");
18 ok(3, Imager::i_img_getmask($im_g) & 1, "1 channel image bad mask");
19 ok(4, Imager::i_img_virtual($im_g) == 0,
20 "1 channel image thinks it is virtual");
21 my $double_bits = length(pack("d", 1)) * 8;
22 ok(5, Imager::i_img_bits($im_g) == $double_bits,
23 "1 channel image has bits != $double_bits");
24 ok(6, Imager::i_img_type($im_g) == 0, "1 channel image isn't direct");
26 my @ginfo = i_img_info($im_g);
27 ok(7, $ginfo[0] == 100, "1 channel image width incorrect");
28 ok(8, $ginfo[1] == 101, "1 channel image height incorrect");
32 my $im_rgb = Imager::i_img_double_new(100, 101, 3);
34 ok(9, Imager::i_img_getchannels($im_rgb) == 3,
35 "3 channel image channel count mismatch");
36 ok(10, (Imager::i_img_getmask($im_rgb) & 7) == 7, "3 channel image bad mask");
37 ok(11, Imager::i_img_bits($im_rgb) == $double_bits,
38 "3 channel image has bits != $double_bits");
39 ok(12, Imager::i_img_type($im_rgb) == 0, "3 channel image isn't direct");
41 my $redf = NCF(1, 0, 0);
42 my $greenf = NCF(0, 1, 0);
43 my $bluef = NCF(0, 0, 1);
47 Imager::i_plinf($im_rgb, 0, $y, ($redf) x 100);
51 test_colorf_gpix(14, $im_rgb, 0, 0, $redf);
52 test_colorf_gpix(16, $im_rgb, 99, 0, $redf);
53 test_colorf_gpix(18, $im_rgb, 0, 100, $redf);
54 test_colorf_gpix(20, $im_rgb, 99, 100, $redf);
55 test_colorf_glin(22, $im_rgb, 0, 0, ($redf) x 100);
56 test_colorf_glin(24, $im_rgb, 0, 100, ($redf) x 100);
58 Imager::i_plinf($im_rgb, 20, 1, ($greenf) x 60);
59 test_colorf_glin(26, $im_rgb, 0, 1,
60 ($redf) x 20, ($greenf) x 60, ($redf) x 20);
63 my $oo16img = Imager->new(xsize=>200, ysize=>201, bits=>16)
66 $oo16img->bits == 16 or print "not ";
71 return Imager::Color::Float->new(@_);
74 sub test_colorf_gpix {
75 my ($test_base, $im, $x, $y, $expected) = @_;
76 my $c = Imager::i_gpixf($im, $x, $y);
78 print "ok ",$test_base++,"\n";
79 colorf_cmp($c, $expected) == 0 or print "not ";
80 print "ok ",$test_base++,"\n";
83 sub test_colorf_glin {
84 my ($test_base, $im, $x, $y, @pels) = @_;
86 my @got = Imager::i_glinf($im, $x, $x+@pels, $y);
87 @got == @pels or print "not ";
88 print "ok ",$test_base++,"\n";
89 grep(colorf_cmp($pels[$_], $got[$_]), 0..$#got) and print "not ";
90 print "ok ",$test_base++,"\n";
95 my @s1 = map { int($_*65535.99) } $c1->rgba;
96 my @s2 = map { int($_*65535.99) } $c2->rgba;
98 # print "# (",join(",", @s1[0..2]),") <=> (",join(",", @s2[0..2]),")\n";
99 return $s1[0] <=> $s2[0]
101 || $s1[2] <=> $s2[2];
105 my ($test_num, $ok, $comment) = @_;
108 print "ok $test_num\n";
111 print "not ok $test_num # $comment\n";