File: 020-combine.t

package info (click to toggle)
libimager-perl 1.027%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,820 kB
  • sloc: perl: 32,971; ansic: 28,092; makefile: 52; cpp: 4
file content (102 lines) | stat: -rw-r--r-- 3,160 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!perl -w
use strict;
use Imager;
use Test::More tests => 31;
use Imager::Test qw/test_image test_image_double is_image/;

my $test_im = test_image;
my $test_im_dbl = test_image_double;

{
  # split out channels and put it back together
  my $red = Imager->combine(src => [ $test_im ]);
  ok($red, "extracted the red channel");
  is($red->getchannels, 1, "red should be a single channel");
  my $green = Imager->combine(src => [ $test_im ], channels => [ 1 ]);
  ok($green, "extracted the green channel");
  is($green->getchannels, 1, "green should be a single channel");
  my $blue = $test_im->convert(preset => "blue");
  ok($blue, "extracted blue (via convert)");

  # put them back together
  my $combined = Imager->combine(src => [ $red, $green, $blue ]);
  is($combined->getchannels, 3, "check we got a three channel image");
  is_image($combined, $test_im, "presto! check it's the same");
}

{
  # no src
  ok(!Imager->combine(), "no src");
  is(Imager->errstr, "src parameter missing", "check message");
}

{
  # bad image error
  my $im = Imager->new;
  ok(!Imager->combine(src => [ $im ]), "empty image");
  is(Imager->errstr, "combine: empty input image (src->[0])",
     "check message");
}

{
  # not an image
  my $im = {};
  ok(!Imager->combine(src => [ $im ]), "not an image");
  is(Imager->errstr, "src must contain image objects", "check message");
}

{
  # no images
  ok(!Imager->combine(src => []), "no images");
  is(Imager->errstr, "At least one image must be supplied",
     "check message");
}

{
  # too many images
  ok(!Imager->combine(src => [ ($test_im) x 5 ]), "too many source images");
  is(Imager->errstr, "Maximum of 4 channels, you supplied 5",
     "check message");
}

{
  # negative channel
  ok(!Imager->combine(src => [ $test_im ], channels => [ -1 ]),
     "negative channel");
  is(Imager->errstr, "Channel numbers must be zero or positive",
     "check message");
}

{
  # channel too high
  ok(!Imager->combine(src => [ $test_im ], channels => [ 3 ]),
     "too high channel");
  is(Imager->errstr, "Channel 3 for image 0 is too high (3 channels)",
     "check message");
}

{
  # make sure we get the higher of the bits
  my $out = Imager->combine(src => [ $test_im, $test_im_dbl ]);
  ok($out, "make from 8 and double/sample images");
  is($out->bits, "double", "check output bits");
}

{
  # check high-bit processing
  # split out channels and put it back together
  my $red = Imager->combine(src => [ $test_im_dbl ]);
  ok($red, "extracted the red channel");
  is($red->getchannels, 1, "red should be a single channel");
  my $green = Imager->combine(src => [ $test_im_dbl ], channels => [ 1 ]);
  ok($green, "extracted the green channel");
  is($green->getchannels, 1, "green should be a single channel");
  my $blue = $test_im_dbl->convert(preset => "blue");
  ok($blue, "extracted blue (via convert)");

  # put them back together
  my $combined = Imager->combine(src => [ $red, $green, $blue ]);
  is($combined->getchannels, 3, "check we got a three channel image");
  is_image($combined, $test_im_dbl, "presto! check it's the same");
  is($combined->bits, "double", "and we got a double image output");
}