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