]>
Commit | Line | Data |
---|---|---|
b47464c1 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use Imager; | |
4 | use Test::More tests => 31; | |
5 | use Imager::Test qw/test_image test_image_double is_image/; | |
6 | ||
7 | my $test_im = test_image; | |
8 | my $test_im_dbl = test_image_double; | |
9 | ||
10 | { | |
11 | # split out channels and put it back together | |
12 | my $red = Imager->combine(src => [ $test_im ]); | |
13 | ok($red, "extracted the red channel"); | |
14 | is($red->getchannels, 1, "red should be a single channel"); | |
15 | my $green = Imager->combine(src => [ $test_im ], channels => [ 1 ]); | |
16 | ok($green, "extracted the green channel"); | |
17 | is($green->getchannels, 1, "green should be a single channel"); | |
18 | my $blue = $test_im->convert(preset => "blue"); | |
19 | ok($blue, "extracted blue (via convert)"); | |
20 | ||
21 | # put them back together | |
22 | my $combined = Imager->combine(src => [ $red, $green, $blue ]); | |
23 | is($combined->getchannels, 3, "check we got a three channel image"); | |
24 | is_image($combined, $test_im, "presto! check it's the same"); | |
25 | } | |
26 | ||
27 | { | |
28 | # no src | |
29 | ok(!Imager->combine(), "no src"); | |
30 | is(Imager->errstr, "src parameter missing", "check message"); | |
31 | } | |
32 | ||
33 | { | |
34 | # bad image error | |
35 | my $im = Imager->new; | |
36 | ok(!Imager->combine(src => [ $im ]), "empty image"); | |
37 | is(Imager->errstr, "empty input image", "check message"); | |
38 | } | |
39 | ||
40 | { | |
41 | # not an image | |
42 | my $im = {}; | |
43 | ok(!Imager->combine(src => [ $im ]), "not an image"); | |
44 | is(Imager->errstr, "src must contain image objects", "check message"); | |
45 | } | |
46 | ||
47 | { | |
48 | # no images | |
49 | ok(!Imager->combine(src => []), "no images"); | |
50 | is(Imager->errstr, "At least one image must be supplied", | |
51 | "check message"); | |
52 | } | |
53 | ||
54 | { | |
55 | # too many images | |
56 | ok(!Imager->combine(src => [ ($test_im) x 5 ]), "too many source images"); | |
57 | is(Imager->errstr, "Maximum of 4 channels, you supplied 5", | |
58 | "check message"); | |
59 | } | |
60 | ||
61 | { | |
62 | # negative channel | |
63 | ok(!Imager->combine(src => [ $test_im ], channels => [ -1 ]), | |
64 | "negative channel"); | |
65 | is(Imager->errstr, "Channel numbers must be zero or positive", | |
66 | "check message"); | |
67 | } | |
68 | ||
69 | { | |
70 | # channel too high | |
71 | ok(!Imager->combine(src => [ $test_im ], channels => [ 3 ]), | |
72 | "too high channel"); | |
73 | is(Imager->errstr, "Channel 3 for image 0 is too high (3 channels)", | |
74 | "check message"); | |
75 | } | |
76 | ||
77 | { | |
78 | # make sure we get the higher of the bits | |
79 | my $out = Imager->combine(src => [ $test_im, $test_im_dbl ]); | |
80 | ok($out, "make from 8 and double/sample images"); | |
81 | is($out->bits, "double", "check output bits"); | |
82 | } | |
83 | ||
84 | { | |
85 | # check high-bit processing | |
86 | # split out channels and put it back together | |
87 | my $red = Imager->combine(src => [ $test_im_dbl ]); | |
88 | ok($red, "extracted the red channel"); | |
89 | is($red->getchannels, 1, "red should be a single channel"); | |
90 | my $green = Imager->combine(src => [ $test_im_dbl ], channels => [ 1 ]); | |
91 | ok($green, "extracted the green channel"); | |
92 | is($green->getchannels, 1, "green should be a single channel"); | |
93 | my $blue = $test_im_dbl->convert(preset => "blue"); | |
94 | ok($blue, "extracted blue (via convert)"); | |
95 | ||
96 | # put them back together | |
97 | my $combined = Imager->combine(src => [ $red, $green, $blue ]); | |
98 | is($combined->getchannels, 3, "check we got a three channel image"); | |
99 | is_image($combined, $test_im_dbl, "presto! check it's the same"); | |
100 | is($combined->bits, "double", "and we got a double image output"); | |
101 | } |