]> git.imager.perl.org - imager.git/blob - t/300-transform/020-combine.t
1.012 release
[imager.git] / t / 300-transform / 020-combine.t
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, "combine: empty input image (src->[0])",
38      "check message");
39 }
40
41 {
42   # not an image
43   my $im = {};
44   ok(!Imager->combine(src => [ $im ]), "not an image");
45   is(Imager->errstr, "src must contain image objects", "check message");
46 }
47
48 {
49   # no images
50   ok(!Imager->combine(src => []), "no images");
51   is(Imager->errstr, "At least one image must be supplied",
52      "check message");
53 }
54
55 {
56   # too many images
57   ok(!Imager->combine(src => [ ($test_im) x 5 ]), "too many source images");
58   is(Imager->errstr, "Maximum of 4 channels, you supplied 5",
59      "check message");
60 }
61
62 {
63   # negative channel
64   ok(!Imager->combine(src => [ $test_im ], channels => [ -1 ]),
65      "negative channel");
66   is(Imager->errstr, "Channel numbers must be zero or positive",
67      "check message");
68 }
69
70 {
71   # channel too high
72   ok(!Imager->combine(src => [ $test_im ], channels => [ 3 ]),
73      "too high channel");
74   is(Imager->errstr, "Channel 3 for image 0 is too high (3 channels)",
75      "check message");
76 }
77
78 {
79   # make sure we get the higher of the bits
80   my $out = Imager->combine(src => [ $test_im, $test_im_dbl ]);
81   ok($out, "make from 8 and double/sample images");
82   is($out->bits, "double", "check output bits");
83 }
84
85 {
86   # check high-bit processing
87   # split out channels and put it back together
88   my $red = Imager->combine(src => [ $test_im_dbl ]);
89   ok($red, "extracted the red channel");
90   is($red->getchannels, 1, "red should be a single channel");
91   my $green = Imager->combine(src => [ $test_im_dbl ], channels => [ 1 ]);
92   ok($green, "extracted the green channel");
93   is($green->getchannels, 1, "green should be a single channel");
94   my $blue = $test_im_dbl->convert(preset => "blue");
95   ok($blue, "extracted blue (via convert)");
96
97   # put them back together
98   my $combined = Imager->combine(src => [ $red, $green, $blue ]);
99   is($combined->getchannels, 3, "check we got a three channel image");
100   is_image($combined, $test_im_dbl, "presto! check it's the same");
101   is($combined->bits, "double", "and we got a double image output");
102 }