1 Do not edit this file, it is generated automatically by apidocs.perl
2 from Imager's source files.
4 Each function description has a comment listing the source file where
5 you can find the documentation.
9 Imager::APIRef - Imager's C API - reference.
14 color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
18 poly.count = sizeof(x) / sizeof(*x);
28 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
31 printf("left %" i_DF "\n", i_DFc(x));
32 printf("point (" i_DFp ")\n", i_DFcp(x, y));
35 i_arc(im, 50, 50, 20, 45, 135, &color);
36 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
37 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
38 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
39 i_circle_aa(im, 50, 50, 45, &color);
40 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
41 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
42 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
43 i_flood_fill(im, 50, 50, &color);
44 i_flood_cfill(im, 50, 50, fill);
45 i_flood_fill_border(im, 50, 50, &color, &border);
46 i_flood_cfill_border(im, 50, 50, fill, border);
47 i_poly_poly_aa(im, 1, &poly, mode, color);
48 i_poly_aa_m(im, count, x, y, mode, color);
49 i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
50 i_poly_aa_cfill(im, count, x, y, mode, fill);
53 im_clear_error(aIMCTX);
55 i_push_error(0, "Yep, it's broken");
56 i_push_error(errno, "Error writing");
57 im_push_error(aIMCTX, 0, "Something is wrong");
59 va_start(args, lastarg);
60 im_push_errorvf(ctx, code, format, args);
61 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
62 im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
65 im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
66 i_set_image_file_limits(500, 500, 1000000);
67 im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
68 i_get_image_file_limits(&width, &height, &bytes)
69 im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
70 i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
73 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
74 i_fill_t *fill = i_new_fill_solid(&color, combine);
75 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
76 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
77 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
78 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
79 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
83 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
84 ssize_t result = i_io_write(io, buffer, size)
86 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
91 # Image creation/destruction
92 i_img *img = i_sametype(src, width, height);
93 i_img *img = i_sametype_chans(src, width, height, channels);
94 i_img *img = im_img_16_new(aIMCTX, width, height, channels);
95 i_img *img = i_img_16_new(width, height, channels);
96 i_img *img = im_img_8_new(aIMCTX, width, height, channels);
97 i_img *img = i_img_8_new(width, height, channels);
98 i_img *img = im_img_double_new(aIMCTX, width, height, channels);
99 i_img *img = i_img_double_new(width, height, channels);
100 i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
101 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
104 # Image Implementation
105 i_img *im = im_img_alloc(aIMCTX);
106 i_img *im = i_img_alloc();
107 im_img_init(aIMCTX, im);
111 // only channel 0 writable
112 i_img_setmask(img, 0x01);
113 int mask = i_img_getmask(img);
114 int channels = i_img_getchannels(img);
115 i_img_dim width = i_img_get_width(im);
116 i_img_dim height = i_img_get_height(im);
123 i_mutex_t m = i_mutex_new();
131 i_tags_set(&img->tags, "i_comment", -1);
132 i_tags_setn(&img->tags, "i_xres", 204);
133 i_tags_setn(&img->tags, "i_yres", 196);
141 =item i_render_color(r, x, y, width, source, color)
143 Render the given color with the coverage specified by C<source[0]> to
146 Renders in normal combine mode.
152 =item i_render_delete(r)
154 Release an C<i_render> object.
160 =item i_render_fill(r, x, y, width, source, fill)
162 Render the given fill with the coverage in C<source[0]> through
169 =item i_render_line(r, x, y, width, source, fill)
171 Render the given fill with the coverage in C<source[0]> through
178 =item i_render_linef(r, x, y, width, source, fill)
180 Render the given fill with the coverage in C<source[0]> through
187 =item i_render_new(im, width)
189 Allocate a new C<i_render> object and initialize it.
206 This is Imager's image type.
208 It contains the following members:
214 C<channels> - the number of channels in the image
218 C<xsize>, C<ysize> - the width and height of the image in pixels
222 C<bytes> - the number of bytes used to store the image data. Undefined
223 where virtual is non-zero.
227 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
228 channels 1 and 2 are writable. There may be bits set for which there
229 are no channels in the image.
233 C<bits> - the number of bits stored per sample. Should be one of
234 i_8_bits, i_16_bits, i_double_bits.
238 C<type> - either i_direct_type for direct color images, or i_palette_type
243 C<virtual> - if zero then this image is-self contained. If non-zero
244 then this image could be an interface to some other implementation.
248 C<idata> - the image data. This should not be directly accessed. A new
249 image implementation can use this to store its image data.
250 i_img_destroy() will myfree() this pointer if it's non-null.
254 C<tags> - a structure storing the image's tags. This should only be
255 accessed via the i_tags_*() functions.
259 C<ext_data> - a pointer for use internal to an image implementation.
260 This should be freed by the image's destroy handler.
264 C<im_data> - data internal to Imager. This is initialized by
269 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
270 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
271 of the required image functions. An image implementation should
272 initialize these between calling i_img_alloc() and i_img_init().
276 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
277 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
278 paletted image function.
282 i_f_destroy - custom image destruction function. This should be used
283 to release memory if necessary.
287 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
291 i_f_psamp_bits - implements i_psamp_bits() for this image.
295 i_f_psamp - implements psamp() for this image.
299 i_f_psampf - implements psamp() for this image.
303 C<im_data> - image specific data internal to Imager.
307 C<context> - the Imager API context this image belongs to.
313 From: File imdatatypes.h
318 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
320 Type for 8-bit/sample color.
326 i_color is a union of:
332 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
336 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
340 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
344 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
345 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
346 reading/writing files.
350 channels - an array of four channels, eg C<c.channels[2]>.
356 From: File imdatatypes.h
360 This is the double/sample color type.
362 Its layout exactly corresponds to i_color.
366 From: File imdatatypes.h
372 This is the "abstract" base type for Imager's fill types.
374 Unless you're implementing a new fill type you'll typically treat this
379 From: File imdatatypes.h
385 A signed integer type that represents an image dimension or ordinate.
387 May be larger than int on some platforms.
391 From: File imdatatypes.h
395 printf("left %" i_DF "\n", i_DFc(x));
397 This is a constant string that can be used with functions like
398 printf() to format i_img_dim values after they're been cast with i_DFc().
400 Does not include the leading C<%>.
404 From: File imdatatypes.h
408 Cast an C<i_img_dim> value to a type for use with the i_DF format
413 From: File imdatatypes.h
417 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
421 From: File imdatatypes.h
425 printf("point (" i_DFp ")\n", i_DFcp(x, y));
427 Format a pair of C<i_img_dim> values. This format string I<does>
428 include the leading C<%>.
432 From: File imdatatypes.h
441 =item i_arc(im, x, y, rad, d1, d2, color)
444 i_arc(im, 50, 50, 20, 45, 135, &color);
446 Fills an arc centered at (x,y) with radius I<rad> covering the range
447 of angles in degrees from d1 to d2, with the color.
453 =item i_arc_aa(im, x, y, rad, d1, d2, color)
456 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
458 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
459 the range of angles in degrees from d1 to d2, with the color.
465 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
468 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
470 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
471 the range of angles in degrees from d1 to d2, with the fill object.
477 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
480 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
482 Fills an arc centered at (x,y) with radius I<rad> covering the range
483 of angles in degrees from d1 to d2, with the fill object.
489 =item i_box(im, x1, y1, x2, y2, color)
492 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
494 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
500 =item i_box_cfill(im, x1, y1, x2, y2, fill)
503 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
505 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
511 =item i_box_filled(im, x1, y1, x2, y2, color)
514 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
516 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
522 =item i_circle_aa(im, x, y, rad, color)
525 i_circle_aa(im, 50, 50, 45, &color);
527 Anti-alias fills a circle centered at (x,y) for radius I<rad> with
534 =item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
537 i_flood_cfill(im, 50, 50, fill);
539 Flood fills the 4-connected region starting from the point (C<seedx>,
540 C<seedy>) with C<fill>.
542 Returns false if (C<seedx>, C<seedy>) are outside the image.
548 =item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
551 i_flood_cfill_border(im, 50, 50, fill, border);
553 Flood fills the 4-connected region starting from the point (C<seedx>,
554 C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
557 Returns false if (C<seedx>, C<seedy>) are outside the image.
563 =item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
566 i_flood_fill(im, 50, 50, &color);
568 Flood fills the 4-connected region starting from the point (C<seedx>,
569 C<seedy>) with I<color>.
571 Returns false if (C<seedx>, C<seedy>) are outside the image.
577 =item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
580 i_flood_fill_border(im, 50, 50, &color, &border);
582 Flood fills the 4-connected region starting from the point (C<seedx>,
583 C<seedy>) with C<color>, fill stops when the fill reaches a pixels
584 with color C<border>.
586 Returns false if (C<seedx>, C<seedy>) are outside the image.
592 =item i_glin(im, l, r, y, colors)
595 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
597 Returns the number of pixels retrieved.
603 =item i_glinf(im, l, r, y, colors)
606 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
609 Returns the number of pixels retrieved.
615 =item i_gpal(im, left, right, y, indexes)
618 Reads palette indexes for the horizontal line (left, y) to (right-1,
621 Returns the number of indexes read.
623 Always returns 0 for direct color images.
629 =item i_gpix(im, C<x>, C<y>, C<color>)
632 Retrieves the C<color> of the pixel (x,y).
634 Returns 0 if the pixel was retrieved, or -1 if not.
640 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
643 Retrieves the color of the pixel (x,y) as a floating point color into
646 Returns 0 if the pixel was retrieved, or -1 if not.
652 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
655 Reads sample values from C<im> for the horizontal line (left, y) to
656 (right-1,y) for the channels specified by C<channels>, an array of int
657 with C<channel_count> elements.
659 If channels is NULL then the first channels_count channels are retrieved for
662 Returns the number of samples read (which should be (right-left) *
669 =item i_gsamp_bg(im, l, r, y, samples, out_channels, background)
672 Like C<i_gsampf()> but applies the source image color over a supplied
675 This is intended for output to image formats that don't support alpha
682 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
684 Reads integer samples scaled to C<bits> bits of precision into the
685 C<unsigned int> array C<samples>.
687 Expect this to be slow unless C<< bits == im->bits >>.
689 Returns the number of samples copied, or -1 on error.
691 Not all image types implement this method.
693 Pushes errors, but does not call C<i_clear_error()>.
699 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
702 Reads floating point sample values from C<im> for the horizontal line
703 (left, y) to (right-1,y) for the channels specified by C<channels>, an
704 array of int with channel_count elements.
706 If C<channels> is NULL then the first C<channel_count> channels are
707 retrieved for each pixel.
709 Returns the number of samples read (which should be (C<right>-C<left>)
716 =item i_gsampf_bg(im, l, r, y, samples, out_channels, background)
719 Like C<i_gsampf()> but applies the source image color over a supplied
722 This is intended for output to image formats that don't support alpha
729 =item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
732 =for stopwords Bresenham's
734 Draw a line to image using Bresenham's line drawing algorithm
736 im - image to draw to
737 x1 - starting x coordinate
738 y1 - starting x coordinate
739 x2 - starting x coordinate
740 y2 - starting x coordinate
741 color - color to write to image
742 endp - endpoint flag (boolean)
748 =item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
751 Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
753 The point (x2, y2) is drawn only if C<endp> is set.
759 =item i_plin(im, l, r, y, colors)
762 Sets (r-l) pixels starting from (l,y) using (r-l) values from
765 Returns the number of pixels set.
771 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
774 Sets (right-left) pixels starting from (left,y) using (right-left)
775 floating point colors from C<fcolors>.
777 Returns the number of pixels set.
783 =item i_poly_aa_cfill_m(im, count, x, y, mode, fill)
785 i_poly_aa_cfill(im, count, x, y, mode, fill);
787 Fill a polygon defined by the points specified by the x and y arrays with
788 the fill specified by C<fill>.
794 =item i_poly_aa_m(im, count, x, y, mode, color)
796 i_poly_aa_m(im, count, x, y, mode, color);
798 Fill a polygon defined by the points specified by the x and y arrays with
799 the color specified by C<color>.
805 =item i_poly_poly_aa(im, count, polys, mode, color)
807 i_poly_poly_aa(im, 1, &poly, mode, color);
809 Fill the C<count> polygons defined by C<polys> the color specified by
812 At least one polygon must be supplied.
814 All polygons must have at least 3 points.
820 =item i_poly_poly_aa_cfill(im, count, polys, mode, fill)
822 i_poly_poly_aa_cfill(im, 1, &poly, mode, fill);
824 Fill the C<count> polygons defined by C<polys> the fill specified by
827 At least one polygon must be supplied.
829 All polygons must have at least 3 points.
835 =item i_ppal(im, left, right, y, indexes)
838 Writes palette indexes for the horizontal line (left, y) to (right-1,
841 Returns the number of indexes written.
843 Always returns 0 for direct color images.
849 =item i_ppix(im, x, y, color)
852 Sets the pixel at (x,y) to I<color>.
854 Returns 0 if the pixel was drawn, or -1 if not.
856 Does no alpha blending, just copies the channels from the supplied
863 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
866 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
868 Returns 0 if the pixel was drawn, or -1 if not.
870 Does no alpha blending, just copies the channels from the supplied
877 =item i_psamp(im, left, right, y, samples, channels, channel_count)
879 Writes sample values from C<samples> to C<im> for the horizontal line
880 (left, y) to (right-1, y) inclusive for the channels specified by
881 C<channels>, an array of C<int> with C<channel_count> elements.
883 If C<channels> is C<NULL> then the first C<channels_count> channels
884 are written to for each pixel.
886 Returns the number of samples written, which should be (right - left)
887 * channel_count. If a channel not in the image is in channels, left
888 is negative, left is outside the image or y is outside the image,
889 returns -1 and pushes an error.
893 From: File immacros.h
895 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
897 Writes integer samples scaled to C<bits> bits of precision from the
898 C<unsigned int> array C<samples>.
900 Expect this to be slow unless C<< bits == im->bits >>.
902 Returns the number of samples copied, or -1 on error.
904 Not all image types implement this method.
906 Pushes errors, but does not call C<i_clear_error()>.
912 =item i_psampf(im, left, right, y, samples, channels, channel_count)
914 Writes floating point sample values from C<samples> to C<im> for the
915 horizontal line (left, y) to (right-1, y) inclusive for the channels
916 specified by C<channels>, an array of C<int> with C<channel_count>
919 If C<channels> is C<NULL> then the first C<channels_count> channels
920 are written to for each pixel.
922 Returns the number of samples written, which should be (right - left)
923 * channel_count. If a channel not in the image is in channels, left
924 is negative, left is outside the image or y is outside the image,
925 returns -1 and pushes an error.
929 From: File immacros.h
934 =head2 Error handling
938 =item i_push_errorf(int code, char const *fmt, ...)
940 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
942 A version of i_push_error() that does printf() like formatting.
944 Does not support perl specific format codes.
950 =item im_clear_error(ctx)
951 X<im_clear_error API>X<i_clear_error API>
953 im_clear_error(aIMCTX);
956 Clears the error stack.
958 Called by any Imager function before doing any other processing.
960 Also callable as C<i_clear_error()>.
966 =item im_push_error(ctx, code, message)
967 X<im_push_error API>X<i_push_error API>
969 i_push_error(0, "Yep, it's broken");
970 i_push_error(errno, "Error writing");
971 im_push_error(aIMCTX, 0, "Something is wrong");
973 Called by an Imager function to push an error message onto the stack.
975 No message is pushed if the stack is full (since this means someone
976 forgot to call i_clear_error(), or that a function that doesn't do
977 error handling is calling function that does.).
983 =item im_push_errorf(ctx, code, char const *fmt, ...)
985 im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
987 A version of im_push_error() that does printf() like formatting.
989 Does not support perl specific format codes.
995 =item im_push_errorvf(ctx, code, format, args)
996 X<im_push_error_vf API>X<i_push_errorvf API>
999 va_start(args, lastarg);
1000 im_push_errorvf(ctx, code, format, args);
1002 Intended for use by higher level functions, takes a varargs pointer
1003 and a format to produce the finally pushed error message.
1005 Does not support perl specific format codes.
1007 Also callable as C<i_push_errorvf(code, format, args)>
1020 =item i_get_file_background(im, &bg)
1023 Retrieve the file write background color tag from the image.
1025 If not present, C<bg> is set to black.
1027 Returns 1 if the C<i_background> tag was found and valid.
1033 =item i_get_file_backgroundf(im, &bg)
1036 Retrieve the file write background color tag from the image as a
1037 floating point color.
1039 Implemented in terms of i_get_file_background().
1041 If not present, C<bg> is set to black.
1043 Returns 1 if the C<i_background> tag was found and valid.
1049 =item im_get_image_file_limits(ctx, &width, &height, &bytes)
1050 X<im_get_image_file_limits API>X<i_get_image_file_limits>
1052 im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
1053 i_get_image_file_limits(&width, &height, &bytes)
1055 Retrieves the file limits set by i_set_image_file_limits().
1061 i_img_dim *width, *height - the maximum width and height of the image.
1065 size_t *bytes - size in memory of the image in bytes.
1069 Also callable as C<i_get_image_file_limits(&width, &height, &bytes)>.
1075 =item im_int_check_image_file_limits(width, height, channels, sample_size)
1076 X<im_int_check_image_file_limits API>X<i_int_check_image_file_limits>
1078 im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
1079 i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
1081 Checks the size of a file in memory against the configured image file
1084 This also range checks the values to those permitted by Imager and
1085 checks for overflows in calculating the size.
1087 Returns non-zero if the file is within limits.
1089 This function is intended to be called by image file read functions.
1091 Also callable as C<i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t)>.
1097 =item im_set_image_file_limits(ctx, width, height, bytes)
1098 X<im_set_image_file_limits API>X<i_set_image_file_limits API>
1100 im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
1101 i_set_image_file_limits(500, 500, 1000000);
1103 Set limits on the sizes of images read by Imager.
1105 Setting a limit to 0 means that limit is ignored.
1107 Negative limits result in failure.
1115 i_img_dim width, height - maximum width and height.
1119 size_t bytes - maximum size in memory in bytes. A value of zero sets
1120 this limit to one gigabyte.
1124 Returns non-zero on success.
1126 Also callable as C<i_set_image_file_limits(width, height, bytes)>.
1139 =item i_new_fill_fount(C<xa>, C<ya>, C<xb>, C<yb>, C<type>, C<repeat>, C<combine>, C<super_sample>, C<ssample_param>, C<count>, C<segs>)
1142 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
1143 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
1146 Creates a new general fill which fills with a fountain fill.
1150 From: File filters.im
1152 =item i_new_fill_hatch(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1155 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
1157 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1158 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1159 values will be combined.
1161 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1162 hash definition, with the high-bits to the left.
1164 If C<cust_hatch> is NULL then one of the standard hatches is used.
1166 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1167 adjoining areas out of alignment, or to align the origin of a hatch
1168 with the side of a filled area.
1174 =item i_new_fill_hatchf(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1177 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
1179 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1180 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1181 values will be combined.
1183 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1184 hash definition, with the high-bits to the left.
1186 If C<cust_hatch> is NULL then one of the standard hatches is used.
1188 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1189 adjoining areas out of alignment, or to align the origin of a hatch
1190 with the side of a filled area.
1196 =item i_new_fill_image(C<im>, C<matrix>, C<xoff>, C<yoff>, C<combine>)
1199 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
1201 Create an image based fill.
1203 matrix is an array of 9 doubles representing a transformation matrix.
1205 C<xoff> and C<yoff> are the offset into the image to start filling from.
1211 =item i_new_fill_solid(color, combine)
1214 i_fill_t *fill = i_new_fill_solid(&color, combine);
1216 Create a solid fill based on an 8-bit color.
1218 If combine is non-zero then alpha values will be combined.
1224 =item i_new_fill_solidf(color, combine)
1227 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
1229 Create a solid fill based on a float color.
1231 If combine is non-zero then alpha values will be combined.
1237 =item i_fill_destroy(fill)
1239 i_fill_destroy(fill);
1241 Call to destroy any fill object.
1254 =item im_io_new_bufchain(ctx)
1255 X<im_io_new_bufchain API>X<i_io_new_bufchain API>
1257 Returns a new io_glue object that has the 'empty' source and but can
1258 be written to and read from later (like a pseudo file).
1260 Also callable as C<io_new_bufchain()>.
1264 From: File iolayer.c
1266 =item im_io_new_buffer(ctx, data, length)
1267 X<im_io_new_buffer API>X<io_new_buffer API>
1269 Returns a new io_glue object that has the source defined as reading
1270 from specified buffer. Note that the buffer is not copied.
1272 ctx - an Imager context object
1273 data - buffer to read from
1274 length - length of buffer
1276 Also callable as C<io_new_buffer(data, length>.
1280 From: File iolayer.c
1282 =item im_io_new_cb(ctx, p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
1283 X<im_io_new_cb API>X<io_new_cb API>
1285 Create a new I/O layer object that calls your supplied callbacks.
1287 In general the callbacks should behave like the corresponding POSIX
1294 C<read_cb>(p, buffer, length) should read up to C<length> bytes into
1295 C<buffer> and return the number of bytes read. At end of file, return
1296 0. On error, return -1.
1300 C<write_cb>(p, buffer, length) should write up to C<length> bytes from
1301 C<buffer> and return the number of bytes written. A return value <= 0
1302 will be treated as an error.
1306 C<seekcb>(p, offset, whence) should seek and return the new offset.
1310 C<close_cb>(p) should return 0 on success, -1 on failure.
1314 C<destroy_cb>(p) should release any memory specific to your callback
1319 Also callable as C<io_new_cb(p, readcb, writecb, seekcb, closecb,
1324 From: File iolayer.c
1326 =item im_io_new_fd(ctx, file)
1327 X<io_new_fd API>X<im_io_new_fd API>
1329 Returns a new io_glue object that has the source defined as reading
1330 from specified file descriptor. Note that the interface to receiving
1331 data from the io_glue callbacks hasn't been done yet.
1333 ctx - and Imager context object
1334 file - file descriptor to read/write from
1336 Also callable as C<io_new_fd(file)>.
1340 From: File iolayer.c
1342 =item i_io_close(io)
1344 Flush any pending output and perform the close action for the stream.
1346 Returns 0 on success.
1350 From: File iolayer.c
1352 =item i_io_flush(io)
1354 Flush any buffered output.
1356 Returns true on success,
1360 From: File iolayer.c
1364 A macro to read a single byte from a buffered I/O glue object.
1366 Returns EOF on failure, or a byte.
1370 From: File iolayer.c
1372 =item i_io_gets(ig, buffer, size, end_of_line)
1375 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
1377 Read up to C<size>-1 bytes from the stream C<ig> into C<buffer>.
1379 If the byte C<end_of_line> is seen then no further bytes will be read.
1381 Returns the number of bytes read.
1383 Always C<NUL> terminates the buffer.
1387 From: File iolayer.c
1389 =item i_io_peekc(ig)
1391 Read the next character from the stream without advancing the stream.
1393 On error or end of file, return EOF.
1395 For unbuffered streams a single character buffer will be setup.
1399 From: File iolayer.c
1401 =item i_io_peekn(ig, buffer, size)
1403 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
1405 Buffer at least C<size> (at most C<< ig->buf_size >> bytes of data
1406 from the stream and return C<size> bytes of it to the caller in
1409 This ignores the buffered state of the stream, and will always setup
1410 buffering if needed.
1412 If no C<type> parameter is provided to Imager::read() or
1413 Imager::read_multi(), Imager will call C<i_io_peekn()> when probing
1414 for the file format.
1416 Returns -1 on error, 0 if there is no data before EOF, or the number
1417 of bytes read into C<buffer>.
1421 From: File iolayer.c
1423 =item i_io_putc(ig, c)
1425 Write a single character to the stream.
1427 On success return c, on error returns EOF
1431 From: File iolayer.c
1433 =item i_io_read(io, buffer, size)
1435 Read up to C<size> bytes from the stream C<io> into C<buffer>.
1437 Returns the number of bytes read. Returns 0 on end of file. Returns
1442 From: File iolayer.c
1444 =item i_io_seek(io, offset, whence)
1446 Seek within the stream.
1448 Acts like perl's seek.
1452 From: File iolayer.c
1454 =item i_io_set_buffered(io, buffered)
1456 Set the buffering mode of the stream.
1458 If you switch buffering off on a stream with buffering on:
1464 any buffered output will be flushed.
1468 any existing buffered input will be consumed before reads become
1473 Returns true on success. This may fail if any buffered output cannot
1478 From: File iolayer.c
1480 =item i_io_write(io, buffer, size)
1482 ssize_t result = i_io_write(io, buffer, size)
1484 Write to the given I/O stream.
1486 Returns the number of bytes written.
1490 From: File iolayer.c
1492 =item io_slurp(ig, c)
1495 Takes the source that the io_glue is bound to and allocates space for
1496 a return buffer and returns the entire content in a single buffer.
1497 Note: This only works for io_glue objects created by
1498 io_new_bufchain(). It is useful for saving to scalars and such.
1501 c - pointer to a pointer to where data should be copied to
1504 size_t size = io_slurp(ig, &data);
1505 ... do something with the data ...
1508 io_slurp() will abort the program if the supplied I/O layer is not
1509 from io_new_bufchain().
1513 From: File iolayer.c
1515 =item io_glue_destroy(ig)
1516 X<io_glue_destroy API>
1518 io_glue_destroy(ig);
1520 Destroy an io_glue objects. Should clean up all related buffers.
1522 ig - io_glue object to destroy.
1526 From: File iolayer.c
1535 =item i_copy(source)
1538 Creates a new image that is a copy of the image C<source>.
1540 Tags are not copied, only the image data.
1548 =item i_copyto(C<dest>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>)
1551 Copies image data from the area (C<x1>,C<y1>)-[C<x2>,C<y2>] in the
1552 source image to a rectangle the same size with it's top-left corner at
1553 (C<tx>,C<ty>) in the destination image.
1555 If C<x1> > C<x2> or C<y1> > C<y2> then the corresponding co-ordinates
1562 =item i_copyto_trans(C<im>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>, C<trans>)
1565 (C<x1>,C<y1>) (C<x2>,C<y2>) specifies the region to copy (in the
1566 source coordinates) (C<tx>,C<ty>) specifies the upper left corner for
1567 the target image. pass NULL in C<trans> for non transparent i_colors.
1573 =item i_img_info(im, info)
1576 Return image information
1579 info - pointer to array to return data
1581 info is an array of 4 integers with the following values:
1586 info[3] - channel mask
1592 =item i_rubthru(C<im>, C<src>, C<tx>, C<ty>, C<src_minx>, C<src_miny>, C<src_maxx>, C<src_maxy>)
1595 Takes the sub image C<src>[C<src_minx>, C<src_maxx>)[C<src_miny>, C<src_maxy>)> and
1596 overlays it at (C<tx>,C<ty>) on the image object.
1598 The alpha channel of each pixel in C<src> is used to control how much
1599 the existing color in C<im> is replaced, if it is 255 then the color
1600 is completely replaced, if it is 0 then the original color is left
1605 From: File rubthru.im
1610 =head2 Image creation/destruction
1614 =item i_sametype(C<im>, C<xsize>, C<ysize>)
1617 i_img *img = i_sametype(src, width, height);
1619 Returns an image of the same type (sample size, channels, paletted/direct).
1621 For paletted images the palette is copied from the source.
1627 =item i_sametype_chans(C<im>, C<xsize>, C<ysize>, C<channels>)
1630 i_img *img = i_sametype_chans(src, width, height, channels);
1632 Returns an image of the same type (sample size).
1634 For paletted images the equivalent direct type is returned.
1640 =item im_img_16_new(ctx, x, y, ch)
1641 X<im_img_16_new API>X<i_img_16_new API>
1643 i_img *img = im_img_16_new(aIMCTX, width, height, channels);
1644 i_img *img = i_img_16_new(width, height, channels);
1646 Create a new 16-bit/sample image.
1648 Returns the image on success, or NULL on failure.
1650 Also callable as C<i_img_16_new(x, y, ch)>
1656 =item im_img_8_new(ctx, x, y, ch)
1657 X<im_img_8_new API>X<i_img_8_new API>
1659 i_img *img = im_img_8_new(aIMCTX, width, height, channels);
1660 i_img *img = i_img_8_new(width, height, channels);
1662 Creates a new image object I<x> pixels wide, and I<y> pixels high with
1669 =item im_img_double_new(ctx, x, y, ch)
1670 X<im_img_double_new API>X<i_img_double_new API>
1672 i_img *img = im_img_double_new(aIMCTX, width, height, channels);
1673 i_img *img = i_img_double_new(width, height, channels);
1675 Creates a new double per sample image.
1677 Also callable as C<i_img_double_new(width, height, channels)>.
1681 From: File imgdouble.c
1683 =item im_img_pal_new(ctx, C<x>, C<y>, C<channels>, C<maxpal>)
1684 X<im_img_pal_new API>X<i_img_pal_new API>
1686 i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
1687 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
1689 Creates a new paletted image of the supplied dimensions.
1691 C<maxpal> is the maximum palette size and should normally be 256.
1693 Returns a new image or NULL on failure.
1695 Also callable as C<i_img_pal_new(width, height, channels, max_palette_size)>.
1701 =item i_img_destroy(C<img>)
1705 Destroy an image object
1714 =head2 Image Implementation
1718 =item im_img_alloc(aIMCTX)
1719 X<im_img_alloc API>X<i_img_alloc API>
1721 i_img *im = im_img_alloc(aIMCTX);
1722 i_img *im = i_img_alloc();
1724 Allocates a new i_img structure.
1726 When implementing a new image type perform the following steps in your
1727 image object creation function:
1733 allocate the image with i_img_alloc().
1737 initialize any function pointers or other data as needed, you can
1738 overwrite the whole block if you need to.
1742 initialize Imager's internal data by calling i_img_init() on the image
1751 =item im_img_init(aIMCTX, image)
1752 X<im_img_init API>X<i_img_init API>
1754 im_img_init(aIMCTX, im);
1757 Imager internal initialization of images.
1759 See L</im_img_alloc(aIMCTX)> for more information.
1768 =head2 Image Information
1772 =item i_img_color_channels(C<im>)
1775 The number of channels holding color information.
1779 From: File immacros.h
1781 =item i_img_get_height(C<im>)
1783 i_img_dim height = i_img_get_height(im);
1785 Returns the height in pixels of the image.
1791 =item i_img_get_width(C<im>)
1793 i_img_dim width = i_img_get_width(im);
1795 Returns the width in pixels of the image.
1801 =item i_img_getchannels(C<im>)
1803 int channels = i_img_getchannels(img);
1805 Get the number of channels in C<im>.
1811 =item i_img_getmask(C<im>)
1813 int mask = i_img_getmask(img);
1815 Get the image channel mask for C<im>.
1821 =item i_img_has_alpha(C<im>)
1824 Return true if the image has an alpha channel.
1828 From: File immacros.h
1830 =item i_img_is_monochrome(img, &zero_is_white)
1833 Tests an image to check it meets our monochrome tests.
1835 The idea is that a file writer can use this to test where it should
1836 write the image in whatever bi-level format it uses, eg. C<pbm> for
1839 For performance of encoders we require monochrome images:
1849 have a palette of two colors, containing only C<(0,0,0)> and
1850 C<(255,255,255)> in either order.
1854 C<zero_is_white> is set to non-zero if the first palette entry is white.
1860 =item i_img_setmask(C<im>, C<ch_mask>)
1862 // only channel 0 writable
1863 i_img_setmask(img, 0x01);
1865 Set the image channel mask for C<im> to C<ch_mask>.
1867 The image channel mask gives some control over which channels can be
1868 written to in the image.
1877 =head2 Image quantization
1881 =item i_quant_makemap(C<quant>, C<imgs>, C<count>)
1884 Analyzes the C<count> images in C<imgs> according to the rules in
1885 C<quant> to build a color map (optimal or not depending on
1886 C<< quant->make_colors >>).
1892 =item i_quant_translate(C<quant>, C<img>)
1895 Quantize the image given the palette in C<quant>.
1897 On success returns a pointer to a memory block of C<< img->xsize *
1898 img->ysize >> C<i_palidx> entries.
1900 On failure returns NULL.
1902 You should call myfree() on the returned block when you're done with
1905 This function will fail if the supplied palette contains no colors.
1911 =item i_quant_transparent(C<quant>, C<data>, C<img>, C<trans_index>)
1914 Dither the alpha channel on C<img> into the palette indexes in
1915 C<data>. Pixels to be transparent are replaced with C<trans_pixel>.
1917 The method used depends on the tr_* members of C<quant>.
1930 =item i_lhead(file, line)
1932 This is an internal function called by the mm_log() macro.
1938 =item i_loog(level, format, ...)
1940 This is an internal function called by the mm_log() macro.
1949 =head2 Mutex functions
1955 i_mutex_t m = i_mutex_new();
1959 If a critical section cannot be created for whatever reason, Imager
1964 From: File mutexwin.c
1966 =item i_mutex_destroy(m)
1974 From: File mutexwin.c
1976 =item i_mutex_lock(m)
1980 Lock the mutex, waiting if another thread has the mutex locked.
1984 From: File mutexwin.c
1986 =item i_mutex_unlock(m)
1992 The behavior of releasing a mutex you don't hold is unspecified.
1996 From: File mutexwin.c
2001 =head2 Paletted images
2005 =item i_addcolors(im, colors, count)
2008 Adds colors to the image's palette.
2010 On success returns the index of the lowest color added.
2012 On failure returns -1.
2014 Always fails for direct color images.
2020 =item i_colorcount(im)
2023 Returns the number of colors in the image's palette.
2025 Returns -1 for direct images.
2031 =item i_findcolor(im, color, &entry)
2034 Searches the images palette for the given color.
2036 On success sets *I<entry> to the index of the color, and returns true.
2038 On failure returns false.
2040 Always fails on direct color images.
2046 =item i_getcolors(im, index, colors, count)
2049 Retrieves I<count> colors starting from I<index> in the image's
2052 On success stores the colors into I<colors> and returns true.
2054 On failure returns false.
2056 Always fails for direct color images.
2058 Fails if there are less than I<index>+I<count> colors in the image's
2065 =item i_maxcolors(im)
2068 Returns the maximum number of colors the palette can hold for the
2071 Returns -1 for direct color images.
2077 =item i_setcolors(im, index, colors, count)
2080 Sets I<count> colors starting from I<index> in the image's palette.
2082 On success returns true.
2084 On failure returns false.
2086 The image must have at least I<index>+I<count> colors in it's palette
2087 for this to succeed.
2089 Always fails on direct color images.
2102 =item i_tags_delbycode(tags, code)
2105 Delete any tags with the given code.
2107 Returns the number of tags deleted.
2113 =item i_tags_delbyname(tags, name)
2116 Delete any tags with the given name.
2118 Returns the number of tags deleted.
2124 =item i_tags_delete(tags, index)
2127 Delete a tag by index.
2129 Returns true on success.
2135 =item i_tags_destroy(tags)
2138 Destroys the given tags structure. Called by i_img_destroy().
2144 =item i_tags_find(tags, name, start, &entry)
2147 Searches for a tag of the given I<name> starting from index I<start>.
2149 On success returns true and sets *I<entry>.
2151 On failure returns false.
2157 =item i_tags_findn(tags, code, start, &entry)
2160 Searches for a tag of the given I<code> starting from index I<start>.
2162 On success returns true and sets *I<entry>.
2164 On failure returns false.
2170 =item i_tags_get_color(tags, name, code, &value)
2173 Retrieve a tag specified by name or code as color.
2175 On success sets the i_color *I<value> to the color and returns true.
2177 On failure returns false.
2183 =item i_tags_get_float(tags, name, code, value)
2186 Retrieves a tag as a floating point value.
2188 If the tag has a string value then that is parsed as a floating point
2189 number, otherwise the integer value of the tag is used.
2191 On success sets *I<value> and returns true.
2193 On failure returns false.
2199 =item i_tags_get_int(tags, name, code, &value)
2202 Retrieve a tag specified by name or code as an integer.
2204 On success sets the int *I<value> to the integer and returns true.
2206 On failure returns false.
2212 =item i_tags_get_string(tags, name, code, value, value_size)
2215 Retrieves a tag by name or code as a string.
2217 On success copies the string to value for a max of value_size and
2220 On failure returns false.
2222 value_size must be at least large enough for a string representation
2225 The copied value is always C<NUL> terminated.
2231 =item i_tags_new(i_img_tags *tags)
2234 Initialize a tags structure. Should not be used if the tags structure
2235 has been previously used.
2237 This should be called tags member of an i_img object on creation (in
2238 i_img_*_new() functions).
2240 To destroy the contents use i_tags_destroy()
2246 =item i_tags_set(tags, name, data, size)
2248 i_tags_set(&img->tags, "i_comment", -1);
2250 Sets the given tag to the string I<data>
2252 If size is -1 then the strlen(I<data>) bytes are stored.
2254 Even on failure, if an existing tag I<name> exists, it will be
2261 =item i_tags_set_color(tags, name, code, &value)
2264 Stores the given color as a tag with the given name and code.
2270 =item i_tags_set_float(tags, name, code, value)
2273 Equivalent to i_tags_set_float2(tags, name, code, value, 30).
2279 =item i_tags_set_float2(tags, name, code, value, places)
2282 Sets the tag with the given name and code to the given floating point
2285 Since tags are strings or ints, we convert the value to a string before
2286 storage at the precision specified by C<places>.
2292 =item i_tags_setn(C<tags>, C<name>, C<idata>)
2294 i_tags_setn(&img->tags, "i_xres", 204);
2295 i_tags_setn(&img->tags, "i_yres", 196);
2297 Sets the given tag to the integer C<idata>
2299 Even on failure, if an existing tag C<name> exists, it will be
2309 =head2 Uncategorized functions
2313 =item i_utf8_advance(char **p, size_t *len)
2315 Retrieve a C<UTF-8> character from the stream.
2317 Modifies *p and *len to indicate the consumed characters.
2319 This doesn't support the extended C<UTF-8> encoding used by later
2320 versions of Perl. Since this is typically used to implement text
2321 output by font drivers, the strings supplied shouldn't have such out
2322 of range characters.
2324 This doesn't check that the C<UTF-8> character is using the shortest
2325 possible representation.
2327 Returns ~0UL on failure.
2333 =item im_context_refdec(ctx, where)
2334 X<im_context_refdec API>
2335 =section Context objects
2337 im_context_refdec(aIMCTX, "a description");
2339 Remove a reference to the context, releasing it if all references have
2344 From: File context.c
2346 =item im_context_refinc(ctx, where)
2347 X<im_context_refinc API>
2348 =section Context objects
2350 im_context_refinc(aIMCTX, "a description");
2352 Add a new reference to the context.
2356 From: File context.c
2358 =item im_context_slot_get(ctx, slot)
2360 Retrieve the value previously stored in the given slot of the context
2365 From: File context.c
2367 =item im_context_slot_new(destructor)
2369 Allocate a new context-local-storage slot.
2371 C<desctructor> will be called when the context is destroyed if the
2372 corresponding slot is non-NULL.
2376 From: File context.c
2378 =item im_context_slot_set(slot, value)
2380 Set the value of a slot.
2382 Returns true on success.
2384 Aborts if the slot supplied is invalid.
2386 If reallocation of slot storage fails, returns false.
2390 From: File context.c
2392 =item im_errors(ctx)
2394 i_errmsg *errors = im_errors(aIMCTX);
2395 i_errmsg *errors = i_errors();
2397 Returns a pointer to the first element of an array of error messages,
2398 terminated by a NULL pointer. The highest level message is first.
2400 Also callable as C<i_errors()>.
2406 =item im_get_context()
2408 Retrieve the context object for the current thread.
2410 Inside Imager itself this is just a function pointer, which the
2411 F<Imager.xs> BOOT handler initializes for use within perl. If you're
2412 taking the Imager code and embedding it elsewhere you need to
2413 initialize the C<im_get_context> pointer at some point.
2426 The following API functions are undocumented so far, hopefully this
2450 Tony Cook <tonyc@cpan.org>
2454 Imager, Imager::API, Imager::ExtUtils, Imager::Inline