]> git.imager.perl.org - imager.git/blob - imext.c
pick up im_ prefix functions too
[imager.git] / imext.c
1 #include "imexttypes.h"
2 #include "imager.h"
3 #include "imio.h"
4
5 static im_context_t get_context(void);
6
7 /*
8  DON'T ADD CASTS TO THESE
9 */
10 im_ext_funcs imager_function_table =
11   {
12     IMAGER_API_VERSION,
13     IMAGER_API_LEVEL,
14
15     mymalloc,
16     myfree,
17     myrealloc,
18
19     mymalloc_file_line,
20     myfree_file_line,
21     myrealloc_file_line,
22
23     im_img_8_new,
24     im_img_16_new,
25     im_img_double_new,
26     im_img_pal_new,
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
63     im_clear_error,
64     im_push_error,
65     i_push_errorf,
66     im_push_errorvf,
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,
102
103     /* IMAGER_API_LEVEL 2 functions */
104     im_set_image_file_limits,
105     im_get_image_file_limits,
106     im_int_check_image_file_limits,
107
108     i_flood_fill_border,
109     i_flood_cfill_border,
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,
118     i_loog,
119
120     /* IMAGER_API_LEVEL 4 functions */
121     im_img_alloc,
122     im_img_init,
123
124     /* IMAGER_API_LEVEL 5 functions */
125     i_img_is_monochrome,
126     i_gsamp_bg,
127     i_gsampf_bg,
128     i_get_file_background,
129     i_get_file_backgroundf,
130     i_utf8_advance,
131     i_render_new,
132     i_render_delete,
133     i_render_color,
134     i_render_fill,
135     i_render_line,
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,
150     im_io_new_fd,
151     im_io_new_bufchain,
152     im_io_new_buffer,
153     im_io_new_cb,
154     io_slurp,
155     io_glue_destroy,
156
157     /* level 8 */
158     get_context,
159     im_push_errorf,
160     im_lhead,
161     im_loog,
162     im_context_refinc,
163     im_context_refdec,
164     im_errors
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
180 Sets the pixel at (x,y) to I<color>.
181
182 Returns 0 if the pixel was drawn, or -1 if not.
183
184 Does no alpha blending, just copies the channels from the supplied
185 color to the image.
186
187 =cut
188 */
189
190 int 
191 (i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
192   return i_ppix(im, x, y, val);
193 }
194
195 /*
196 =item i_gpix(im, C<x>, C<y>, C<color>)
197
198 =category Drawing
199
200 Retrieves the C<color> of the pixel (x,y).
201
202 Returns 0 if the pixel was retrieved, or -1 if not.
203
204 =cut
205 */
206
207 int
208 (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
209   return i_gpix(im, x, y, val);
210 }
211
212 /*
213 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
214
215 =category Drawing
216
217 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
218
219 Returns 0 if the pixel was drawn, or -1 if not.
220
221 Does no alpha blending, just copies the channels from the supplied
222 color to the image.
223
224 =cut
225 */
226 int
227 (i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
228   return i_ppixf(im, x, y, val);
229 }
230
231 /*
232 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
233
234 =category Drawing
235
236 Retrieves the color of the pixel (x,y) as a floating point color into
237 C<fcolor>.
238
239 Returns 0 if the pixel was retrieved, or -1 if not.
240
241 =cut
242 */
243
244 int
245 (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
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
254 Sets (r-l) pixels starting from (l,y) using (r-l) values from
255 I<colors>.
256
257 Returns the number of pixels set.
258
259 =cut
260 */
261
262 i_img_dim
263 (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
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
272 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
273
274 Returns the number of pixels retrieved.
275
276 =cut
277 */
278
279 i_img_dim
280 (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
281   return i_glin(im, l, r, y, vals);
282 }
283
284 /*
285 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
286
287 =category Drawing
288
289 Sets (right-left) pixels starting from (left,y) using (right-left)
290 floating point colors from C<fcolors>.
291
292 Returns the number of pixels set.
293
294 =cut
295 */
296
297 i_img_dim
298 (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
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
307 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
308 point colors.
309
310 Returns the number of pixels retrieved.
311
312 =cut
313 */
314
315 i_img_dim
316 (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
317   return i_glinf(im, l, r, y, vals);
318 }
319
320 /*
321 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
322
323 =category Drawing
324
325 Reads 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
327 with C<channel_count> elements.
328
329 If channels is NULL then the first channels_count channels are retrieved for
330 each pixel.
331
332 Returns the number of samples read (which should be (right-left) *
333 channel_count)
334
335 =cut
336 */
337 i_img_dim
338 (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp, 
339                    const int *chans, int chan_count) {
340   return i_gsamp(im, l, r, y, samp, chans, chan_count);
341 }
342
343 /*
344 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
345
346 =category Drawing
347
348 Reads 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
350 array of int with channel_count elements.
351
352 If C<channels> is NULL then the first C<channel_count> channels are
353 retrieved for each pixel.
354
355 Returns the number of samples read (which should be (C<right>-C<left>)
356 * C<channel_count>)
357
358 =cut
359 */
360 i_img_dim
361 (i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp, 
362            const int *chans, int chan_count) {
363   return i_gsampf(im, l, r, y, samp, chans, chan_count);
364 }
365
366 /*
367 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
368 =category Drawing
369
370 Reads integer samples scaled to C<bits> bits of precision into the
371 C<unsigned int> array C<samples>.
372
373 Expect this to be slow unless C<< bits == im->bits >>.
374
375 Returns the number of samples copied, or -1 on error.
376
377 Not all image types implement this method.
378
379 Pushes 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
388 Writes integer samples scaled to C<bits> bits of precision from the
389 C<unsigned int> array C<samples>.
390
391 Expect this to be slow unless C<< bits == im->bits >>.
392
393 Returns the number of samples copied, or -1 on error.
394
395 Not all image types implement this method.
396
397 Pushes errors, but does not call C<i_clear_error()>.
398
399 =cut
400 */
401
402 /*
403 =item i_gpal(im, left, right, y, indexes)
404
405 =category Drawing
406
407 Reads palette indexes for the horizontal line (left, y) to (right-1,
408 y) into C<indexes>.
409
410 Returns the number of indexes read.
411
412 Always returns 0 for direct color images.
413
414 =cut
415 */
416 i_img_dim
417 (i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
418   return i_gpal(im, x, r, y, vals);
419 }
420
421 /*
422 =item i_ppal(im, left, right, y, indexes)
423
424 =category Drawing
425
426 Writes palette indexes for the horizontal line (left, y) to (right-1,
427 y) from C<indexes>.
428
429 Returns the number of indexes written.
430
431 Always returns 0 for direct color images.
432
433 =cut
434 */
435 i_img_dim
436 (i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
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
445 Adds colors to the image's palette.
446
447 On success returns the index of the lowest color added.
448
449 On failure returns -1.
450
451 Always fails for direct color images.
452
453 =cut
454 */
455
456 int
457 (i_addcolors)(i_img *im, const i_color *colors, int count) {
458   return i_addcolors(im, colors, count);
459 }
460
461 /*
462 =item i_getcolors(im, index, colors, count)
463
464 =category Paletted images
465
466 Retrieves I<count> colors starting from I<index> in the image's
467 palette.
468
469 On success stores the colors into I<colors> and returns true.
470
471 On failure returns false.
472
473 Always fails for direct color images.
474
475 Fails if there are less than I<index>+I<count> colors in the image's
476 palette.
477
478 =cut
479 */
480
481 int
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
491 Returns the number of colors in the image's palette.
492
493 Returns -1 for direct images.
494
495 =cut
496 */
497
498 int
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
508 Returns the maximum number of colors the palette can hold for the
509 image.
510
511 Returns -1 for direct color images.
512
513 =cut
514 */
515
516 int
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
526 Searches the images palette for the given color.
527
528 On success sets *I<entry> to the index of the color, and returns true.
529
530 On failure returns false.
531
532 Always fails on direct color images.
533
534 =cut
535 */
536 int
537 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
538   return i_findcolor(im, color, entry);
539 }
540
541 /*
542 =item i_setcolors(im, index, colors, count)
543
544 =category Paletted images
545
546 Sets I<count> colors starting from I<index> in the image's palette.
547
548 On success returns true.
549
550 On failure returns false.
551
552 The image must have at least I<index>+I<count> colors in it's palette
553 for this to succeed.
554
555 Always fails on direct color images.
556
557 =cut
558 */
559 int
560 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
561   return i_setcolors(im, index, colors, count);
562 }
563
564 /*
565 =item im_get_context()
566
567 Retrieve the context object for the current thread.
568
569 Inside Imager itself this is just a function pointer, which the
570 Imager.xs BOOT handler initializes for use within perl.  If you're
571 taking the Imager code and embedding it elsewhere you need to
572 initialize the C<im_get_context> pointer at some point.
573
574 =cut
575 */
576
577 static im_context_t
578 get_context(void) {
579   return im_get_context();
580 }