document the new test image functions
[imager.git] / imext.c
CommitLineData
92bda632
TC
1#include "imexttypes.h"
2#include "imager.h"
50c75381 3#include "imio.h"
92bda632
TC
4
5/*
6 DON'T ADD CASTS TO THESE
7*/
8im_ext_funcs imager_function_table =
9 {
d1f5892c
TC
10 IMAGER_API_VERSION,
11 IMAGER_API_LEVEL,
12
92bda632
TC
13 mymalloc,
14 myfree,
15 myrealloc,
16
e310e5f9
TC
17 mymalloc_file_line,
18 myfree_file_line,
19 myrealloc_file_line,
20
92bda632
TC
21 i_img_8_new,
22 i_img_16_new,
23 i_img_double_new,
24 i_img_pal_new,
25 i_img_destroy,
26 i_sametype,
27 i_sametype_chans,
28 i_img_info,
29
30 i_ppix,
31 i_gpix,
32 i_ppixf,
33 i_gpixf,
34 i_plin,
35 i_glin,
36 i_plinf,
37 i_glinf,
38 i_gsamp,
39 i_gsampf,
40 i_gpal,
41 i_ppal,
42 i_addcolors,
43 i_getcolors,
44 i_colorcount,
45 i_maxcolors,
46 i_findcolor,
47 i_setcolors,
48
49 i_new_fill_solid,
50 i_new_fill_solidf,
51 i_new_fill_hatch,
52 i_new_fill_hatchf,
53 i_new_fill_image,
54 i_new_fill_fount,
55 i_fill_destroy,
56
57 i_quant_makemap,
58 i_quant_translate,
59 i_quant_transparent,
60
61 i_clear_error,
62 i_push_error,
63 i_push_errorf,
64 i_push_errorvf,
65
66 i_tags_new,
67 i_tags_set,
68 i_tags_setn,
69 i_tags_destroy,
70 i_tags_find,
71 i_tags_findn,
72 i_tags_delete,
73 i_tags_delbyname,
74 i_tags_delbycode,
75 i_tags_get_float,
76 i_tags_set_float,
77 i_tags_set_float2,
78 i_tags_get_int,
79 i_tags_get_string,
80 i_tags_get_color,
81 i_tags_set_color,
82
83 i_box,
84 i_box_filled,
85 i_box_cfill,
86 i_line,
87 i_line_aa,
88 i_arc,
89 i_arc_aa,
90 i_arc_cfill,
91 i_arc_aa_cfill,
92 i_circle_aa,
93 i_flood_fill,
94 i_flood_cfill,
95
96 i_copyto,
97 i_copyto_trans,
98 i_copy,
99 i_rubthru,
2b405c9e
TC
100
101 /* IMAGER_API_LEVEL 2 functions */
102 i_set_image_file_limits,
103 i_get_image_file_limits,
104 i_int_check_image_file_limits,
3efb0915
TC
105
106 i_flood_fill_border,
107 i_flood_cfill_border,
d5477d3d
TC
108
109 /* IMAGER_API_LEVEL 3 functions */
110 i_img_setmask,
111 i_img_getmask,
112 i_img_getchannels,
113 i_img_get_width,
114 i_img_get_height,
115 i_lhead,
bd8052a6
TC
116 i_loog,
117
118 /* IMAGER_API_LEVEL 4 functions */
119 i_img_alloc,
120 i_img_init,
e5ee047b
TC
121
122 /* IMAGER_API_LEVEL 5 functions */
797a9f9c
TC
123 i_img_is_monochrome,
124 i_gsamp_bg,
125 i_gsampf_bg,
126 i_get_file_background,
718b8c97 127 i_get_file_backgroundf,
50c75381
TC
128 i_utf8_advance,
129 i_render_new,
130 i_render_delete,
131 i_render_color,
132 i_render_fill,
133 i_render_line,
134 i_render_linef
92bda632
TC
135 };
136
137/* in general these functions aren't called by Imager internally, but
138 only via the pointers above, since faster macros that call the
139 image vtable pointers are used.
140
141 () are used around the function names to prevent macro replacement
142 on the function names.
143*/
144
145/*
146=item i_ppix(im, x, y, color)
147
148=category Drawing
149
150Sets the pixel at (x,y) to I<color>.
151
152Returns 0 if the pixel was drawn, or -1 if not.
153
154Does no alpha blending, just copies the channels from the supplied
155color to the image.
156
157=cut
158*/
159
160int
8d14daab 161(i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
92bda632
TC
162 return i_ppix(im, x, y, val);
163}
164
165/*
5715f7c3 166=item i_gpix(im, C<x>, C<y>, C<color>)
92bda632
TC
167
168=category Drawing
169
5715f7c3 170Retrieves the C<color> of the pixel (x,y).
92bda632
TC
171
172Returns 0 if the pixel was retrieved, or -1 if not.
173
174=cut
175*/
176
177int
8d14daab 178(i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
92bda632
TC
179 return i_gpix(im, x, y, val);
180}
181
182/*
5715f7c3 183=item i_ppixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
184
185=category Drawing
186
5715f7c3 187Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
92bda632
TC
188
189Returns 0 if the pixel was drawn, or -1 if not.
190
191Does no alpha blending, just copies the channels from the supplied
192color to the image.
193
194=cut
195*/
196int
8d14daab 197(i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
92bda632
TC
198 return i_ppixf(im, x, y, val);
199}
200
201/*
5715f7c3 202=item i_gpixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
203
204=category Drawing
205
206Retrieves the color of the pixel (x,y) as a floating point color into
5715f7c3 207C<fcolor>.
92bda632
TC
208
209Returns 0 if the pixel was retrieved, or -1 if not.
210
211=cut
212*/
213
214int
8d14daab 215(i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
92bda632
TC
216 return i_gpixf(im, x, y, val);
217}
218
219/*
220=item i_plin(im, l, r, y, colors)
221
222=category Drawing
223
224Sets (r-l) pixels starting from (l,y) using (r-l) values from
225I<colors>.
226
227Returns the number of pixels set.
228
229=cut
230*/
231
8d14daab
TC
232i_img_dim
233(i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
92bda632
TC
234 return i_plin(im, l, r, y, vals);
235}
236
237/*
238=item i_glin(im, l, r, y, colors)
239
240=category Drawing
241
242Retrieves (r-l) pixels starting from (l,y) into I<colors>.
243
244Returns the number of pixels retrieved.
245
246=cut
247*/
248
8d14daab
TC
249i_img_dim
250(i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
92bda632
TC
251 return i_glin(im, l, r, y, vals);
252}
253
254/*
5715f7c3 255=item i_plinf(im, C<left>, C<right>, C<fcolors>)
92bda632
TC
256
257=category Drawing
258
5715f7c3
TC
259Sets (right-left) pixels starting from (left,y) using (right-left)
260floating point colors from C<fcolors>.
92bda632
TC
261
262Returns the number of pixels set.
263
264=cut
265*/
266
8d14daab
TC
267i_img_dim
268(i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
92bda632
TC
269 return i_plinf(im, l, r, y, vals);
270}
271
272/*
273=item i_glinf(im, l, r, y, colors)
274
275=category Drawing
276
277Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
278point colors.
279
280Returns the number of pixels retrieved.
281
282=cut
283*/
284
8d14daab
TC
285i_img_dim
286(i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
92bda632
TC
287 return i_glinf(im, l, r, y, vals);
288}
289
290/*
5715f7c3 291=item i_gsamp(im, left, right, y, samples, channels, channel_count)
92bda632
TC
292
293=category Drawing
294
5715f7c3
TC
295Reads sample values from C<im> for the horizontal line (left, y) to
296(right-1,y) for the channels specified by C<channels>, an array of int
297with C<channel_count> elements.
92bda632 298
5715f7c3 299If channels is NULL then the first channels_count channels are retrieved for
92bda632
TC
300each pixel.
301
5715f7c3
TC
302Returns the number of samples read (which should be (right-left) *
303channel_count)
92bda632
TC
304
305=cut
306*/
8d14daab
TC
307i_img_dim
308(i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
92bda632
TC
309 const int *chans, int chan_count) {
310 return i_gsamp(im, l, r, y, samp, chans, chan_count);
311}
312
313/*
5715f7c3 314=item i_gsampf(im, left, right, y, samples, channels, channel_count)
92bda632
TC
315
316=category Drawing
317
5715f7c3
TC
318Reads floating point sample values from C<im> for the horizontal line
319(left, y) to (right-1,y) for the channels specified by C<channels>, an
320array of int with channel_count elements.
92bda632 321
5715f7c3
TC
322If C<channels> is NULL then the first C<channel_count> channels are
323retrieved for each pixel.
92bda632 324
5715f7c3
TC
325Returns the number of samples read (which should be (C<right>-C<left>)
326* C<channel_count>)
92bda632
TC
327
328=cut
329*/
8d14daab
TC
330i_img_dim
331(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
92bda632
TC
332 const int *chans, int chan_count) {
333 return i_gsampf(im, l, r, y, samp, chans, chan_count);
334}
335
336/*
5715f7c3 337=item i_gpal(im, left, right, y, indexes)
92bda632
TC
338
339=category Drawing
340
5715f7c3
TC
341Reads palette indexes for the horizontal line (left, y) to (right-1,
342y) into C<indexes>.
92bda632
TC
343
344Returns the number of indexes read.
345
346Always returns 0 for direct color images.
347
348=cut
349*/
8d14daab
TC
350i_img_dim
351(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
92bda632
TC
352 return i_gpal(im, x, r, y, vals);
353}
354
355/*
5715f7c3 356=item i_ppal(im, left, right, y, indexes)
92bda632
TC
357
358=category Drawing
359
5715f7c3
TC
360Writes palette indexes for the horizontal line (left, y) to (right-1,
361y) from C<indexes>.
92bda632
TC
362
363Returns the number of indexes written.
364
365Always returns 0 for direct color images.
366
367=cut
368*/
8d14daab
TC
369i_img_dim
370(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
92bda632
TC
371 return i_ppal(im, x, r, y, vals);
372}
373
374/*
375=item i_addcolors(im, colors, count)
376
377=category Paletted images
378
379Adds colors to the image's palette.
380
381On success returns the index of the lowest color added.
382
383On failure returns -1.
384
385Always fails for direct color images.
386
387=cut
388*/
389
390int
97ac0a96 391(i_addcolors)(i_img *im, const i_color *colors, int count) {
92bda632
TC
392 return i_addcolors(im, colors, count);
393}
394
395/*
396=item i_getcolors(im, index, colors, count)
397
398=category Paletted images
399
400Retrieves I<count> colors starting from I<index> in the image's
401palette.
402
403On success stores the colors into I<colors> and returns true.
404
405On failure returns false.
406
407Always fails for direct color images.
408
409Fails if there are less than I<index>+I<count> colors in the image's
410palette.
411
412=cut
413*/
414
415int
416(i_getcolors)(i_img *im, int i, i_color *colors, int count) {
417 return i_getcolors(im, i, colors, count);
418}
419
420/*
421=item i_colorcount(im)
422
423=category Paletted images
424
425Returns the number of colors in the image's palette.
426
427Returns -1 for direct images.
428
429=cut
430*/
431
432int
433(i_colorcount)(i_img *im) {
434 return i_colorcount(im);
435}
436
437/*
438=item i_maxcolors(im)
439
440=category Paletted images
441
442Returns the maximum number of colors the palette can hold for the
443image.
444
445Returns -1 for direct color images.
446
447=cut
448*/
449
450int
451(i_maxcolors)(i_img *im) {
452 return i_maxcolors(im);
453}
454
455/*
456=item i_findcolor(im, color, &entry)
457
458=category Paletted images
459
460Searches the images palette for the given color.
461
462On success sets *I<entry> to the index of the color, and returns true.
463
464On failure returns false.
465
466Always fails on direct color images.
467
468=cut
469*/
470int
97ac0a96 471(i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
92bda632
TC
472 return i_findcolor(im, color, entry);
473}
474
475/*
476=item i_setcolors(im, index, colors, count)
477
478=category Paletted images
479
480Sets I<count> colors starting from I<index> in the image's palette.
481
5715f7c3 482On success returns true.
92bda632
TC
483
484On failure returns false.
485
486The image must have at least I<index>+I<count> colors in it's palette
487for this to succeed.
488
489Always fails on direct color images.
490
491=cut
492*/
493int
97ac0a96 494(i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
92bda632
TC
495 return i_setcolors(im, index, colors, count);
496}
497