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);
44 i_push_error(0, "Yep, it's broken");
45 i_push_error(errno, "Error writing");
46 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
49 i_set_image_file_limits(500, 500, 1000000);
50 i_get_image_file_limits(&width, &height, &bytes)
51 i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
54 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
55 i_fill_t *fill = i_new_fill_solid(&color, combine);
56 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
57 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
58 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
59 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
60 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
64 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
65 ssize_t result = i_io_write(io, buffer, size)
67 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
72 # Image creation/destruction
73 i_img *img = i_sametype(src, width, height);
74 i_img *img = i_sametype_chans(src, width, height, channels);
75 i_img *img = i_img_16_new(width, height, channels);
76 i_img *img = i_img_8_new(width, height, channels);
77 i_img *img = i_img_double_new(width, height, channels);
78 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
81 # Image Implementation
84 // only channel 0 writable
85 i_img_setmask(img, 0x01);
86 int mask = i_img_getmask(img);
87 int channels = i_img_getchannels(img);
88 i_img_dim width = i_img_get_width(im);
89 i_img_dim height = i_img_get_height(im);
98 i_tags_set(&img->tags, "i_comment", -1);
99 i_tags_setn(&img->tags, "i_xres", 204);
100 i_tags_setn(&img->tags, "i_yres", 196);
108 =item i_render_color(r, x, y, width, source, color)
110 Render the given color with the coverage specified by C<source[0]> to
113 Renders in normal combine mode.
119 =item i_render_delete(r)
121 Release an C<i_render> object.
127 =item i_render_fill(r, x, y, width, source, fill)
129 Render the given fill with the coverage in C<source[0]> through
136 =item i_render_line(r, x, y, width, source, fill)
138 Render the given fill with the coverage in C<source[0]> through
145 =item i_render_linef(r, x, y, width, source, fill)
147 Render the given fill with the coverage in C<source[0]> through
154 =item i_render_new(im, width)
156 Allocate a new C<i_render> object and initialize it.
173 This is Imager's image type.
175 It contains the following members:
181 C<channels> - the number of channels in the image
185 C<xsize>, C<ysize> - the width and height of the image in pixels
189 C<bytes> - the number of bytes used to store the image data. Undefined
190 where virtual is non-zero.
194 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
195 channels 1 and 2 are writable. There may be bits set for which there
196 are no channels in the image.
200 C<bits> - the number of bits stored per sample. Should be one of
201 i_8_bits, i_16_bits, i_double_bits.
205 C<type> - either i_direct_type for direct color images, or i_palette_type
210 C<virtual> - if zero then this image is-self contained. If non-zero
211 then this image could be an interface to some other implementation.
215 C<idata> - the image data. This should not be directly accessed. A new
216 image implementation can use this to store its image data.
217 i_img_destroy() will myfree() this pointer if it's non-null.
221 C<tags> - a structure storing the image's tags. This should only be
222 accessed via the i_tags_*() functions.
226 C<ext_data> - a pointer for use internal to an image implementation.
227 This should be freed by the image's destroy handler.
231 C<im_data> - data internal to Imager. This is initialized by
236 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
237 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
238 of the required image functions. An image implementation should
239 initialize these between calling i_img_alloc() and i_img_init().
243 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
244 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
245 paletted image function.
249 i_f_destroy - custom image destruction function. This should be used
250 to release memory if necessary.
254 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
258 i_f_psamp_bits - implements i_psamp_bits() for this image.
262 i_f_psamp - implements psamp() for this image.
266 i_f_psampf - implements psamp() for this image.
270 C<im_data> - image specific data internal to Imager.
274 C<context> - the Imager API context this image belongs to.
280 From: File imdatatypes.h
285 black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
287 Type for 8-bit/sample color.
293 i_color is a union of:
299 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
303 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
307 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
311 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
312 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
313 reading/writing files.
317 channels - an array of four channels, eg C<c.channels[2]>.
323 From: File imdatatypes.h
327 This is the double/sample color type.
329 Its layout exactly corresponds to i_color.
333 From: File imdatatypes.h
339 This is the "abstract" base type for Imager's fill types.
341 Unless you're implementing a new fill type you'll typically treat this
346 From: File imdatatypes.h
352 A signed integer type that represents an image dimension or ordinate.
354 May be larger than int on some platforms.
358 From: File imdatatypes.h
362 printf("left %" i_DF "\n", i_DFc(x));
364 This is a constant string that can be used with functions like
365 printf() to format i_img_dim values after they're been cast with i_DFc().
367 Does not include the leading C<%>.
371 From: File imdatatypes.h
375 Cast an C<i_img_dim> value to a type for use with the i_DF format
380 From: File imdatatypes.h
384 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
388 From: File imdatatypes.h
392 printf("point (" i_DFp ")\n", i_DFcp(x, y));
394 Format a pair of C<i_img_dim> values. This format string I<does>
395 include the leading C<%>.
399 From: File imdatatypes.h
408 =item i_arc(im, x, y, rad, d1, d2, color)
411 i_arc(im, 50, 50, 20, 45, 135, &color);
413 Fills an arc centered at (x,y) with radius I<rad> covering the range
414 of angles in degrees from d1 to d2, with the color.
420 =item i_arc_aa(im, x, y, rad, d1, d2, color)
423 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
425 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
426 the range of angles in degrees from d1 to d2, with the color.
432 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
435 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
437 Anti-alias fills an arc centered at (x,y) with radius I<rad> covering
438 the range of angles in degrees from d1 to d2, with the fill object.
444 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
447 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
449 Fills an arc centered at (x,y) with radius I<rad> covering the range
450 of angles in degrees from d1 to d2, with the fill object.
456 =item i_box(im, x1, y1, x2, y2, color)
459 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
461 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
467 =item i_box_cfill(im, x1, y1, x2, y2, fill)
470 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
472 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
478 =item i_box_filled(im, x1, y1, x2, y2, color)
481 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
483 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
489 =item i_circle_aa(im, x, y, rad, color)
492 i_circle_aa(im, 50, 50, 45, &color);
494 Anti-alias fills a circle centered at (x,y) for radius I<rad> with
501 =item i_flood_cfill(C<im>, C<seedx>, C<seedy>, C<fill>)
504 i_flood_cfill(im, 50, 50, fill);
506 Flood fills the 4-connected region starting from the point (C<seedx>,
507 C<seedy>) with C<fill>.
509 Returns false if (C<seedx>, C<seedy>) are outside the image.
515 =item i_flood_cfill_border(C<im>, C<seedx>, C<seedy>, C<fill>, C<border>)
518 i_flood_cfill_border(im, 50, 50, fill, border);
520 Flood fills the 4-connected region starting from the point (C<seedx>,
521 C<seedy>) with C<fill>, the fill stops when it reaches pixels of color
524 Returns false if (C<seedx>, C<seedy>) are outside the image.
530 =item i_flood_fill(C<im>, C<seedx>, C<seedy>, C<color>)
533 i_flood_fill(im, 50, 50, &color);
535 Flood fills the 4-connected region starting from the point (C<seedx>,
536 C<seedy>) with I<color>.
538 Returns false if (C<seedx>, C<seedy>) are outside the image.
544 =item i_flood_fill_border(C<im>, C<seedx>, C<seedy>, C<color>, C<border>)
547 i_flood_fill_border(im, 50, 50, &color, &border);
549 Flood fills the 4-connected region starting from the point (C<seedx>,
550 C<seedy>) with C<color>, fill stops when the fill reaches a pixels
551 with color C<border>.
553 Returns false if (C<seedx>, C<seedy>) are outside the image.
559 =item i_glin(im, l, r, y, colors)
562 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
564 Returns the number of pixels retrieved.
570 =item i_glinf(im, l, r, y, colors)
573 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
576 Returns the number of pixels retrieved.
582 =item i_gpal(im, left, right, y, indexes)
585 Reads palette indexes for the horizontal line (left, y) to (right-1,
588 Returns the number of indexes read.
590 Always returns 0 for direct color images.
596 =item i_gpix(im, C<x>, C<y>, C<color>)
599 Retrieves the C<color> of the pixel (x,y).
601 Returns 0 if the pixel was retrieved, or -1 if not.
607 =item i_gpixf(im, C<x>, C<y>, C<fcolor>)
610 Retrieves the color of the pixel (x,y) as a floating point color into
613 Returns 0 if the pixel was retrieved, or -1 if not.
619 =item i_gsamp(im, left, right, y, samples, channels, channel_count)
622 Reads sample values from C<im> for the horizontal line (left, y) to
623 (right-1,y) for the channels specified by C<channels>, an array of int
624 with C<channel_count> elements.
626 If channels is NULL then the first channels_count channels are retrieved for
629 Returns the number of samples read (which should be (right-left) *
636 =item i_gsamp_bg(im, l, r, y, samples, out_channels, background)
639 Like C<i_gsampf()> but applies the source image color over a supplied
642 This is intended for output to image formats that don't support alpha
649 =item i_gsamp_bits(im, left, right, y, samples, channels, channel_count, bits)
651 Reads integer samples scaled to C<bits> bits of precision into the
652 C<unsigned int> array C<samples>.
654 Expect this to be slow unless C<< bits == im->bits >>.
656 Returns the number of samples copied, or -1 on error.
658 Not all image types implement this method.
660 Pushes errors, but does not call C<i_clear_error()>.
666 =item i_gsampf(im, left, right, y, samples, channels, channel_count)
669 Reads floating point sample values from C<im> for the horizontal line
670 (left, y) to (right-1,y) for the channels specified by C<channels>, an
671 array of int with channel_count elements.
673 If C<channels> is NULL then the first C<channel_count> channels are
674 retrieved for each pixel.
676 Returns the number of samples read (which should be (C<right>-C<left>)
683 =item i_gsampf_bg(im, l, r, y, samples, out_channels, background)
686 Like C<i_gsampf()> but applies the source image color over a supplied
689 This is intended for output to image formats that don't support alpha
696 =item i_line(C<im>, C<x1>, C<y1>, C<x2>, C<y2>, C<color>, C<endp>)
699 =for stopwords Bresenham's
701 Draw a line to image using Bresenham's line drawing algorithm
703 im - image to draw to
704 x1 - starting x coordinate
705 y1 - starting x coordinate
706 x2 - starting x coordinate
707 y2 - starting x coordinate
708 color - color to write to image
709 endp - endpoint flag (boolean)
715 =item i_line_aa(C<im>, C<x1>, C<x2>, C<y1>, C<y2>, C<color>, C<endp>)
718 Anti-alias draws a line from (x1,y1) to (x2, y2) in color.
720 The point (x2, y2) is drawn only if C<endp> is set.
726 =item i_plin(im, l, r, y, colors)
729 Sets (r-l) pixels starting from (l,y) using (r-l) values from
732 Returns the number of pixels set.
738 =item i_plinf(im, C<left>, C<right>, C<fcolors>)
741 Sets (right-left) pixels starting from (left,y) using (right-left)
742 floating point colors from C<fcolors>.
744 Returns the number of pixels set.
750 =item i_ppal(im, left, right, y, indexes)
753 Writes palette indexes for the horizontal line (left, y) to (right-1,
756 Returns the number of indexes written.
758 Always returns 0 for direct color images.
764 =item i_ppix(im, x, y, color)
767 Sets the pixel at (x,y) to I<color>.
769 Returns 0 if the pixel was drawn, or -1 if not.
771 Does no alpha blending, just copies the channels from the supplied
778 =item i_ppixf(im, C<x>, C<y>, C<fcolor>)
781 Sets the pixel at (C<x>,C<y>) to the floating point color C<fcolor>.
783 Returns 0 if the pixel was drawn, or -1 if not.
785 Does no alpha blending, just copies the channels from the supplied
792 =item i_psamp(im, left, right, y, samples, channels, channel_count)
794 Writes sample values from C<samples> to C<im> for the horizontal line
795 (left, y) to (right-1, y) inclusive for the channels specified by
796 C<channels>, an array of C<int> with C<channel_count> elements.
798 If C<channels> is C<NULL> then the first C<channels_count> channels
799 are written to for each pixel.
801 Returns the number of samples written, which should be (right - left)
802 * channel_count. If a channel not in the image is in channels, left
803 is negative, left is outside the image or y is outside the image,
804 returns -1 and pushes an error.
808 From: File immacros.h
810 =item i_psamp_bits(im, left, right, y, samples, channels, channel_count, bits)
812 Writes integer samples scaled to C<bits> bits of precision from the
813 C<unsigned int> array C<samples>.
815 Expect this to be slow unless C<< bits == im->bits >>.
817 Returns the number of samples copied, or -1 on error.
819 Not all image types implement this method.
821 Pushes errors, but does not call C<i_clear_error()>.
827 =item i_psampf(im, left, right, y, samples, channels, channel_count)
829 Writes floating point sample values from C<samples> to C<im> for the
830 horizontal line (left, y) to (right-1, y) inclusive for the channels
831 specified by C<channels>, an array of C<int> with C<channel_count>
834 If C<channels> is C<NULL> then the first C<channels_count> channels
835 are written to for each pixel.
837 Returns the number of samples written, which should be (right - left)
838 * channel_count. If a channel not in the image is in channels, left
839 is negative, left is outside the image or y is outside the image,
840 returns -1 and pushes an error.
844 From: File immacros.h
849 =head2 Error handling
853 =item i_clear_error()
857 Clears the error stack.
859 Called by any Imager function before doing any other processing.
865 =item i_push_error(int code, char const *msg)
867 i_push_error(0, "Yep, it's broken");
868 i_push_error(errno, "Error writing");
870 Called by an Imager function to push an error message onto the stack.
872 No message is pushed if the stack is full (since this means someone
873 forgot to call i_clear_error(), or that a function that doesn't do
874 error handling is calling function that does.).
880 =item i_push_errorf(int code, char const *fmt, ...)
882 i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
884 A version of i_push_error() that does printf() like formatting.
886 Does not support perl specific format codes.
892 =item i_push_errorvf(int C<code>, char const *C<fmt>, va_list C<ap>)
895 Intended for use by higher level functions, takes a varargs pointer
896 and a format to produce the finally pushed error message.
898 Does not support perl specific format codes.
911 =item i_get_file_background(im, &bg)
914 Retrieve the file write background color tag from the image.
916 If not present, C<bg> is set to black.
918 Returns 1 if the C<i_background> tag was found and valid.
924 =item i_get_file_backgroundf(im, &bg)
927 Retrieve the file write background color tag from the image as a
928 floating point color.
930 Implemented in terms of i_get_file_background().
932 If not present, C<bg> is set to black.
934 Returns 1 if the C<i_background> tag was found and valid.
940 =item i_get_image_file_limits(&width, &height, &bytes)
943 i_get_image_file_limits(&width, &height, &bytes)
945 Retrieves the file limits set by i_set_image_file_limits().
951 i_img_dim *width, *height - the maximum width and height of the image.
955 size_t *bytes - size in memory of the image in bytes.
963 =item i_int_check_image_file_limits(width, height, channels, sample_size)
966 i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
968 Checks the size of a file in memory against the configured image file
971 This also range checks the values to those permitted by Imager and
972 checks for overflows in calculating the size.
974 Returns non-zero if the file is within limits.
976 This function is intended to be called by image file read functions.
982 =item i_set_image_file_limits(width, height, bytes)
985 i_set_image_file_limits(500, 500, 1000000);
987 Set limits on the sizes of images read by Imager.
989 Setting a limit to 0 means that limit is ignored.
991 Negative limits result in failure.
999 i_img_dim width, height - maximum width and height.
1003 size_t bytes - maximum size in memory in bytes. A value of zero sets
1004 this limit to one gigabyte.
1008 Returns non-zero on success.
1021 =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>)
1024 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
1025 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
1028 Creates a new general fill which fills with a fountain fill.
1032 From: File filters.im
1034 =item i_new_fill_hatch(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1037 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
1039 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1040 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1041 values will be combined.
1043 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1044 hash definition, with the high-bits to the left.
1046 If C<cust_hatch> is NULL then one of the standard hatches is used.
1048 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1049 adjoining areas out of alignment, or to align the origin of a hatch
1050 with the the side of a filled area.
1056 =item i_new_fill_hatchf(C<fg>, C<bg>, C<combine>, C<hatch>, C<cust_hatch>, C<dx>, C<dy>)
1059 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
1061 Creates a new hatched fill with the C<fg> color used for the 1 bits in
1062 the hatch and C<bg> for the 0 bits. If C<combine> is non-zero alpha
1063 values will be combined.
1065 If C<cust_hatch> is non-NULL it should be a pointer to 8 bytes of the
1066 hash definition, with the high-bits to the left.
1068 If C<cust_hatch> is NULL then one of the standard hatches is used.
1070 (C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
1071 adjoining areas out of alignment, or to align the origin of a hatch
1072 with the the side of a filled area.
1078 =item i_new_fill_image(C<im>, C<matrix>, C<xoff>, C<yoff>, C<combine>)
1081 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
1083 Create an image based fill.
1085 matrix is an array of 9 doubles representing a transformation matrix.
1087 C<xoff> and C<yoff> are the offset into the image to start filling from.
1093 =item i_new_fill_solid(color, combine)
1096 i_fill_t *fill = i_new_fill_solid(&color, combine);
1098 Create a solid fill based on an 8-bit color.
1100 If combine is non-zero then alpha values will be combined.
1106 =item i_new_fill_solidf(color, combine)
1109 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
1111 Create a solid fill based on a float color.
1113 If combine is non-zero then alpha values will be combined.
1119 =item i_fill_destroy(fill)
1121 i_fill_destroy(fill);
1123 Call to destroy any fill object.
1136 =item io_new_bufchain()
1138 returns a new io_glue object that has the 'empty' source and but can
1139 be written to and read from later (like a pseudo file).
1143 From: File iolayer.c
1145 =item io_new_buffer(data, length)
1147 Returns a new io_glue object that has the source defined as reading
1148 from specified buffer. Note that the buffer is not copied.
1150 data - buffer to read from
1151 length - length of buffer
1155 From: File iolayer.c
1157 =item io_new_cb(p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
1159 Create a new I/O layer object that calls your supplied callbacks.
1161 In general the callbacks should behave like the corresponding POSIX
1168 C<read_cb>(p, buffer, length) should read up to C<length> bytes into
1169 C<buffer> and return the number of bytes read. At end of file, return
1170 0. On error, return -1.
1174 C<write_cb>(p, buffer, length) should write up to C<length> bytes from
1175 C<buffer> and return the number of bytes written. A return value <= 0
1176 will be treated as an error.
1180 C<seekcb>(p, offset, whence) should seek and return the new offset.
1184 C<close_cb>(p) should return 0 on success, -1 on failure.
1188 C<destroy_cb>(p) should release any memory specific to your callback
1195 From: File iolayer.c
1199 returns a new io_glue object that has the source defined as reading
1200 from specified file descriptor. Note that the the interface to receiving
1201 data from the io_glue callbacks hasn't been done yet.
1203 fd - file descriptor to read/write from
1207 From: File iolayer.c
1209 =item i_io_close(io)
1211 Flush any pending output and perform the close action for the stream.
1213 Returns 0 on success.
1217 From: File iolayer.c
1219 =item i_io_flush(io)
1221 Flush any buffered output.
1223 Returns true on success,
1227 From: File iolayer.c
1231 A macro to read a single byte from a buffered I/O glue object.
1233 Returns EOF on failure, or a byte.
1237 From: File iolayer.c
1239 =item i_io_gets(ig, buffer, size, end_of_line)
1242 ssize_t len = i_io_gets(buffer, sizeof(buffer), '\n');
1244 Read up to C<size>-1 bytes from the stream C<ig> into C<buffer>.
1246 If the byte C<end_of_line> is seen then no further bytes will be read.
1248 Returns the number of bytes read.
1250 Always C<NUL> terminates the buffer.
1254 From: File iolayer.c
1256 =item i_io_peekc(ig)
1258 Read the next character from the stream without advancing the stream.
1260 On error or end of file, return EOF.
1262 For unbuffered streams a single character buffer will be setup.
1266 From: File iolayer.c
1268 =item i_io_peekn(ig, buffer, size)
1270 ssize_t count = i_io_peekn(ig, buffer, sizeof(buffer));
1272 Buffer at least C<size> (at most C<< ig->buf_size >> bytes of data
1273 from the stream and return C<size> bytes of it to the caller in
1276 This ignores the buffered state of the stream, and will always setup
1277 buffering if needed.
1279 If no C<type> parameter is provided to Imager::read() or
1280 Imager::read_multi(), Imager will call C<i_io_peekn()> when probing
1281 for the file format.
1283 Returns -1 on error, 0 if there is no data before EOF, or the number
1284 of bytes read into C<buffer>.
1288 From: File iolayer.c
1290 =item i_io_putc(ig, c)
1292 Write a single character to the stream.
1294 On success return c, on error returns EOF
1298 From: File iolayer.c
1300 =item i_io_read(io, buffer, size)
1302 Read up to C<size> bytes from the stream C<io> into C<buffer>.
1304 Returns the number of bytes read. Returns 0 on end of file. Returns
1309 From: File iolayer.c
1311 =item i_io_seek(io, offset, whence)
1313 Seek within the stream.
1315 Acts like perl's seek.
1319 From: File iolayer.c
1321 =item i_io_set_buffered(io, buffered)
1323 Set the buffering mode of the stream.
1325 If you switch buffering off on a stream with buffering on:
1331 any buffered output will be flushed.
1335 any existing buffered input will be consumed before reads become
1340 Returns true on success. This may fail if any buffered output cannot
1345 From: File iolayer.c
1347 =item i_io_write(io, buffer, size)
1349 ssize_t result = i_io_write(io, buffer, size)
1351 Write to the given I/O stream.
1353 Returns the number of bytes written.
1357 From: File iolayer.c
1359 =item io_slurp(ig, c)
1361 Takes the source that the io_glue is bound to and allocates space for
1362 a return buffer and returns the entire content in a single buffer.
1363 Note: This only works for io_glue objects created by
1364 io_new_bufchain(). It is useful for saving to scalars and such.
1367 c - pointer to a pointer to where data should be copied to
1370 size_t size = io_slurp(ig, &data);
1371 ... do something with the data ...
1374 io_slurp() will abort the program if the supplied I/O layer is not
1375 from io_new_bufchain().
1379 From: File iolayer.c
1381 =item io_glue_destroy(ig)
1383 io_glue_destroy(ig);
1385 Destroy an io_glue objects. Should clean up all related buffers.
1387 ig - io_glue object to destroy.
1391 From: File iolayer.c
1400 =item i_copy(source)
1403 Creates a new image that is a copy of the image C<source>.
1405 Tags are not copied, only the image data.
1413 =item i_copyto(C<dest>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>)
1416 Copies image data from the area (C<x1>,C<y1>)-[C<x2>,C<y2>] in the
1417 source image to a rectangle the same size with it's top-left corner at
1418 (C<tx>,C<ty>) in the destination image.
1420 If C<x1> > C<x2> or C<y1> > C<y2> then the corresponding co-ordinates
1427 =item i_copyto_trans(C<im>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>, C<trans>)
1430 (C<x1>,C<y1>) (C<x2>,C<y2>) specifies the region to copy (in the
1431 source coordinates) (C<tx>,C<ty>) specifies the upper left corner for
1432 the target image. pass NULL in C<trans> for non transparent i_colors.
1438 =item i_img_info(im, info)
1441 Return image information
1444 info - pointer to array to return data
1446 info is an array of 4 integers with the following values:
1451 info[3] - channel mask
1457 =item i_rubthru(C<im>, C<src>, C<tx>, C<ty>, C<src_minx>, C<src_miny>, C<src_maxx>, C<src_maxy>)
1460 Takes the sub image C<src>[C<src_minx>, C<src_maxx>)[C<src_miny>, C<src_maxy>)> and
1461 overlays it at (C<tx>,C<ty>) on the image object.
1463 The alpha channel of each pixel in C<src> is used to control how much
1464 the existing color in C<im> is replaced, if it is 255 then the color
1465 is completely replaced, if it is 0 then the original color is left
1470 From: File rubthru.im
1475 =head2 Image creation/destruction
1479 =item i_img_16_new(x, y, ch)
1482 i_img *img = i_img_16_new(width, height, channels);
1484 Create a new 16-bit/sample image.
1486 Returns the image on success, or NULL on failure.
1492 =item i_img_8_new(x, y, ch)
1496 i_img *img = i_img_8_new(width, height, channels);
1498 Creates a new image object I<x> pixels wide, and I<y> pixels high with
1505 =item i_img_double_new(i_img_dim x, i_img_dim y, int ch)
1507 i_img *img = i_img_double_new(width, height, channels);
1509 Creates a new double per sample image.
1513 From: File imgdouble.c
1515 =item i_img_pal_new(C<x>, C<y>, C<channels>, C<maxpal>)
1518 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
1520 Creates a new paletted image of the supplied dimensions.
1522 C<maxpal> is the maximum palette size and should normally be 256.
1524 Returns a new image or NULL on failure.
1530 =item i_sametype(C<im>, C<xsize>, C<ysize>)
1533 i_img *img = i_sametype(src, width, height);
1535 Returns an image of the same type (sample size, channels, paletted/direct).
1537 For paletted images the palette is copied from the source.
1543 =item i_sametype_chans(C<im>, C<xsize>, C<ysize>, C<channels>)
1546 i_img *img = i_sametype_chans(src, width, height, channels);
1548 Returns an image of the same type (sample size).
1550 For paletted images the equivalent direct type is returned.
1556 =item i_img_destroy(C<img>)
1560 Destroy an image object
1569 =head2 Image Implementation
1575 Allocates a new i_img structure.
1577 When implementing a new image type perform the following steps in your
1578 image object creation function:
1584 allocate the image with i_img_alloc().
1588 initialize any function pointers or other data as needed, you can
1589 overwrite the whole block if you need to.
1593 initialize Imager's internal data by calling i_img_init() on the image
1602 =item i_img_init(C<img>)
1604 Imager internal initialization of images.
1606 Currently this does very little, in the future it may be used to
1607 support threads, or color profiles.
1616 =head2 Image Information
1620 =item i_img_color_channels(C<im>)
1623 The number of channels holding color information.
1627 From: File immacros.h
1629 =item i_img_get_height(C<im>)
1631 i_img_dim height = i_img_get_height(im);
1633 Returns the height in pixels of the image.
1639 =item i_img_get_width(C<im>)
1641 i_img_dim width = i_img_get_width(im);
1643 Returns the width in pixels of the image.
1649 =item i_img_getchannels(C<im>)
1651 int channels = i_img_getchannels(img);
1653 Get the number of channels in C<im>.
1659 =item i_img_getmask(C<im>)
1661 int mask = i_img_getmask(img);
1663 Get the image channel mask for C<im>.
1669 =item i_img_has_alpha(C<im>)
1672 Return true if the image has an alpha channel.
1676 From: File immacros.h
1678 =item i_img_is_monochrome(img, &zero_is_white)
1681 Tests an image to check it meets our monochrome tests.
1683 The idea is that a file writer can use this to test where it should
1684 write the image in whatever bi-level format it uses, eg. C<pbm> for
1687 For performance of encoders we require monochrome images:
1697 have a palette of two colors, containing only C<(0,0,0)> and
1698 C<(255,255,255)> in either order.
1702 C<zero_is_white> is set to non-zero if the first palette entry is white.
1708 =item i_img_setmask(C<im>, C<ch_mask>)
1710 // only channel 0 writable
1711 i_img_setmask(img, 0x01);
1713 Set the image channel mask for C<im> to C<ch_mask>.
1715 The image channel mask gives some control over which channels can be
1716 written to in the image.
1725 =head2 Image quantization
1729 =item i_quant_makemap(C<quant>, C<imgs>, C<count>)
1732 Analyzes the C<count> images in C<imgs> according to the rules in
1733 C<quant> to build a color map (optimal or not depending on
1734 C<< quant->make_colors >>).
1740 =item i_quant_translate(C<quant>, C<img>)
1743 Quantize the image given the palette in C<quant>.
1745 On success returns a pointer to a memory block of C<< img->xsize *
1746 img->ysize >> C<i_palidx> entries.
1748 On failure returns NULL.
1750 You should call myfree() on the returned block when you're done with
1753 This function will fail if the supplied palette contains no colors.
1759 =item i_quant_transparent(C<quant>, C<data>, C<img>, C<trans_index>)
1762 Dither the alpha channel on C<img> into the palette indexes in
1763 C<data>. Pixels to be transparent are replaced with C<trans_pixel>.
1765 The method used depends on the tr_* members of C<quant>.
1778 =item i_lhead(file, line)
1780 This is an internal function called by the mm_log() macro.
1786 =item i_loog(level, format, ...)
1788 This is an internal function called by the mm_log() macro.
1794 =item mm_log((level, format, ...))
1796 This is the main entry point to logging. Note that the extra set of
1797 parentheses are required due to limitations in C89 macros.
1799 This will format a string with the current file and line number to the
1800 log file if logging is enabled.
1809 =head2 Paletted images
1813 =item i_addcolors(im, colors, count)
1816 Adds colors to the image's palette.
1818 On success returns the index of the lowest color added.
1820 On failure returns -1.
1822 Always fails for direct color images.
1828 =item i_colorcount(im)
1831 Returns the number of colors in the image's palette.
1833 Returns -1 for direct images.
1839 =item i_findcolor(im, color, &entry)
1842 Searches the images palette for the given color.
1844 On success sets *I<entry> to the index of the color, and returns true.
1846 On failure returns false.
1848 Always fails on direct color images.
1854 =item i_getcolors(im, index, colors, count)
1857 Retrieves I<count> colors starting from I<index> in the image's
1860 On success stores the colors into I<colors> and returns true.
1862 On failure returns false.
1864 Always fails for direct color images.
1866 Fails if there are less than I<index>+I<count> colors in the image's
1873 =item i_maxcolors(im)
1876 Returns the maximum number of colors the palette can hold for the
1879 Returns -1 for direct color images.
1885 =item i_setcolors(im, index, colors, count)
1888 Sets I<count> colors starting from I<index> in the image's palette.
1890 On success returns true.
1892 On failure returns false.
1894 The image must have at least I<index>+I<count> colors in it's palette
1895 for this to succeed.
1897 Always fails on direct color images.
1910 =item i_tags_delbycode(tags, code)
1913 Delete any tags with the given code.
1915 Returns the number of tags deleted.
1921 =item i_tags_delbyname(tags, name)
1924 Delete any tags with the given name.
1926 Returns the number of tags deleted.
1932 =item i_tags_delete(tags, index)
1935 Delete a tag by index.
1937 Returns true on success.
1943 =item i_tags_destroy(tags)
1946 Destroys the given tags structure. Called by i_img_destroy().
1952 =item i_tags_find(tags, name, start, &entry)
1955 Searches for a tag of the given I<name> starting from index I<start>.
1957 On success returns true and sets *I<entry>.
1959 On failure returns false.
1965 =item i_tags_findn(tags, code, start, &entry)
1968 Searches for a tag of the given I<code> starting from index I<start>.
1970 On success returns true and sets *I<entry>.
1972 On failure returns false.
1978 =item i_tags_get_color(tags, name, code, &value)
1981 Retrieve a tag specified by name or code as color.
1983 On success sets the i_color *I<value> to the color and returns true.
1985 On failure returns false.
1991 =item i_tags_get_float(tags, name, code, value)
1994 Retrieves a tag as a floating point value.
1996 If the tag has a string value then that is parsed as a floating point
1997 number, otherwise the integer value of the tag is used.
1999 On success sets *I<value> and returns true.
2001 On failure returns false.
2007 =item i_tags_get_int(tags, name, code, &value)
2010 Retrieve a tag specified by name or code as an integer.
2012 On success sets the int *I<value> to the integer and returns true.
2014 On failure returns false.
2020 =item i_tags_get_string(tags, name, code, value, value_size)
2023 Retrieves a tag by name or code as a string.
2025 On success copies the string to value for a max of value_size and
2028 On failure returns false.
2030 value_size must be at least large enough for a string representation
2033 The copied value is always C<NUL> terminated.
2039 =item i_tags_new(i_img_tags *tags)
2042 Initialize a tags structure. Should not be used if the tags structure
2043 has been previously used.
2045 This should be called tags member of an i_img object on creation (in
2046 i_img_*_new() functions).
2048 To destroy the contents use i_tags_destroy()
2054 =item i_tags_set(tags, name, data, size)
2056 i_tags_set(&img->tags, "i_comment", -1);
2058 Sets the given tag to the string I<data>
2060 If size is -1 then the strlen(I<data>) bytes are stored.
2062 Even on failure, if an existing tag I<name> exists, it will be
2069 =item i_tags_set_color(tags, name, code, &value)
2072 Stores the given color as a tag with the given name and code.
2078 =item i_tags_set_float(tags, name, code, value)
2081 Equivalent to i_tags_set_float2(tags, name, code, value, 30).
2087 =item i_tags_set_float2(tags, name, code, value, places)
2090 Sets the tag with the given name and code to the given floating point
2093 Since tags are strings or ints, we convert the value to a string before
2094 storage at the precision specified by C<places>.
2100 =item i_tags_setn(C<tags>, C<name>, C<idata>)
2102 i_tags_setn(&img->tags, "i_xres", 204);
2103 i_tags_setn(&img->tags, "i_yres", 196);
2105 Sets the given tag to the integer C<idata>
2107 Even on failure, if an existing tag C<name> exists, it will be
2117 =head2 Uncategorized functions
2121 =item i_utf8_advance(char **p, size_t *len)
2123 Retrieve a C<UTF-8> character from the stream.
2125 Modifies *p and *len to indicate the consumed characters.
2127 This doesn't support the extended C<UTF-8> encoding used by later
2128 versions of Perl. Since this is typically used to implement text
2129 output by font drivers, the strings supplied shouldn't have such out
2130 of range characters.
2132 This doesn't check that the C<UTF-8> character is using the shortest
2133 possible representation.
2135 Returns ~0UL on failure.
2148 Tony Cook <tonyc@cpan.org>
2152 Imager, Imager::ExtUtils, Imager::Inline