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;
22 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
25 printf("left %" i_DF "\n", i_DFc(x));
26 printf("point (" i_DFp ")\n", i_DFcp(x, y));
29 i_arc(im, 50, 50, 20, 45, 135, &color);
30 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
31 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
32 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
33 i_circle_aa(im, 50, 50, 45, &color);
34 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
35 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
36 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
37 i_flood_fill(im, 50, 50, &color);
38 i_flood_cfill(im, 50, 50, fill);
39 i_flood_fill_border(im, 50, 50, &color, &border);
40 i_flood_cfill_border(im, 50, 50, fill, border);
43 im_clear_error(aIMCTX);
45 i_push_error(0, "Yep, it's broken");
46 i_push_error(errno, "Error writing");
47 im_push_error(aIMCTX, 0, "Something is wrong");
49 va_start(args, lastarg);
50 im_push_errorvf(ctx, code, format, args);
51 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
52 im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
55 im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
56 i_set_image_file_limits(500, 500, 1000000);
57 im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
58 i_get_image_file_limits(&width, &height, &bytes)
59 im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
60 i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
63 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
64 i_fill_t *fill = i_new_fill_solid(&color, combine);
65 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
66 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
67 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
68 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
69 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
73 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
74 ssize_t result = i_io_write(io, buffer, size)
76 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
81 # Image creation/destruction
82 i_img *img = i_sametype(src, width, height);
83 i_img *img = i_sametype_chans(src, width, height, channels);
84 i_img *img = im_img_16_new(aIMCTX, width, height, channels);
85 i_img *img = i_img_16_new(width, height, channels);
86 i_img *img = im_img_8_new(aIMCTX, width, height, channels);
87 i_img *img = i_img_8_new(width, height, channels);
88 i_img *img = im_img_double_new(aIMCTX, width, height, channels);
89 i_img *img = i_img_double_new(width, height, channels);
90 i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
91 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
94 # Image Implementation
95 i_img *im = im_img_alloc(aIMCTX);
96 i_img *im = i_img_alloc();
97 im_img_init(aIMCTX, im);
101 // only channel 0 writable
102 i_img_setmask(img, 0x01);
103 int mask = i_img_getmask(img);
104 int channels = i_img_getchannels(img);
105 i_img_dim width = i_img_get_width(im);
106 i_img_dim height = i_img_get_height(im);
113 i_mutex_t m = i_mutex_new();
121 i_tags_set(&img->tags, "i_comment", -1);
122 i_tags_setn(&img->tags, "i_xres", 204);
123 i_tags_setn(&img->tags, "i_yres", 196);
131 =item i_render_color(r, x, y, width, source, color)
133 Render the given color with the coverage specified by C<source[0]> to
136 Renders in normal combine mode.
142 =item i_render_delete(r)
144 Release an C<i_render> object.
150 =item i_render_fill(r, x, y, width, source, fill)
152 Render the given fill with the coverage in C<source[0]> through
159 =item i_render_line(r, x, y, width, source, fill)
161 Render the given fill with the coverage in C<source[0]> through
168 =item i_render_linef(r, x, y, width, source, fill)
170 Render the given fill with the coverage in C<source[0]> through
177 =item i_render_new(im, width)
179 Allocate a new C<i_render> object and initialize it.
196 This is Imager's image type.
198 It contains the following members:
204 C<channels> - the number of channels in the image
208 C<xsize>, C<ysize> - the width and height of the image in pixels
212 C<bytes> - the number of bytes used to store the image data. Undefined
213 where virtual is non-zero.
217 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
218 channels 1 and 2 are writable. There may be bits set for which there
219 are no channels in the image.
223 C<bits> - the number of bits stored per sample. Should be one of
224 i_8_bits, i_16_bits, i_double_bits.
228 C<type> - either i_direct_type for direct color images, or i_palette_type
233 C<virtual> - if zero then this image is-self contained. If non-zero
234 then this image could be an interface to some other implementation.
238 C<idata> - the image data. This should not be directly accessed. A new
239 image implementation can use this to store its image data.
240 i_img_destroy() will myfree() this pointer if it's non-null.
244 C<tags> - a structure storing the image's tags. This should only be
245 accessed via the i_tags_*() functions.
249 C<ext_data> - a pointer for use internal to an image implementation.
250 This should be freed by the image's destroy handler.
254 C<im_data> - data internal to Imager. This is initialized by
259 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
260 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
261 of the required image functions. An image implementation should
262 initialize these between calling i_img_alloc() and i_img_init().
266 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
267 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
268 paletted image function.
272 i_f_destroy - custom image destruction function. This should be used
273 to release memory if necessary.
277 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
281 i_f_psamp_bits - implements i_psamp_bits() for this image.
285 i_f_psamp - implements psamp() for this image.
289 i_f_psampf - implements psamp() for this image.
293 C<im_data> - image specific data internal to Imager.
297 C<context> - the Imager API context this image belongs to.
303 From: File imdatatypes.h
308 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
310 Type for 8-bit/sample color.
316 i_color is a union of:
322 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
326 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
330 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
334 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
335 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
336 reading/writing files.
340 channels - an array of four channels, eg C<c.channels[2]>.
346 From: File imdatatypes.h
350 This is the double/sample color type.
352 Its layout exactly corresponds to i_color.
356 From: File imdatatypes.h
362 This is the "abstract" base type for Imager's fill types.
364 Unless you're implementing a new fill type you'll typically treat this
369 From: File imdatatypes.h
375 A signed integer type that represents an image dimension or ordinate.
377 May be larger than int on some platforms.
381 From: File imdatatypes.h
385 printf("left %" i_DF "\n", i_DFc(x));
387 This is a constant string that can be used with functions like
388 printf() to format i_img_dim values after they're been cast with i_DFc().
390 Does not include the leading C<%>.
394 From: File imdatatypes.h
398 Cast an C<i_img_dim> value to a type for use with the i_DF format
403 From: File imdatatypes.h
407 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
411 From: File imdatatypes.h
415 printf("point (" i_DFp ")\n", i_DFcp(x, y));
417 Format a pair of C<i_img_dim> values. This format string I<does>
418 include the leading C<%>.
422 From: File imdatatypes.h
431 =item i_arc(im, x, y, rad, d1, d2, color)
434 i_arc(im, 50, 50, 20, 45, 135, &color);
436 Fills an arc centered at (x,y) with radius I<rad> covering the range
437 of angles in degrees from d1 to d2, with the color.
443 =item i_arc_aa(im, x, y, rad, d1, d2, color)
446 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
448 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
449 the range of angles in degrees from d1 to d2, with the color.
455 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
458 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
460 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
461 the range of angles in degrees from d1 to d2, with the fill object.
467 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
470 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
472 Fills an arc centered at (x,y) with radius I<rad> covering the range
473 of angles in degrees from d1 to d2, with the fill object.
479 =item i_box(im, x1, y1, x2, y2, color)
482 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
484 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
490 =item i_box_cfill(im, x1, y1, x2, y2, fill)
493 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
495 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
501 =item i_box_filled(im, x1, y1, x2, y2, color)
504 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
506 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
512 =item i_circle_aa(im, x, y, rad, color)
515 i_circle_aa(im, 50, 50, 45, &color);
517 Anti-alias fills a circle centered at (x,y) for radius I<rad> with
524 =item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
527 i_flood_cfill(im, 50, 50, fill);
529 Flood fills the 4-connected region starting from the point (C<seedx>,
530 C<seedy>) with C<fill>.
532 Returns false if (C<seedx>, C<seedy>) are outside the image.
538 =item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
541 i_flood_cfill_border(im, 50, 50, fill, border);
543 Flood fills the 4-connected region starting from the point (C<seedx>,
544 C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
547 Returns false if (C<seedx>, C<seedy>) are outside the image.
553 =item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
556 i_flood_fill(im, 50, 50, &color);
558 Flood fills the 4-connected region starting from the point (C<seedx>,
559 C<seedy>) with I<color>.
561 Returns false if (C<seedx>, C<seedy>) are outside the image.
567 =item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
570 i_flood_fill_border(im, 50, 50, &color, &border);
572 Flood fills the 4-connected region starting from the point (C<seedx>,
573 C<seedy>) with C<color>, fill stops when the fill reaches a pixels
574 with color C<border>.
576 Returns false if (C<seedx>, C<seedy>) are outside the image.
582 =item i_glin(im, l, r, y, colors)
585 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
587 Returns the number of pixels retrieved.
593 =item i_glinf(im, l, r, y, colors)
596 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
599 Returns the number of pixels retrieved.
605 =item i_gpal(im, left, right, y, indexes)
608 Reads palette indexes for the horizontal line (left, y) to (right-1,
611 Returns the number of indexes read.
613 Always returns 0 for direct color images.
619 =item i_gpix(im, C<x>, C<y>, C<color>)
622 Retrieves the C<color> of the pixel (x,y).
624 Returns 0 if the pixel was retrieved, or -1 if not.
630 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
633 Retrieves the color of the pixel (x,y) as a floating point color into
636 Returns 0 if the pixel was retrieved, or -1 if not.
642 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
645 Reads sample values from C<im> for the horizontal line (left, y) to
646 (right-1,y) for the channels specified by C<channels>, an array of int
647 with C<channel_count> elements.
649 If channels is NULL then the first channels_count channels are retrieved for
652 Returns the number of samples read (which should be (right-left) *
659 =item i_gsamp_bg(im, l, r, y, samples, out_channels, background)
662 Like C<i_gsampf()> but applies the source image color over a supplied
665 This is intended for output to image formats that don't support alpha
672 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
674 Reads integer samples scaled to C<bits> bits of precision into the
675 C<unsigned int> array C<samples>.
677 Expect this to be slow unless C<< bits == im->bits >>.
679 Returns the number of samples copied, or -1 on error.
681 Not all image types implement this method.
683 Pushes errors, but does not call C<i_clear_error()>.
689 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
692 Reads floating point sample values from C<im> for the horizontal line
693 (left, y) to (right-1,y) for the channels specified by C<channels>, an
694 array of int with channel_count elements.
696 If C<channels> is NULL then the first C<channel_count> channels are
697 retrieved for each pixel.
699 Returns the number of samples read (which should be (C<right>-C<left>)
706 =item i_gsampf_bg(im, l, r, y, samples, out_channels, background)
709 Like C<i_gsampf()> but applies the source image color over a supplied
712 This is intended for output to image formats that don't support alpha
719 =item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
722 =for stopwords Bresenham's
724 Draw a line to image using Bresenham's line drawing algorithm
726 im - image to draw to
727 x1 - starting x coordinate
728 y1 - starting x coordinate
729 x2 - starting x coordinate
730 y2 - starting x coordinate
731 color - color to write to image
732 endp - endpoint flag (boolean)
738 =item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
741 Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
743 The point (x2, y2) is drawn only if C<endp> is set.
749 =item i_plin(im, l, r, y, colors)
752 Sets (r-l) pixels starting from (l,y) using (r-l) values from
755 Returns the number of pixels set.
761 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
764 Sets (right-left) pixels starting from (left,y) using (right-left)
765 floating point colors from C<fcolors>.
767 Returns the number of pixels set.
773 =item i_ppal(im, left, right, y, indexes)
776 Writes palette indexes for the horizontal line (left, y) to (right-1,
779 Returns the number of indexes written.
781 Always returns 0 for direct color images.
787 =item i_ppix(im, x, y, color)
790 Sets the pixel at (x,y) to I<color>.
792 Returns 0 if the pixel was drawn, or -1 if not.
794 Does no alpha blending, just copies the channels from the supplied
801 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
804 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
806 Returns 0 if the pixel was drawn, or -1 if not.
808 Does no alpha blending, just copies the channels from the supplied
815 =item i_psamp(im, left, right, y, samples, channels, channel_count)
817 Writes sample values from C<samples> to C<im> for the horizontal line
818 (left, y) to (right-1, y) inclusive for the channels specified by
819 C<channels>, an array of C<int> with C<channel_count> elements.
821 If C<channels> is C<NULL> then the first C<channels_count> channels
822 are written to for each pixel.
824 Returns the number of samples written, which should be (right - left)
825 * channel_count. If a channel not in the image is in channels, left
826 is negative, left is outside the image or y is outside the image,
827 returns -1 and pushes an error.
831 From: File immacros.h
833 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
835 Writes integer samples scaled to C<bits> bits of precision from the
836 C<unsigned int> array C<samples>.
838 Expect this to be slow unless C<< bits == im->bits >>.
840 Returns the number of samples copied, or -1 on error.
842 Not all image types implement this method.
844 Pushes errors, but does not call C<i_clear_error()>.
850 =item i_psampf(im, left, right, y, samples, channels, channel_count)
852 Writes floating point sample values from C<samples> to C<im> for the
853 horizontal line (left, y) to (right-1, y) inclusive for the channels
854 specified by C<channels>, an array of C<int> with C<channel_count>
857 If C<channels> is C<NULL> then the first C<channels_count> channels
858 are written to for each pixel.
860 Returns the number of samples written, which should be (right - left)
861 * channel_count. If a channel not in the image is in channels, left
862 is negative, left is outside the image or y is outside the image,
863 returns -1 and pushes an error.
867 From: File immacros.h
872 =head2 Error handling
876 =item i_push_errorf(int code, char const *fmt, ...)
878 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
880 A version of i_push_error() that does printf() like formatting.
882 Does not support perl specific format codes.
888 =item im_clear_error(ctx)
889 X<im_clear_error API>X<i_clear_error API>
891 im_clear_error(aIMCTX);
894 Clears the error stack.
896 Called by any Imager function before doing any other processing.
898 Also callable as C<i_clear_error()>.
904 =item im_push_error(ctx, code, message)
905 X<im_push_error API>X<i_push_error API>
907 i_push_error(0, "Yep, it's broken");
908 i_push_error(errno, "Error writing");
909 im_push_error(aIMCTX, 0, "Something is wrong");
911 Called by an Imager function to push an error message onto the stack.
913 No message is pushed if the stack is full (since this means someone
914 forgot to call i_clear_error(), or that a function that doesn't do
915 error handling is calling function that does.).
921 =item im_push_errorf(ctx, code, char const *fmt, ...)
923 im_push_errorf(aIMCTX, errno, "Cannot open file %s: %d", filename, errno);
925 A version of im_push_error() that does printf() like formatting.
927 Does not support perl specific format codes.
933 =item im_push_errorvf(ctx, code, format, args)
934 X<im_push_error_vf API>X<i_push_errorvf API>
937 va_start(args, lastarg);
938 im_push_errorvf(ctx, code, format, args);
940 Intended for use by higher level functions, takes a varargs pointer
941 and a format to produce the finally pushed error message.
943 Does not support perl specific format codes.
945 Also callable as C<i_push_errorvf(code, format, args)>
958 =item i_get_file_background(im, &bg)
961 Retrieve the file write background color tag from the image.
963 If not present, C<bg> is set to black.
965 Returns 1 if the C<i_background> tag was found and valid.
971 =item i_get_file_backgroundf(im, &bg)
974 Retrieve the file write background color tag from the image as a
975 floating point color.
977 Implemented in terms of i_get_file_background().
979 If not present, C<bg> is set to black.
981 Returns 1 if the C<i_background> tag was found and valid.
987 =item im_get_image_file_limits(ctx, &width, &height, &bytes)
988 X<im_get_image_file_limits API>X<i_get_image_file_limits>
990 im_get_image_file_limits(aIMCTX, &width, &height, &bytes)
991 i_get_image_file_limits(&width, &height, &bytes)
993 Retrieves the file limits set by i_set_image_file_limits().
999 i_img_dim *width, *height - the maximum width and height of the image.
1003 size_t *bytes - size in memory of the image in bytes.
1007 Also callable as C<i_get_image_file_limits(&width, &height, &bytes)>.
1013 =item im_int_check_image_file_limits(width, height, channels, sample_size)
1014 X<im_int_check_image_file_limits API>X<i_int_check_image_file_limits>
1016 im_int_check_image_file_limits(aIMCTX, width, height, channels, sizeof(i_sample_t))
1017 i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
1019 Checks the size of a file in memory against the configured image file
1022 This also range checks the values to those permitted by Imager and
1023 checks for overflows in calculating the size.
1025 Returns non-zero if the file is within limits.
1027 This function is intended to be called by image file read functions.
1029 Also callable as C<i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t)>.
1035 =item im_set_image_file_limits(ctx, width, height, bytes)
1036 X<im_set_image_file_limits API>X<i_set_image_file_limits API>
1038 im_set_image_file_limits(aIMCTX, 500, 500, 1000000);
1039 i_set_image_file_limits(500, 500, 1000000);
1041 Set limits on the sizes of images read by Imager.
1043 Setting a limit to 0 means that limit is ignored.
1045 Negative limits result in failure.
1053 i_img_dim width, height - maximum width and height.
1057 size_t bytes - maximum size in memory in bytes. A value of zero sets
1058 this limit to one gigabyte.
1062 Returns non-zero on success.
1064 Also callable as C<i_set_image_file_limits(width, height, bytes)>.
1077 =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>)
1080 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
1081 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
1084 Creates a new general fill which fills with a fountain fill.
1088 From: File filters.im
1090 =item i_new_fill_hatch(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1093 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
1095 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1096 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1097 values will be combined.
1099 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1100 hash definition, with the high-bits to the left.
1102 If C<cust_hatch> is NULL then one of the standard hatches is used.
1104 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1105 adjoining areas out of alignment, or to align the origin of a hatch
1106 with the the side of a filled area.
1112 =item i_new_fill_hatchf(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1115 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
1117 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1118 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1119 values will be combined.
1121 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1122 hash definition, with the high-bits to the left.
1124 If C<cust_hatch> is NULL then one of the standard hatches is used.
1126 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1127 adjoining areas out of alignment, or to align the origin of a hatch
1128 with the the side of a filled area.
1134 =item i_new_fill_image(C<im>, C<matrix>, C<xoff>, C<yoff>, C<combine>)
1137 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
1139 Create an image based fill.
1141 matrix is an array of 9 doubles representing a transformation matrix.
1143 C<xoff> and C<yoff> are the offset into the image to start filling from.
1149 =item i_new_fill_solid(color, combine)
1152 i_fill_t *fill = i_new_fill_solid(&color, combine);
1154 Create a solid fill based on an 8-bit color.
1156 If combine is non-zero then alpha values will be combined.
1162 =item i_new_fill_solidf(color, combine)
1165 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
1167 Create a solid fill based on a float color.
1169 If combine is non-zero then alpha values will be combined.
1175 =item i_fill_destroy(fill)
1177 i_fill_destroy(fill);
1179 Call to destroy any fill object.
1192 =item im_io_new_bufchain(ctx)
1193 X<im_io_new_bufchain API>X<i_io_new_bufchain API>
1195 Returns a new io_glue object that has the 'empty' source and but can
1196 be written to and read from later (like a pseudo file).
1198 Also callable as C<io_new_bufchain()>.
1202 From: File iolayer.c
1204 =item im_io_new_buffer(ctx, data, length)
1205 X<im_io_new_buffer API>X<io_new_buffer API>
1207 Returns a new io_glue object that has the source defined as reading
1208 from specified buffer. Note that the buffer is not copied.
1210 ctx - an Imager context object
1211 data - buffer to read from
1212 length - length of buffer
1214 Also callable as C<io_new_buffer(data, length>.
1218 From: File iolayer.c
1220 =item im_io_new_cb(ctx, p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
1221 X<im_io_new_cb API>X<io_new_cb API>
1223 Create a new I/O layer object that calls your supplied callbacks.
1225 In general the callbacks should behave like the corresponding POSIX
1232 C<read_cb>(p, buffer, length) should read up to C<length> bytes into
1233 C<buffer> and return the number of bytes read. At end of file, return
1234 0. On error, return -1.
1238 C<write_cb>(p, buffer, length) should write up to C<length> bytes from
1239 C<buffer> and return the number of bytes written. A return value <= 0
1240 will be treated as an error.
1244 C<seekcb>(p, offset, whence) should seek and return the new offset.
1248 C<close_cb>(p) should return 0 on success, -1 on failure.
1252 C<destroy_cb>(p) should release any memory specific to your callback
1257 Also callable as C<io_new_cb(p, readcb, writecb, seekcb, closecb,
1262 From: File iolayer.c
1264 =item im_io_new_fd(ctx, file)
1265 X<io_new_fd API>X<im_io_new_fd API>
1267 Returns a new io_glue object that has the source defined as reading
1268 from specified file descriptor. Note that the the interface to receiving
1269 data from the io_glue callbacks hasn't been done yet.
1271 ctx - and Imager context object
1272 file - file descriptor to read/write from
1274 Also callable as C<io_new_fd(file)>.
1278 From: File iolayer.c
1280 =item i_io_close(io)
1282 Flush any pending output and perform the close action for the stream.
1284 Returns 0 on success.
1288 From: File iolayer.c
1290 =item i_io_flush(io)
1292 Flush any buffered output.
1294 Returns true on success,
1298 From: File iolayer.c
1302 A macro to read a single byte from a buffered I/O glue object.
1304 Returns EOF on failure, or a byte.
1308 From: File iolayer.c
1310 =item i_io_gets(ig, buffer, size, end_of_line)
1313 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
1315 Read up to C<size>-1 bytes from the stream C<ig> into C<buffer>.
1317 If the byte C<end_of_line> is seen then no further bytes will be read.
1319 Returns the number of bytes read.
1321 Always C<NUL> terminates the buffer.
1325 From: File iolayer.c
1327 =item i_io_peekc(ig)
1329 Read the next character from the stream without advancing the stream.
1331 On error or end of file, return EOF.
1333 For unbuffered streams a single character buffer will be setup.
1337 From: File iolayer.c
1339 =item i_io_peekn(ig, buffer, size)
1341 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
1343 Buffer at least C<size> (at most C<< ig->buf_size >> bytes of data
1344 from the stream and return C<size> bytes of it to the caller in
1347 This ignores the buffered state of the stream, and will always setup
1348 buffering if needed.
1350 If no C<type> parameter is provided to Imager::read() or
1351 Imager::read_multi(), Imager will call C<i_io_peekn()> when probing
1352 for the file format.
1354 Returns -1 on error, 0 if there is no data before EOF, or the number
1355 of bytes read into C<buffer>.
1359 From: File iolayer.c
1361 =item i_io_putc(ig, c)
1363 Write a single character to the stream.
1365 On success return c, on error returns EOF
1369 From: File iolayer.c
1371 =item i_io_read(io, buffer, size)
1373 Read up to C<size> bytes from the stream C<io> into C<buffer>.
1375 Returns the number of bytes read. Returns 0 on end of file. Returns
1380 From: File iolayer.c
1382 =item i_io_seek(io, offset, whence)
1384 Seek within the stream.
1386 Acts like perl's seek.
1390 From: File iolayer.c
1392 =item i_io_set_buffered(io, buffered)
1394 Set the buffering mode of the stream.
1396 If you switch buffering off on a stream with buffering on:
1402 any buffered output will be flushed.
1406 any existing buffered input will be consumed before reads become
1411 Returns true on success. This may fail if any buffered output cannot
1416 From: File iolayer.c
1418 =item i_io_write(io, buffer, size)
1420 ssize_t result = i_io_write(io, buffer, size)
1422 Write to the given I/O stream.
1424 Returns the number of bytes written.
1428 From: File iolayer.c
1430 =item io_slurp(ig, c)
1433 Takes the source that the io_glue is bound to and allocates space for
1434 a return buffer and returns the entire content in a single buffer.
1435 Note: This only works for io_glue objects created by
1436 io_new_bufchain(). It is useful for saving to scalars and such.
1439 c - pointer to a pointer to where data should be copied to
1442 size_t size = io_slurp(ig, &data);
1443 ... do something with the data ...
1446 io_slurp() will abort the program if the supplied I/O layer is not
1447 from io_new_bufchain().
1451 From: File iolayer.c
1453 =item io_glue_destroy(ig)
1454 X<io_glue_destroy API>
1456 io_glue_destroy(ig);
1458 Destroy an io_glue objects. Should clean up all related buffers.
1460 ig - io_glue object to destroy.
1464 From: File iolayer.c
1473 =item i_copy(source)
1476 Creates a new image that is a copy of the image C<source>.
1478 Tags are not copied, only the image data.
1486 =item i_copyto(C<dest>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>)
1489 Copies image data from the area (C<x1>,C<y1>)-[C<x2>,C<y2>] in the
1490 source image to a rectangle the same size with it's top-left corner at
1491 (C<tx>,C<ty>) in the destination image.
1493 If C<x1> > C<x2> or C<y1> > C<y2> then the corresponding co-ordinates
1500 =item i_copyto_trans(C<im>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>, C<trans>)
1503 (C<x1>,C<y1>) (C<x2>,C<y2>) specifies the region to copy (in the
1504 source coordinates) (C<tx>,C<ty>) specifies the upper left corner for
1505 the target image. pass NULL in C<trans> for non transparent i_colors.
1511 =item i_img_info(im, info)
1514 Return image information
1517 info - pointer to array to return data
1519 info is an array of 4 integers with the following values:
1524 info[3] - channel mask
1530 =item i_rubthru(C<im>, C<src>, C<tx>, C<ty>, C<src_minx>, C<src_miny>, C<src_maxx>, C<src_maxy>)
1533 Takes the sub image C<src>[C<src_minx>, C<src_maxx>)[C<src_miny>, C<src_maxy>)> and
1534 overlays it at (C<tx>,C<ty>) on the image object.
1536 The alpha channel of each pixel in C<src> is used to control how much
1537 the existing color in C<im> is replaced, if it is 255 then the color
1538 is completely replaced, if it is 0 then the original color is left
1543 From: File rubthru.im
1548 =head2 Image creation/destruction
1552 =item i_sametype(C<im>, C<xsize>, C<ysize>)
1555 i_img *img = i_sametype(src, width, height);
1557 Returns an image of the same type (sample size, channels, paletted/direct).
1559 For paletted images the palette is copied from the source.
1565 =item i_sametype_chans(C<im>, C<xsize>, C<ysize>, C<channels>)
1568 i_img *img = i_sametype_chans(src, width, height, channels);
1570 Returns an image of the same type (sample size).
1572 For paletted images the equivalent direct type is returned.
1578 =item im_img_16_new(ctx, x, y, ch)
1579 X<im_img_16_new API>X<i_img_16_new API>
1581 i_img *img = im_img_16_new(aIMCTX, width, height, channels);
1582 i_img *img = i_img_16_new(width, height, channels);
1584 Create a new 16-bit/sample image.
1586 Returns the image on success, or NULL on failure.
1588 Also callable as C<i_img_16_new(x, y, ch)>
1594 =item im_img_8_new(ctx, x, y, ch)
1595 X<im_img_8_new API>X<i_img_8_new API>
1597 i_img *img = im_img_8_new(aIMCTX, width, height, channels);
1598 i_img *img = i_img_8_new(width, height, channels);
1600 Creates a new image object I<x> pixels wide, and I<y> pixels high with
1607 =item im_img_double_new(ctx, x, y, ch)
1608 X<im_img_double_new API>X<i_img_double_new API>
1610 i_img *img = im_img_double_new(aIMCTX, width, height, channels);
1611 i_img *img = i_img_double_new(width, height, channels);
1613 Creates a new double per sample image.
1615 Also callable as C<i_img_double_new(width, height, channels)>.
1619 From: File imgdouble.c
1621 =item im_img_pal_new(ctx, C<x>, C<y>, C<channels>, C<maxpal>)
1622 X<im_img_pal_new API>X<i_img_pal_new API>
1624 i_img *img = im_img_pal_new(aIMCTX, width, height, channels, max_palette_size)
1625 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
1627 Creates a new paletted image of the supplied dimensions.
1629 C<maxpal> is the maximum palette size and should normally be 256.
1631 Returns a new image or NULL on failure.
1633 Also callable as C<i_img_pal_new(width, height, channels, max_palette_size)>.
1639 =item i_img_destroy(C<img>)
1643 Destroy an image object
1652 =head2 Image Implementation
1656 =item im_img_alloc(aIMCTX)
1657 X<im_img_alloc API>X<i_img_alloc API>
1659 i_img *im = im_img_alloc(aIMCTX);
1660 i_img *im = i_img_alloc();
1662 Allocates a new i_img structure.
1664 When implementing a new image type perform the following steps in your
1665 image object creation function:
1671 allocate the image with i_img_alloc().
1675 initialize any function pointers or other data as needed, you can
1676 overwrite the whole block if you need to.
1680 initialize Imager's internal data by calling i_img_init() on the image
1689 =item im_img_init(aIMCTX, image)
1690 X<im_img_init API>X<i_img_init API>
1692 im_img_init(aIMCTX, im);
1695 Imager internal initialization of images.
1697 See L</im_img_alloc(aIMCTX)> for more information.
1706 =head2 Image Information
1710 =item i_img_color_channels(C<im>)
1713 The number of channels holding color information.
1717 From: File immacros.h
1719 =item i_img_get_height(C<im>)
1721 i_img_dim height = i_img_get_height(im);
1723 Returns the height in pixels of the image.
1729 =item i_img_get_width(C<im>)
1731 i_img_dim width = i_img_get_width(im);
1733 Returns the width in pixels of the image.
1739 =item i_img_getchannels(C<im>)
1741 int channels = i_img_getchannels(img);
1743 Get the number of channels in C<im>.
1749 =item i_img_getmask(C<im>)
1751 int mask = i_img_getmask(img);
1753 Get the image channel mask for C<im>.
1759 =item i_img_has_alpha(C<im>)
1762 Return true if the image has an alpha channel.
1766 From: File immacros.h
1768 =item i_img_is_monochrome(img, &zero_is_white)
1771 Tests an image to check it meets our monochrome tests.
1773 The idea is that a file writer can use this to test where it should
1774 write the image in whatever bi-level format it uses, eg. C<pbm> for
1777 For performance of encoders we require monochrome images:
1787 have a palette of two colors, containing only C<(0,0,0)> and
1788 C<(255,255,255)> in either order.
1792 C<zero_is_white> is set to non-zero if the first palette entry is white.
1798 =item i_img_setmask(C<im>, C<ch_mask>)
1800 // only channel 0 writable
1801 i_img_setmask(img, 0x01);
1803 Set the image channel mask for C<im> to C<ch_mask>.
1805 The image channel mask gives some control over which channels can be
1806 written to in the image.
1815 =head2 Image quantization
1819 =item i_quant_makemap(C<quant>, C<imgs>, C<count>)
1822 Analyzes the C<count> images in C<imgs> according to the rules in
1823 C<quant> to build a color map (optimal or not depending on
1824 C<< quant->make_colors >>).
1830 =item i_quant_translate(C<quant>, C<img>)
1833 Quantize the image given the palette in C<quant>.
1835 On success returns a pointer to a memory block of C<< img->xsize *
1836 img->ysize >> C<i_palidx> entries.
1838 On failure returns NULL.
1840 You should call myfree() on the returned block when you're done with
1843 This function will fail if the supplied palette contains no colors.
1849 =item i_quant_transparent(C<quant>, C<data>, C<img>, C<trans_index>)
1852 Dither the alpha channel on C<img> into the palette indexes in
1853 C<data>. Pixels to be transparent are replaced with C<trans_pixel>.
1855 The method used depends on the tr_* members of C<quant>.
1868 =item i_lhead(file, line)
1870 This is an internal function called by the mm_log() macro.
1876 =item i_loog(level, format, ...)
1878 This is an internal function called by the mm_log() macro.
1887 =head2 Mutex functions
1893 i_mutex_t m = i_mutex_new();
1897 If a critical section cannot be created for whatever reason, Imager
1902 From: File mutexwin.c
1904 =item i_mutex_destroy(m)
1912 From: File mutexwin.c
1914 =item i_mutex_lock(m)
1918 Lock the mutex, waiting if another thread has the mutex locked.
1922 From: File mutexwin.c
1924 =item i_mutex_unlock(m)
1930 The behavior of releasing a mutex you don't hold is unspecified.
1934 From: File mutexwin.c
1939 =head2 Paletted images
1943 =item i_addcolors(im, colors, count)
1946 Adds colors to the image's palette.
1948 On success returns the index of the lowest color added.
1950 On failure returns -1.
1952 Always fails for direct color images.
1958 =item i_colorcount(im)
1961 Returns the number of colors in the image's palette.
1963 Returns -1 for direct images.
1969 =item i_findcolor(im, color, &entry)
1972 Searches the images palette for the given color.
1974 On success sets *I<entry> to the index of the color, and returns true.
1976 On failure returns false.
1978 Always fails on direct color images.
1984 =item i_getcolors(im, index, colors, count)
1987 Retrieves I<count> colors starting from I<index> in the image's
1990 On success stores the colors into I<colors> and returns true.
1992 On failure returns false.
1994 Always fails for direct color images.
1996 Fails if there are less than I<index>+I<count> colors in the image's
2003 =item i_maxcolors(im)
2006 Returns the maximum number of colors the palette can hold for the
2009 Returns -1 for direct color images.
2015 =item i_setcolors(im, index, colors, count)
2018 Sets I<count> colors starting from I<index> in the image's palette.
2020 On success returns true.
2022 On failure returns false.
2024 The image must have at least I<index>+I<count> colors in it's palette
2025 for this to succeed.
2027 Always fails on direct color images.
2040 =item i_tags_delbycode(tags, code)
2043 Delete any tags with the given code.
2045 Returns the number of tags deleted.
2051 =item i_tags_delbyname(tags, name)
2054 Delete any tags with the given name.
2056 Returns the number of tags deleted.
2062 =item i_tags_delete(tags, index)
2065 Delete a tag by index.
2067 Returns true on success.
2073 =item i_tags_destroy(tags)
2076 Destroys the given tags structure. Called by i_img_destroy().
2082 =item i_tags_find(tags, name, start, &entry)
2085 Searches for a tag of the given I<name> starting from index I<start>.
2087 On success returns true and sets *I<entry>.
2089 On failure returns false.
2095 =item i_tags_findn(tags, code, start, &entry)
2098 Searches for a tag of the given I<code> starting from index I<start>.
2100 On success returns true and sets *I<entry>.
2102 On failure returns false.
2108 =item i_tags_get_color(tags, name, code, &value)
2111 Retrieve a tag specified by name or code as color.
2113 On success sets the i_color *I<value> to the color and returns true.
2115 On failure returns false.
2121 =item i_tags_get_float(tags, name, code, value)
2124 Retrieves a tag as a floating point value.
2126 If the tag has a string value then that is parsed as a floating point
2127 number, otherwise the integer value of the tag is used.
2129 On success sets *I<value> and returns true.
2131 On failure returns false.
2137 =item i_tags_get_int(tags, name, code, &value)
2140 Retrieve a tag specified by name or code as an integer.
2142 On success sets the int *I<value> to the integer and returns true.
2144 On failure returns false.
2150 =item i_tags_get_string(tags, name, code, value, value_size)
2153 Retrieves a tag by name or code as a string.
2155 On success copies the string to value for a max of value_size and
2158 On failure returns false.
2160 value_size must be at least large enough for a string representation
2163 The copied value is always C<NUL> terminated.
2169 =item i_tags_new(i_img_tags *tags)
2172 Initialize a tags structure. Should not be used if the tags structure
2173 has been previously used.
2175 This should be called tags member of an i_img object on creation (in
2176 i_img_*_new() functions).
2178 To destroy the contents use i_tags_destroy()
2184 =item i_tags_set(tags, name, data, size)
2186 i_tags_set(&img->tags, "i_comment", -1);
2188 Sets the given tag to the string I<data>
2190 If size is -1 then the strlen(I<data>) bytes are stored.
2192 Even on failure, if an existing tag I<name> exists, it will be
2199 =item i_tags_set_color(tags, name, code, &value)
2202 Stores the given color as a tag with the given name and code.
2208 =item i_tags_set_float(tags, name, code, value)
2211 Equivalent to i_tags_set_float2(tags, name, code, value, 30).
2217 =item i_tags_set_float2(tags, name, code, value, places)
2220 Sets the tag with the given name and code to the given floating point
2223 Since tags are strings or ints, we convert the value to a string before
2224 storage at the precision specified by C<places>.
2230 =item i_tags_setn(C<tags>, C<name>, C<idata>)
2232 i_tags_setn(&img->tags, "i_xres", 204);
2233 i_tags_setn(&img->tags, "i_yres", 196);
2235 Sets the given tag to the integer C<idata>
2237 Even on failure, if an existing tag C<name> exists, it will be
2247 =head2 Uncategorized functions
2251 =item i_utf8_advance(char **p, size_t *len)
2253 Retrieve a C<UTF-8> character from the stream.
2255 Modifies *p and *len to indicate the consumed characters.
2257 This doesn't support the extended C<UTF-8> encoding used by later
2258 versions of Perl. Since this is typically used to implement text
2259 output by font drivers, the strings supplied shouldn't have such out
2260 of range characters.
2262 This doesn't check that the C<UTF-8> character is using the shortest
2263 possible representation.
2265 Returns ~0UL on failure.
2271 =item im_context_refdec(ctx, where)
2272 X<im_context_refdec API>
2273 =section Context objects
2275 im_context_refdec(aIMCTX, "a description");
2277 Remove a reference to the context, releasing it if all references have
2282 From: File context.c
2284 =item im_context_refinc(ctx, where)
2285 X<im_context_refinc API>
2286 =section Context objects
2288 im_context_refinc(aIMCTX, "a description");
2290 Add a new reference to the context.
2294 From: File context.c
2296 =item im_context_slot_get(ctx, slot)
2298 Retrieve the value previously stored in the given slot of the context
2303 From: File context.c
2305 =item im_context_slot_new(destructor)
2307 Allocate a new context-local-storage slot.
2309 C<desctructor> will be called when the context is destroyed if the
2310 corresponding slot is non-NULL.
2314 From: File context.c
2316 =item im_context_slot_set(slot, value)
2318 Set the value of a slot.
2320 Returns true on success.
2322 Aborts if the slot supplied is invalid.
2324 If reallocation of slot storage fails, returns false.
2328 From: File context.c
2330 =item im_errors(ctx)
2332 i_errmsg *errors = im_errors(aIMCTX);
2333 i_errmsg *errors = i_errors();
2335 Returns a pointer to the first element of an array of error messages,
2336 terminated by a NULL pointer. The highest level message is first.
2338 Also callable as C<i_errors()>.
2344 =item im_get_context()
2346 Retrieve the context object for the current thread.
2348 Inside Imager itself this is just a function pointer, which the
2349 F<Imager.xs> BOOT handler initializes for use within perl. If you're
2350 taking the Imager code and embedding it elsewhere you need to
2351 initialize the C<im_get_context> pointer at some point.
2364 The following API functions are undocumented so far, hopefully this
2388 Tony Cook <tonyc@cpan.org>
2392 Imager, Imager::API, Imager::ExtUtils, Imager::Inline