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