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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
.TH LIBQUANTA_QUANTISE 3 libquanta
.SH NAME
libquanta_quantise \- Colour-quantise an image
.SH SYNPOSIS
.nf
#include <libquanta.h>
\fBstruct libquanta_image\fP {
size_t \fIwidth\fP;
size_t \fIheight\fP;
size_t \fIimage\fP[];
};
\fBstruct libquanta_palette\fP {
size_t \fIsize\fP;
uint64_t \fIpalette\fP[];
};
\fBstruct libquanta_channel\fP {
size_t \fIbits_in\fP;
size_t \fIbits_out\fP;
size_t \fIimage_width\fP;
size_t \fIimage_height\fP;
size_t \fIimage_row_size\fP;
size_t \fIimage_cell_size\fP;
const void *\fIimage\fP;
};
struct libquanta_image *\fBlibquanta_quantise\fP(struct libquanta_palette *\fIpalette\fP, ...);
struct libquanta_image *\fBlibquanta_vquantise\fP(struct libquanta_palette *\fIpalette\fP, va_list \fIargs\fP);
.fi
.PP
Link with
.I -lquanta
.IR -lm .
.SH DESCRIPTION
The
.BR libquanta_quantise ()
creates and returnes a colour-quantised image from
input image and desired palette size.
.PP
.I palette->size
shall the desired palette size: the maximum number
of colours. This value must be at least 1.
.I *palette
may be otherwise uninitialised.
.PP
Upon successful completion,
.I palette->size
will be set to the actual number of colours stored
in the palette, which will not exceed the input
value of
.IR palette->size.
Additionally,
.I palette->palette
will be filled with the colours in the colour
palette choosen by the function. For a colour index
.I i
(integer within [0,
.IR palette->size )
(using the output value of
.IR palette->size ))
and channel index
.I j
(integer within [0,
.IR n ),
where
.I n
is the number of colour channels (the number of
arguments between
.I palette
and the
.I NULL
at the end of the argument list),
.I palette->palette[i*n+j]
is the value of the
.IR j -th
primary colour of the
.IR i -th
palette colour.
On failure, arbitrary values may be stored in
.IR palette->palette .
.PP
After
.I palette
the caller shall provide one
.B const struct libquanta_channel *
per primary colour (at least one) in the image's
colour model. This list shall be terminated by a
.I NULL
as the final argument.
For each such argument,
.I .bits_in
shall be the number of bits used to stored colour
values for that colour channel in the input image.
This value must be at least 1, but no greater than 64.
.I .bits_out
shall be the number of bits used to stored colour
values for that colour channel in the output colour
palette. This value must be at least 1, but no
greater than
.IR .bits_in .
.I .image_width
shall be the number of pixels the image is wide.
.I .image_height
shall be the number of pixels the image is tall.
.IR .image ,
.IR .image_row_size ,
and
.IR image_cell_size
shall be configured so that
.I &((const char *).image)[y * .image_row_size + x * .image_cell_size]
points to the value of pixel
.RI ( x ,
.IR y )
for the colour channel.
Although the naming of
.I .image_row_size
and
.I .image_cell_size
imply row-major layout, column-major layout
is also supported. If
.I .bits_in
is between 1 and 8 (inclusively),
values in
.I .image
shall use the type
.BR uint8_t .
If
.I .bits_in
is between 9 and 16,
.B uint16_t
is used. If
.I .bits_in
is between 17 and 32,
.B uint32_t
is used. If
.I .bits_in
is between 33 and 64,
.B uint64_t
is used.
.PP
For the returned
.BR "struct libquanta_image" ,
.I width
will be set to the image width
.RI ( .image_width
used for the input
.IR "struct libquanta_channel" s),
.I height
will be set to the image height
.RI ( .image_height
used for the input
.IR "struct libquanta_channel" s),
and
.I .image[y*.width+x]
for each
.I y
in [0,
.IR .height )
and each
.I x
in [0,
.IR .width )
will be set to the index of the
palette colour selected for pixel
.RI ( x ,
.IR y ),
will be less than the value assigned to
.I palette->size
when the function returns.
.PP
Unused elements in
.I palette->palette
may remain uninitialised or contain
arbitrary values when the function
returns.
.PP
The
.BR libquanta_vquantise ()
function is a variant of the
.BR libquanta_quantise ()
function, that uses
.I va_list args
to hold variadic arguments.
.SH RETURN VALUE
Upon successful completion, the
.BR libquanta_quantise (3)
and
.BR libquanta_vquantise (3)
functions return a pointer to a newly
allocated colour-quantised image. The
caller is responsible for deallocating
the image by calling the
.BR free (3)
with the returned pointer.
On failure, the functions return
.I NULL
and set
.I errno
to indicate the error.
.SH ERRORS
The
.BR libquanta_quantise ()
and
.BR libquanta_vquantise ()
functions will fail if:
.TP
.B EINVAL
.I palette
is
.IR NULL .
.TP
.B EINVAL
.I palette->size
is 0.
.TP
.B EINVAL
No colour cannel is provided (the first
variadic argument is
.IR NULL ).
.TP
.B EINVAL
At least one of the colour channel descriptions
have an invalid configuration
.RI ( .bits_in
is less than 1 or greater than 64, or
.I .bits_out
is less than 1 or greater than
.IR .bits_in ).
.TP
.B EINVAL
The colour channel descriptions do not have the
same image dimensions configured.
.TP
.B ENOMEM
Storage space available is insufficient.
.SH SEE ALSO
.BR libquanta (7),
.BR libquanta_malloc_palette (3),
.BR libquanta_quantise_wu (3)
|