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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
.TH LIBLSS16_DECODE_TO_COLOUR_INDEX 3 LIBLSS16
.SH NAME
liblss16_decode_to_colour_index \- Decode an LSS16 image file
.SH SYNOPSIS
.nf
#include <liblss16.h>
enum liblss16_decode_state {
LIBLSS16_DECODE_RUNNING,
LIBLSS16_DECODE_END_OF_IMAGE,
LIBLSS16_DECODE_ERROR
};
enum liblss16_decode_error {
LIBLSS16_DECODE_TRUNCATED_MAGIC,
LIBLSS16_DECODE_BAD_MAGIC,
LIBLSS16_DECODE_TRUNCATED_HEADER,
LIBLSS16_DECODE_BAD_IMAGE_SIZE,
LIBLSS16_DECODE_BAD_COLOUR,
LIBLSS16_DECODE_BAD_ROW_PADDING,
LIBLSS16_DECODE_EXCESSIVE_RUN_LENGTH,
LIBLSS16_DECODE_TRUNCATED_IMAGE
};
struct liblss16_colour {
uint8_t \fIr\fP;
uint8_t \fIg\fP;
uint8_t \fIb\fP;
};
struct liblss16_header {
uint16_t \fIwidth\fP;
uint16_t \fIheight\fP;
struct liblss16_colour \fIcolour_map\fP[16];
};
struct liblss16_decoder {
struct liblss16_header \fIimage\fP;
/* internal fields omitted */
};
enum liblss16_decode_state liblss16_decode_to_colour_index(
struct liblss16_decoder *\fIdecoder\fP,
const void *\fIdata\fP, size_t \fIlength\fP, size_t *\fIconsumed_out\fP,
uint8_t *\fIpixels\fP, size_t \fIpixels_size\fP, size_t *\fInpixels_out\fP,
enum liblss16_decode_error *\fIerror_out\fP);
.fi
.PP
Link with
.IR -llss16 .
.SH DESCRIPTION
The
.BR liblss16_decode_to_colour_index ()
function decodes an image encoded in the LSS16 file format.
Before the decoding of a file is started
.I decoder
must be initialised with the
.BR liblss16_decoder_init (3)
function. The function is then repeatedly while it returns
.IR LIBLSS16_DECODE_RUNNING .
.PP
For each call, currently available file content is input in the
.I data
parameter, and the number of available bytes is input in the
.I length
parameter. After each call, the application shall discard the
.I *consumed_out
first bytes of
.I data
and decrease
.I length
by the same amount, but it may also append newly available
data, and increase
.I length
correspondingly.
.PP
The call shall provide a buffer for at least one pixel in the
.I pixels
parameter, and specify the number of pixels the buffer can
store in the
.I pixels_size
parameter. The function will set
.I *npixels_out
to the number of pixels output to the beginning of
.IR pixels .
Each pixel is encoded with a colour index, which is a non-negative
integer 15 or less. The function will set
.I decoder->image
the first time it sets
.I *npixels_out
to a non-zero value, or earlier. At this time, the width or height
of the image, in number of pixels, can be looked up in
.I decoder->image.width
and
.I decoder->image.height
respectively. Additionally the colour palette is also set, so the
colours of the returned pixels can be looked up. If the value
.I P
is returned for a pixel,
.I decoder->image.colour_map[P]
is a
.B struct liblss16_colour
that describes the pixel's colour;
.I .r
is an unsigned 8-bit integer value for the red component
of the pixel's sRGB colour, likewise
.I .g
is the green value and
.I .b
is the blue value.
.PP
.I decoder
must not be
.IR NULL .
.PP
.I data
may only be
.I NULL
if
.I length
is 0, which is used while still decoding
after then end of the file has been reached.
.PP
.I consumed_out
must not be
.IR NULL .
.PP
.I pixels
must not be null
.IR NULL ,
and
.I pixels_size
must not be 0.
.PP
.I npixels_out
must not be
.IR NULL .
.PP
.I error_out
shall either be
.I NULL
or a pointer to where the error code shall be
stored should the function fail.
.SH RETURN VALUE
The
.BR liblss16_decode_to_colour_index ()
function will returns the following values:
.TP
.B LIBLSS16_DECODE_RUNNING
The end of the image has not yet been reached.
The file if truncated if the end of the file is reached.
.TP
.B LIBLSS16_DECODE_END_OF_IMAGE
The end of the image is reched.
If the end of the file has not yet been reached, it
contains extraneous data.
.TP
.B LIBLSS16_DECODE_ERROR
A decoding error has occured, and processing most be
aborted. This always indicate that the file is corrupted
or not an LSS16 file.
.I *error_out
will be se to indicate the error unless
.I error_out
is
.IR NULL .
.PP
Note that
.I *npixels_out
and
.I *consumed_out
are always set.
.SH ERRORS
The
.BR liblss16_decode_to_colour_index ()
function fails for the following reasons:
.TP
.B LIBLSS16_DECODE_TRUNCATED_MAGIC
The file contains up to the first three bytes of the
LSS16 magic number, but is truncated and does not
contain the fourth byte.
.TP
.B LIBLSS16_DECODE_BAD_MAGIC
The file does not begin with the LSS16 magic number.
.TP
.B LIBLSS16_DECODE_TRUNCATED_HEADER
The file is too short to contain the full header.
.TP
.B LIBLSS16_DECODE_BAD_IMAGE_SIZE
The image width is 0, the image height is 0, or
the image height exceeds 32767.
.I decoder->image.width
and
.I decoder->image.height
will be set so each of the reasons apply can be
determined.
.TP
.B LIBLSS16_DECODE_BAD_COLOUR
The file is corrupt and the colour palette contains
a value greater than 63.
.TP
.B LIBLSS16_DECODE_BAD_ROW_PADDING
The file is corrupt and contains non-zero row padding.
.TP
.B LIBLSS16_DECODE_EXCESSIVE_RUN_LENGTH
The file is corrupt and contains a run length
crossing two or more rows of pixels.
.TP
.B LIBLSS16_DECODE_TRUNCATED_IMAGE
The file contains the full header, but is truncated
and does not contain the full image data.
.SH SEE ALSO
.BR liblss16_decode_strerror (3),
.BR liblss16_encode_from_colour_index (3),
.BR liblss16 (7)
|