]> git.draconx.ca Git - liblbx.git/blob - tests/images.at
Trivial manual fixes.
[liblbx.git] / tests / images.at
1 # Copyright © 2013, 2021 Nick Bowler
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 AT_BANNER([Image format tests])
17
18 m4_divert_push([PREPARE_TESTS])dnl
19 # Read the header from a PAM image (from standard input) and set declared
20 # parameters in shell variables.  For example, if the PAM header specifies
21 # DEPTH 2, the shell variable pam_DEPTH will be set to 2.
22 #
23 # Returns a nonzero status if the header could not be parsed.
24 pam_read_header () {
25   pam_save_IFS=$IFS
26   pam_p7_seen=false pam_endhdr_seen=false
27
28   while IFS= read a; do
29     case $a in
30     P7)
31       $pam_p7_seen && break # duplicated header
32       pam_p7_seen=true
33       ;;
34     ENDHDR)
35       pam_endhdr_seen=true
36       break
37       ;;
38     *)
39       IFS=$pam_save_IFS read b c <<EOF
40 $a
41 EOF
42         b=AS_TR_SH([$b])
43         AS_VAR_SET([pam_$b], [$c])
44       ;;
45     esac
46   done
47
48   IFS=$pam_save_IFS
49   $pam_p7_seen && $pam_endhdr_seen
50 }
51
52 pam_check_header () {
53   for pam_arg
54   do
55     AS_UNSET([pam_$pam_arg])
56   done
57
58   pam_read_header || return
59
60   for pam_arg
61   do
62     AS_VAR_SET_IF([pam_$pam_arg],
63       [AS_VAR_COPY([pam_val], [pam_$pam_arg])],
64       [AS_UNSET([pam_val])])
65     AS_ECHO(["$pam_arg${pam_val+ = }${pam_val- unset}"])
66   done
67 }
68 m4_divert_pop([PREPARE_TESTS])
69
70 AT_SETUP([Empty image])
71
72 AT_CHECK([lbximg -F pbm -dnf "$testdata/image-0x0" && cat out.000.pbm], [0],
73 [P1
74 0 0
75 ])
76
77 AT_CLEANUP
78
79 AT_SETUP([PAM output format (no palette)])
80
81 # image-1x1 (no palette)
82 AT_CHECK([lbximg -F pam -dnf "$testdata/image-1x1"])
83 AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
84 [WIDTH = 1
85 HEIGHT = 1
86 DEPTH = 1
87 TUPLTYPE = GRAYSCALE
88 ])
89
90 AT_CLEANUP
91
92 AT_SETUP([PAM output format (no palette + transparency)])
93
94 # image-1x1 (no palette)
95 AT_CHECK([lbximg -F pam -dnf "$testdata/image-1x1-mt"])
96 AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
97 [WIDTH = 1
98 HEIGHT = 1
99 DEPTH = 2
100 TUPLTYPE = GRAYSCALE_ALPHA
101 ])
102
103 AT_CLEANUP
104
105 AT_SETUP([PAM output format (palette)])
106
107 # image-1x1 (no palette)
108 AT_CHECK([lbximg -F pam -df "$testdata/image-1x1" \
109                  -p "$testdata/palette-ramp"])
110 AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
111 [WIDTH = 1
112 HEIGHT = 1
113 DEPTH = 3
114 TUPLTYPE = RGB
115 ])
116
117 AT_CLEANUP
118
119 AT_SETUP([PAM output format (palette + transparency)])
120
121 # image-1x1 (no palette)
122 AT_CHECK([lbximg -F pam -df "$testdata/image-1x1-mt" \
123                  -p "$testdata/palette-ramp"])
124 AT_CHECK([pam_check_header WIDTH HEIGHT DEPTH TUPLTYPE <out.000.pam], [0],
125 [WIDTH = 1
126 HEIGHT = 1
127 DEPTH = 4
128 TUPLTYPE = RGB_ALPHA
129 ])
130
131 AT_CLEANUP