1 #include "imexttypes.h"
6 static im_context_t get_context(void);
7 static i_img *mathom_i_img_8_new(i_img_dim, i_img_dim, int);
8 static i_img *mathom_i_img_16_new(i_img_dim, i_img_dim, int);
9 static i_img *mathom_i_img_double_new(i_img_dim, i_img_dim, int);
10 static i_img *mathom_i_img_pal_new(i_img_dim, i_img_dim, int, int);
11 static void mathom_i_clear_error(void);
12 static void mathom_i_push_error(int, const char *);
13 static void mathom_i_push_errorvf(int, const char *, va_list);
14 static int mathom_i_set_image_file_limits(i_img_dim, i_img_dim, size_t);
15 static int mathom_i_get_image_file_limits(i_img_dim*, i_img_dim*, size_t*);
17 mathom_i_int_check_image_file_limits(i_img_dim, i_img_dim, int, size_t);
18 static i_img *mathom_i_img_alloc(void);
19 static void mathom_i_img_init(i_img *);
20 static i_io_glue_t *mathom_io_new_fd(int);
21 static i_io_glue_t *mathom_io_new_bufchain(void);
23 mathom_io_new_buffer(const char *data, size_t, i_io_closebufp_t, void *);
25 mathom_io_new_cb(void *, i_io_readl_t, i_io_writel_t, i_io_seekl_t,
26 i_io_closel_t, i_io_destroyl_t);
29 DON'T ADD CASTS TO THESE
31 im_ext_funcs imager_function_table =
46 mathom_i_img_double_new,
87 mathom_i_push_errorvf,
124 /* IMAGER_API_LEVEL 2 functions */
125 mathom_i_set_image_file_limits,
126 mathom_i_get_image_file_limits,
127 mathom_i_int_check_image_file_limits,
130 i_flood_cfill_border,
132 /* IMAGER_API_LEVEL 3 functions */
141 /* IMAGER_API_LEVEL 4 functions */
145 /* IMAGER_API_LEVEL 5 functions */
149 i_get_file_background,
150 i_get_file_backgroundf,
172 mathom_io_new_bufchain,
173 mathom_io_new_buffer,
187 im_set_image_file_limits,
188 im_get_image_file_limits,
189 im_int_check_image_file_limits,
212 i_poly_poly_aa_cfill,
218 i_img_color_channels,
226 /* in general these functions aren't called by Imager internally, but
227 only via the pointers above, since faster macros that call the
228 image vtable pointers are used.
230 () are used around the function names to prevent macro replacement
231 on the function names.
235 =item i_ppix(im, x, y, color)
239 Sets the pixel at (x,y) to I<color>.
241 Returns 0 if the pixel was drawn, or -1 if not.
243 Does no alpha blending, just copies the channels from the supplied
250 (i_ppix)(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) {
251 return i_ppix(im, x, y, val);
255 =item i_gpix(im, C<x>, C<y>, C<color>)
259 Retrieves the C<color> of the pixel (x,y).
261 Returns 0 if the pixel was retrieved, or -1 if not.
267 (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val) {
268 return i_gpix(im, x, y, val);
272 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
276 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
278 Returns 0 if the pixel was drawn, or -1 if not.
280 Does no alpha blending, just copies the channels from the supplied
286 (i_ppixf)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) {
287 return i_ppixf(im, x, y, val);
291 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
295 Retrieves the color of the pixel (x,y) as a floating point color into
298 Returns 0 if the pixel was retrieved, or -1 if not.
304 (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val) {
305 return i_gpixf(im, x, y, val);
309 =item i_plin(im, l, r, y, colors)
313 Sets (r-l) pixels starting from (l,y) using (r-l) values from
316 Returns the number of pixels set.
322 (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
323 return i_plin(im, l, r, y, vals);
327 =item i_glin(im, l, r, y, colors)
331 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
333 Returns the number of pixels retrieved.
339 (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
340 return i_glin(im, l, r, y, vals);
344 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
348 Sets (right-left) pixels starting from (left,y) using (right-left)
349 floating point colors from C<fcolors>.
351 Returns the number of pixels set.
357 (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
358 return i_plinf(im, l, r, y, vals);
362 =item i_glinf(im, l, r, y, colors)
366 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
369 Returns the number of pixels retrieved.
375 (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
376 return i_glinf(im, l, r, y, vals);
380 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
384 Reads sample values from C<im> for the horizontal line (left, y) to
385 (right-1,y) for the channels specified by C<channels>, an array of int
386 with C<channel_count> elements.
388 If channels is NULL then the first channels_count channels are retrieved for
391 Returns the number of samples read (which should be (right-left) *
397 (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
398 const int *chans, int chan_count) {
399 return i_gsamp(im, l, r, y, samp, chans, chan_count);
403 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
407 Reads floating point sample values from C<im> for the horizontal line
408 (left, y) to (right-1,y) for the channels specified by C<channels>, an
409 array of int with channel_count elements.
411 If C<channels> is NULL then the first C<channel_count> channels are
412 retrieved for each pixel.
414 Returns the number of samples read (which should be (C<right>-C<left>)
420 (i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
421 const int *chans, int chan_count) {
422 return i_gsampf(im, l, r, y, samp, chans, chan_count);
426 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
429 Reads integer samples scaled to C<bits> bits of precision into the
430 C<unsigned int> array C<samples>.
432 Expect this to be slow unless C<< bits == im->bits >>.
434 Returns the number of samples copied, or -1 on error.
436 Not all image types implement this method.
438 Pushes errors, but does not call C<i_clear_error()>.
444 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
447 Writes integer samples scaled to C<bits> bits of precision from the
448 C<unsigned int> array C<samples>.
450 Expect this to be slow unless C<< bits == im->bits >>.
452 Returns the number of samples copied, or -1 on error.
454 Not all image types implement this method.
456 Pushes errors, but does not call C<i_clear_error()>.
462 =item i_gpal(im, left, right, y, indexes)
466 Reads palette indexes for the horizontal line (left, y) to (right-1,
469 Returns the number of indexes read.
471 Always returns 0 for direct color images.
476 (i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals) {
477 return i_gpal(im, x, r, y, vals);
481 =item i_ppal(im, left, right, y, indexes)
485 Writes palette indexes for the horizontal line (left, y) to (right-1,
488 Returns the number of indexes written.
490 Always returns 0 for direct color images.
495 (i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals) {
496 return i_ppal(im, x, r, y, vals);
500 =item i_addcolors(im, colors, count)
502 =category Paletted images
504 Adds colors to the image's palette.
506 On success returns the index of the lowest color added.
508 On failure returns -1.
510 Always fails for direct color images.
516 (i_addcolors)(i_img *im, const i_color *colors, int count) {
517 return i_addcolors(im, colors, count);
521 =item i_getcolors(im, index, colors, count)
523 =category Paletted images
525 Retrieves I<count> colors starting from I<index> in the image's
528 On success stores the colors into I<colors> and returns true.
530 On failure returns false.
532 Always fails for direct color images.
534 Fails if there are less than I<index>+I<count> colors in the image's
541 (i_getcolors)(i_img *im, int i, i_color *colors, int count) {
542 return i_getcolors(im, i, colors, count);
546 =item i_colorcount(im)
548 =category Paletted images
550 Returns the number of colors in the image's palette.
552 Returns -1 for direct images.
558 (i_colorcount)(i_img *im) {
559 return i_colorcount(im);
563 =item i_maxcolors(im)
565 =category Paletted images
567 Returns the maximum number of colors the palette can hold for the
570 Returns -1 for direct color images.
576 (i_maxcolors)(i_img *im) {
577 return i_maxcolors(im);
581 =item i_findcolor(im, color, &entry)
583 =category Paletted images
585 Searches the images palette for the given color.
587 On success sets *I<entry> to the index of the color, and returns true.
589 On failure returns false.
591 Always fails on direct color images.
596 (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry) {
597 return i_findcolor(im, color, entry);
601 =item i_setcolors(im, index, colors, count)
603 =category Paletted images
605 Sets I<count> colors starting from I<index> in the image's palette.
607 On success returns true.
609 On failure returns false.
611 The image must have at least I<index>+I<count> colors in it's palette
614 Always fails on direct color images.
619 (i_setcolors)(i_img *im, int index, const i_color *colors, int count) {
620 return i_setcolors(im, index, colors, count);
624 =item im_get_context()
626 Retrieve the context object for the current thread.
628 Inside Imager itself this is just a function pointer, which the
629 F<Imager.xs> BOOT handler initializes for use within perl. If you're
630 taking the Imager code and embedding it elsewhere you need to
631 initialize the C<im_get_context> pointer at some point.
638 return im_get_context();
642 mathom_i_img_8_new(i_img_dim xsize, i_img_dim ysize, int channels) {
643 return i_img_8_new(xsize, ysize, channels);
647 mathom_i_img_16_new(i_img_dim xsize, i_img_dim ysize, int channels) {
648 return i_img_16_new(xsize, ysize, channels);
652 mathom_i_img_double_new(i_img_dim xsize, i_img_dim ysize, int channels) {
653 return i_img_double_new(xsize, ysize, channels);
657 mathom_i_img_pal_new(i_img_dim xsize, i_img_dim ysize, int channels,
659 return i_img_pal_new(xsize, ysize, channels, maxpal);
663 mathom_i_clear_error(void) {
668 mathom_i_push_error(int code, const char *msg) {
669 i_push_error(code, msg);
673 mathom_i_push_errorvf(int code, const char *fmt, va_list args) {
674 i_push_errorvf(code, fmt, args);
678 mathom_i_set_image_file_limits(i_img_dim max_width, i_img_dim max_height,
680 return i_set_image_file_limits(max_width, max_height, max_bytes);
684 mathom_i_get_image_file_limits(i_img_dim *pmax_width, i_img_dim *pmax_height,
685 size_t *pmax_bytes) {
686 return i_get_image_file_limits(pmax_width, pmax_height, pmax_bytes);
690 mathom_i_int_check_image_file_limits(i_img_dim width, i_img_dim height,
691 int channels, size_t sample_size) {
692 return i_int_check_image_file_limits(width, height, channels, sample_size);
696 mathom_i_img_alloc(void) {
697 return i_img_alloc();
701 mathom_i_img_init(i_img *im) {
706 mathom_io_new_fd(int fd) {
707 return io_new_fd(fd);
710 mathom_io_new_bufchain(void) {
711 return io_new_bufchain();
715 mathom_io_new_buffer(const char *data, size_t size, i_io_closebufp_t closefp,
717 return io_new_buffer(data, size, closefp, close_data);
721 mathom_io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb,
722 i_io_seekl_t seekcb, i_io_closel_t closecb,
723 i_io_destroyl_t destroycb) {
724 return io_new_cb(p, readcb, writecb, seekcb, closecb, destroycb);