1 #include "imexttypes.h"
5 static im_context_t get_context(void);
6 static i_img *mathom_i_img_8_new(i_img_dim, i_img_dim, int);
7 static i_img *mathom_i_img_16_new(i_img_dim, i_img_dim, int);
8 static i_img *mathom_i_img_double_new(i_img_dim, i_img_dim, int);
9 static i_img *mathom_i_img_pal_new(i_img_dim, i_img_dim, int, int);
10 static void mathom_i_clear_error(void);
11 static void mathom_i_push_error(int, const char *);
12 static void mathom_i_push_errorvf(int, const char *, va_list);
13 static int mathom_i_set_image_file_limits(i_img_dim, i_img_dim, size_t);
14 static int mathom_i_get_image_file_limits(i_img_dim*, i_img_dim*, size_t*);
16 mathom_i_int_check_image_file_limits(i_img_dim, i_img_dim, int, size_t);
17 static i_img *mathom_i_img_alloc(void);
18 static void mathom_i_img_init(i_img *);
19 static i_io_glue_t *mathom_io_new_fd(int);
20 static i_io_glue_t *mathom_io_new_bufchain(void);
22 mathom_io_new_buffer(const char *data, size_t, i_io_closebufp_t, void *);
24 mathom_io_new_cb(void *, i_io_readl_t, i_io_writel_t, i_io_seekl_t,
25 i_io_closel_t, i_io_destroyl_t);
28 DON'T ADD CASTS TO THESE
30 im_ext_funcs imager_function_table =
45 mathom_i_img_double_new,
86 mathom_i_push_errorvf,
123 /* IMAGER_API_LEVEL 2 functions */
124 mathom_i_set_image_file_limits,
125 mathom_i_get_image_file_limits,
126 mathom_i_int_check_image_file_limits,
129 i_flood_cfill_border,
131 /* IMAGER_API_LEVEL 3 functions */
140 /* IMAGER_API_LEVEL 4 functions */
144 /* IMAGER_API_LEVEL 5 functions */
148 i_get_file_background,
149 i_get_file_backgroundf,
171 mathom_io_new_bufchain,
172 mathom_io_new_buffer,
186 im_set_image_file_limits,
187 im_get_image_file_limits,
188 im_int_check_image_file_limits,
211 i_poly_poly_aa_cfill,
216 /* in general these functions aren't called by Imager internally, but
217 only via the pointers above, since faster macros that call the
218 image vtable pointers are used.
220 () are used around the function names to prevent macro replacement
221 on the function names.
225 =item i_ppix(im, x, y, color)
229 Sets the pixel at (x,y) to I<color>.
231 Returns 0 if the pixel was drawn, or -1 if not.
233 Does no alpha blending, just copies the channels from the supplied
240 (i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
241 return i_ppix(im, x, y, val);
245 =item i_gpix(im, C<x>, C<y>, C<color>)
249 Retrieves the C<color> of the pixel (x,y).
251 Returns 0 if the pixel was retrieved, or -1 if not.
257 (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
258 return i_gpix(im, x, y, val);
262 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
266 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
268 Returns 0 if the pixel was drawn, or -1 if not.
270 Does no alpha blending, just copies the channels from the supplied
276 (i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
277 return i_ppixf(im, x, y, val);
281 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
285 Retrieves the color of the pixel (x,y) as a floating point color into
288 Returns 0 if the pixel was retrieved, or -1 if not.
294 (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
295 return i_gpixf(im, x, y, val);
299 =item i_plin(im, l, r, y, colors)
303 Sets (r-l) pixels starting from (l,y) using (r-l) values from
306 Returns the number of pixels set.
312 (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
313 return i_plin(im, l, r, y, vals);
317 =item i_glin(im, l, r, y, colors)
321 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
323 Returns the number of pixels retrieved.
329 (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
330 return i_glin(im, l, r, y, vals);
334 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
338 Sets (right-left) pixels starting from (left,y) using (right-left)
339 floating point colors from C<fcolors>.
341 Returns the number of pixels set.
347 (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
348 return i_plinf(im, l, r, y, vals);
352 =item i_glinf(im, l, r, y, colors)
356 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
359 Returns the number of pixels retrieved.
365 (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
366 return i_glinf(im, l, r, y, vals);
370 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
374 Reads sample values from C<im> for the horizontal line (left, y) to
375 (right-1,y) for the channels specified by C<channels>, an array of int
376 with C<channel_count> elements.
378 If channels is NULL then the first channels_count channels are retrieved for
381 Returns the number of samples read (which should be (right-left) *
387 (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
388 const int *chans, int chan_count) {
389 return i_gsamp(im, l, r, y, samp, chans, chan_count);
393 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
397 Reads floating point sample values from C<im> for the horizontal line
398 (left, y) to (right-1,y) for the channels specified by C<channels>, an
399 array of int with channel_count elements.
401 If C<channels> is NULL then the first C<channel_count> channels are
402 retrieved for each pixel.
404 Returns the number of samples read (which should be (C<right>-C<left>)
410 (i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
411 const int *chans, int chan_count) {
412 return i_gsampf(im, l, r, y, samp, chans, chan_count);
416 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
419 Reads integer samples scaled to C<bits> bits of precision into the
420 C<unsigned int> array C<samples>.
422 Expect this to be slow unless C<< bits == im->bits >>.
424 Returns the number of samples copied, or -1 on error.
426 Not all image types implement this method.
428 Pushes errors, but does not call C<i_clear_error()>.
434 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
437 Writes integer samples scaled to C<bits> bits of precision from the
438 C<unsigned int> array C<samples>.
440 Expect this to be slow unless C<< bits == im->bits >>.
442 Returns the number of samples copied, or -1 on error.
444 Not all image types implement this method.
446 Pushes errors, but does not call C<i_clear_error()>.
452 =item i_gpal(im, left, right, y, indexes)
456 Reads palette indexes for the horizontal line (left, y) to (right-1,
459 Returns the number of indexes read.
461 Always returns 0 for direct color images.
466 (i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
467 return i_gpal(im, x, r, y, vals);
471 =item i_ppal(im, left, right, y, indexes)
475 Writes palette indexes for the horizontal line (left, y) to (right-1,
478 Returns the number of indexes written.
480 Always returns 0 for direct color images.
485 (i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
486 return i_ppal(im, x, r, y, vals);
490 =item i_addcolors(im, colors, count)
492 =category Paletted images
494 Adds colors to the image's palette.
496 On success returns the index of the lowest color added.
498 On failure returns -1.
500 Always fails for direct color images.
506 (i_addcolors)(i_img *im, const i_color *colors, int count) {
507 return i_addcolors(im, colors, count);
511 =item i_getcolors(im, index, colors, count)
513 =category Paletted images
515 Retrieves I<count> colors starting from I<index> in the image's
518 On success stores the colors into I<colors> and returns true.
520 On failure returns false.
522 Always fails for direct color images.
524 Fails if there are less than I<index>+I<count> colors in the image's
531 (i_getcolors)(i_img *im, int i, i_color *colors, int count) {
532 return i_getcolors(im, i, colors, count);
536 =item i_colorcount(im)
538 =category Paletted images
540 Returns the number of colors in the image's palette.
542 Returns -1 for direct images.
548 (i_colorcount)(i_img *im) {
549 return i_colorcount(im);
553 =item i_maxcolors(im)
555 =category Paletted images
557 Returns the maximum number of colors the palette can hold for the
560 Returns -1 for direct color images.
566 (i_maxcolors)(i_img *im) {
567 return i_maxcolors(im);
571 =item i_findcolor(im, color, &entry)
573 =category Paletted images
575 Searches the images palette for the given color.
577 On success sets *I<entry> to the index of the color, and returns true.
579 On failure returns false.
581 Always fails on direct color images.
586 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
587 return i_findcolor(im, color, entry);
591 =item i_setcolors(im, index, colors, count)
593 =category Paletted images
595 Sets I<count> colors starting from I<index> in the image's palette.
597 On success returns true.
599 On failure returns false.
601 The image must have at least I<index>+I<count> colors in it's palette
604 Always fails on direct color images.
609 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
610 return i_setcolors(im, index, colors, count);
614 =item im_get_context()
616 Retrieve the context object for the current thread.
618 Inside Imager itself this is just a function pointer, which the
619 F<Imager.xs> BOOT handler initializes for use within perl. If you're
620 taking the Imager code and embedding it elsewhere you need to
621 initialize the C<im_get_context> pointer at some point.
628 return im_get_context();
632 mathom_i_img_8_new(i_img_dim xsize, i_img_dim ysize, int channels) {
633 return i_img_8_new(xsize, ysize, channels);
637 mathom_i_img_16_new(i_img_dim xsize, i_img_dim ysize, int channels) {
638 return i_img_16_new(xsize, ysize, channels);
642 mathom_i_img_double_new(i_img_dim xsize, i_img_dim ysize, int channels) {
643 return i_img_double_new(xsize, ysize, channels);
647 mathom_i_img_pal_new(i_img_dim xsize, i_img_dim ysize, int channels,
649 return i_img_pal_new(xsize, ysize, channels, maxpal);
653 mathom_i_clear_error(void) {
658 mathom_i_push_error(int code, const char *msg) {
659 i_push_error(code, msg);
663 mathom_i_push_errorvf(int code, const char *fmt, va_list args) {
664 i_push_errorvf(code, fmt, args);
668 mathom_i_set_image_file_limits(i_img_dim max_width, i_img_dim max_height,
670 return i_set_image_file_limits(max_width, max_height, max_bytes);
674 mathom_i_get_image_file_limits(i_img_dim *pmax_width, i_img_dim *pmax_height,
675 size_t *pmax_bytes) {
676 return i_get_image_file_limits(pmax_width, pmax_height, pmax_bytes);
680 mathom_i_int_check_image_file_limits(i_img_dim width, i_img_dim height,
681 int channels, size_t sample_size) {
682 return i_int_check_image_file_limits(width, height, channels, sample_size);
686 mathom_i_img_alloc(void) {
687 return i_img_alloc();
691 mathom_i_img_init(i_img *im) {
696 mathom_io_new_fd(int fd) {
697 return io_new_fd(fd);
700 mathom_io_new_bufchain(void) {
701 return io_new_bufchain();
705 mathom_io_new_buffer(const char *data, size_t size, i_io_closebufp_t closefp,
707 return io_new_buffer(data, size, closefp, close_data);
711 mathom_io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb,
712 i_io_seekl_t seekcb, i_io_closel_t closecb,
713 i_io_destroyl_t destroycb) {
714 return io_new_cb(p, readcb, writecb, seekcb, closecb, destroycb);