WIP, more context changes
[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
d03fd5a4
TC
21 i_img_8_new,
22 i_img_16_new,
23 i_img_double_new,
24 i_img_pal_new,
92bda632
TC
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
d03fd5a4
TC
61 i_clear_error,
62 i_push_error,
92bda632 63 i_push_errorf,
d03fd5a4 64 i_push_errorvf,
92bda632
TC
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 */
d03fd5a4
TC
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 */
d03fd5a4
TC
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,
6d5c85a2
TC
134 i_render_linef,
135
136 /* level 6 */
137 i_io_getc_imp,
138 i_io_peekc_imp,
139 i_io_peekn,
140 i_io_putc_imp,
141 i_io_read,
142 i_io_write,
143 i_io_seek,
144 i_io_flush,
145 i_io_close,
146 i_io_set_buffered,
147 i_io_gets,
d03fd5a4
TC
148 io_new_fd,
149 io_new_bufchain,
150 io_new_buffer,
151 io_new_cb,
6d5c85a2 152 io_slurp,
d03fd5a4 153 io_glue_destroy
92bda632
TC
154 };
155
156/* in general these functions aren't called by Imager internally, but
157 only via the pointers above, since faster macros that call the
158 image vtable pointers are used.
159
160 () are used around the function names to prevent macro replacement
161 on the function names.
162*/
163
164/*
165=item i_ppix(im, x, y, color)
166
167=category Drawing
168
169Sets the pixel at (x,y) to I<color>.
170
171Returns 0 if the pixel was drawn, or -1 if not.
172
173Does no alpha blending, just copies the channels from the supplied
174color to the image.
175
176=cut
177*/
178
179int
8d14daab 180(i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
92bda632
TC
181 return i_ppix(im, x, y, val);
182}
183
184/*
5715f7c3 185=item i_gpix(im, C<x>, C<y>, C<color>)
92bda632
TC
186
187=category Drawing
188
5715f7c3 189Retrieves the C<color> of the pixel (x,y).
92bda632
TC
190
191Returns 0 if the pixel was retrieved, or -1 if not.
192
193=cut
194*/
195
196int
8d14daab 197(i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
92bda632
TC
198 return i_gpix(im, x, y, val);
199}
200
201/*
5715f7c3 202=item i_ppixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
203
204=category Drawing
205
5715f7c3 206Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
92bda632
TC
207
208Returns 0 if the pixel was drawn, or -1 if not.
209
210Does no alpha blending, just copies the channels from the supplied
211color to the image.
212
213=cut
214*/
215int
8d14daab 216(i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
92bda632
TC
217 return i_ppixf(im, x, y, val);
218}
219
220/*
5715f7c3 221=item i_gpixf(im, C<x>, C<y>, C<fcolor>)
92bda632
TC
222
223=category Drawing
224
225Retrieves the color of the pixel (x,y) as a floating point color into
5715f7c3 226C<fcolor>.
92bda632
TC
227
228Returns 0 if the pixel was retrieved, or -1 if not.
229
230=cut
231*/
232
233int
8d14daab 234(i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
92bda632
TC
235 return i_gpixf(im, x, y, val);
236}
237
238/*
239=item i_plin(im, l, r, y, colors)
240
241=category Drawing
242
243Sets (r-l) pixels starting from (l,y) using (r-l) values from
244I<colors>.
245
246Returns the number of pixels set.
247
248=cut
249*/
250
8d14daab
TC
251i_img_dim
252(i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
92bda632
TC
253 return i_plin(im, l, r, y, vals);
254}
255
256/*
257=item i_glin(im, l, r, y, colors)
258
259=category Drawing
260
261Retrieves (r-l) pixels starting from (l,y) into I<colors>.
262
263Returns the number of pixels retrieved.
264
265=cut
266*/
267
8d14daab
TC
268i_img_dim
269(i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
92bda632
TC
270 return i_glin(im, l, r, y, vals);
271}
272
273/*
5715f7c3 274=item i_plinf(im, C<left>, C<right>, C<fcolors>)
92bda632
TC
275
276=category Drawing
277
5715f7c3
TC
278Sets (right-left) pixels starting from (left,y) using (right-left)
279floating point colors from C<fcolors>.
92bda632
TC
280
281Returns the number of pixels set.
282
283=cut
284*/
285
8d14daab
TC
286i_img_dim
287(i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
92bda632
TC
288 return i_plinf(im, l, r, y, vals);
289}
290
291/*
292=item i_glinf(im, l, r, y, colors)
293
294=category Drawing
295
296Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
297point colors.
298
299Returns the number of pixels retrieved.
300
301=cut
302*/
303
8d14daab
TC
304i_img_dim
305(i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
92bda632
TC
306 return i_glinf(im, l, r, y, vals);
307}
308
309/*
5715f7c3 310=item i_gsamp(im, left, right, y, samples, channels, channel_count)
92bda632
TC
311
312=category Drawing
313
5715f7c3
TC
314Reads sample values from C<im> for the horizontal line (left, y) to
315(right-1,y) for the channels specified by C<channels>, an array of int
316with C<channel_count> elements.
92bda632 317
5715f7c3 318If channels is NULL then the first channels_count channels are retrieved for
92bda632
TC
319each pixel.
320
5715f7c3
TC
321Returns the number of samples read (which should be (right-left) *
322channel_count)
92bda632
TC
323
324=cut
325*/
8d14daab
TC
326i_img_dim
327(i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
92bda632
TC
328 const int *chans, int chan_count) {
329 return i_gsamp(im, l, r, y, samp, chans, chan_count);
330}
331
332/*
5715f7c3 333=item i_gsampf(im, left, right, y, samples, channels, channel_count)
92bda632
TC
334
335=category Drawing
336
5715f7c3
TC
337Reads floating point sample values from C<im> for the horizontal line
338(left, y) to (right-1,y) for the channels specified by C<channels>, an
339array of int with channel_count elements.
92bda632 340
5715f7c3
TC
341If C<channels> is NULL then the first C<channel_count> channels are
342retrieved for each pixel.
92bda632 343
5715f7c3
TC
344Returns the number of samples read (which should be (C<right>-C<left>)
345* C<channel_count>)
92bda632
TC
346
347=cut
348*/
8d14daab
TC
349i_img_dim
350(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
92bda632
TC
351 const int *chans, int chan_count) {
352 return i_gsampf(im, l, r, y, samp, chans, chan_count);
353}
354
48095bd4
TC
355/*
356=item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
357=category Drawing
358
359Reads integer samples scaled to C<bits> bits of precision into the
360C<unsigned int> array C<samples>.
361
362Expect this to be slow unless C<< bits == im->bits >>.
363
364Returns the number of samples copied, or -1 on error.
365
366Not all image types implement this method.
367
368Pushes errors, but does not call C<i_clear_error()>.
369
370=cut
371*/
372
373/*
374=item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
375=category Drawing
376
377Writes integer samples scaled to C<bits> bits of precision from the
378C<unsigned int> array C<samples>.
379
380Expect this to be slow unless C<< bits == im->bits >>.
381
382Returns the number of samples copied, or -1 on error.
383
384Not all image types implement this method.
385
386Pushes errors, but does not call C<i_clear_error()>.
387
388=cut
389*/
390
92bda632 391/*
5715f7c3 392=item i_gpal(im, left, right, y, indexes)
92bda632
TC
393
394=category Drawing
395
5715f7c3
TC
396Reads palette indexes for the horizontal line (left, y) to (right-1,
397y) into C<indexes>.
92bda632
TC
398
399Returns the number of indexes read.
400
401Always returns 0 for direct color images.
402
403=cut
404*/
8d14daab
TC
405i_img_dim
406(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
92bda632
TC
407 return i_gpal(im, x, r, y, vals);
408}
409
410/*
5715f7c3 411=item i_ppal(im, left, right, y, indexes)
92bda632
TC
412
413=category Drawing
414
5715f7c3
TC
415Writes palette indexes for the horizontal line (left, y) to (right-1,
416y) from C<indexes>.
92bda632
TC
417
418Returns the number of indexes written.
419
420Always returns 0 for direct color images.
421
422=cut
423*/
8d14daab
TC
424i_img_dim
425(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
92bda632
TC
426 return i_ppal(im, x, r, y, vals);
427}
428
429/*
430=item i_addcolors(im, colors, count)
431
432=category Paletted images
433
434Adds colors to the image's palette.
435
436On success returns the index of the lowest color added.
437
438On failure returns -1.
439
440Always fails for direct color images.
441
442=cut
443*/
444
445int
97ac0a96 446(i_addcolors)(i_img *im, const i_color *colors, int count) {
92bda632
TC
447 return i_addcolors(im, colors, count);
448}
449
450/*
451=item i_getcolors(im, index, colors, count)
452
453=category Paletted images
454
455Retrieves I<count> colors starting from I<index> in the image's
456palette.
457
458On success stores the colors into I<colors> and returns true.
459
460On failure returns false.
461
462Always fails for direct color images.
463
464Fails if there are less than I<index>+I<count> colors in the image's
465palette.
466
467=cut
468*/
469
470int
471(i_getcolors)(i_img *im, int i, i_color *colors, int count) {
472 return i_getcolors(im, i, colors, count);
473}
474
475/*
476=item i_colorcount(im)
477
478=category Paletted images
479
480Returns the number of colors in the image's palette.
481
482Returns -1 for direct images.
483
484=cut
485*/
486
487int
488(i_colorcount)(i_img *im) {
489 return i_colorcount(im);
490}
491
492/*
493=item i_maxcolors(im)
494
495=category Paletted images
496
497Returns the maximum number of colors the palette can hold for the
498image.
499
500Returns -1 for direct color images.
501
502=cut
503*/
504
505int
506(i_maxcolors)(i_img *im) {
507 return i_maxcolors(im);
508}
509
510/*
511=item i_findcolor(im, color, &entry)
512
513=category Paletted images
514
515Searches the images palette for the given color.
516
517On success sets *I<entry> to the index of the color, and returns true.
518
519On failure returns false.
520
521Always fails on direct color images.
522
523=cut
524*/
525int
97ac0a96 526(i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
92bda632
TC
527 return i_findcolor(im, color, entry);
528}
529
530/*
531=item i_setcolors(im, index, colors, count)
532
533=category Paletted images
534
535Sets I<count> colors starting from I<index> in the image's palette.
536
5715f7c3 537On success returns true.
92bda632
TC
538
539On failure returns false.
540
541The image must have at least I<index>+I<count> colors in it's palette
542for this to succeed.
543
544Always fails on direct color images.
545
546=cut
547*/
548int
97ac0a96 549(i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
92bda632
TC
550 return i_setcolors(im, index, colors, count);
551}
552