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