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.
14 color.rgba.red = 255; color.rgba.green = 0; color.rgba.blue = 255;
21 i_arc(im, 50, 50, 20, 45, 135, &color);
22 i_arc_aa(im, 50, 50, 35, 90, 135, &color);
23 i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
24 i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
25 i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
26 i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
27 i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
28 i_circle_aa(im, 50, 50, 45, &color);
29 i_flood_cfill(im, 50, 50, fill);
30 i_flood_cfill_border(im, 50, 50, fill, border);
31 i_flood_fill(im, 50, 50, &color);
32 i_flood_fill_border(im, 50, 50, &color, &border);
37 i_get_image_file_limits(&width, &height, &bytes)
38 i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
39 i_set_image_file_limits(500, 500, 1000000);
43 fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear,
44 i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
45 i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
46 i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
47 i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
48 i_fill_t *fill = i_new_fill_solid(&color, combine);
49 i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
54 i_img *img = i_img_16_new(width, height, channels);
56 # Image creation/destruction
57 i_img *img = i_img_8_new(width, height, channels);
59 i_img *img = i_img_double_new(width, height, channels);
60 i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
61 i_img *img = i_sametype(src, width, height);
62 i_img *img = i_sametype_chans(src, width, height, channels);
64 # Image Implementation
84 This is Imager's image type.
86 It contains the following members:
92 channels - the number of channels in the image
96 xsize, ysize - the width and height of the image in pixels
100 bytes - the number of bytes used to store the image data. Undefined
101 where virtual is non-zero.
105 ch_mask - a mask of writable channels. eg. if this is 6 then only
106 channels 1 and 2 are writable. There may be bits set for which there
107 are no channels in the image.
111 bits - the number of bits stored per sample. Should be one of
112 i_8_bits, i_16_bits, i_double_bits.
116 type - either i_direct_type for direct color images, or i_palette_type
121 virtual - if zero then this image is-self contained. If non-zero then
122 this image could be an interface to some other implementation.
126 idata - the image data. This should not be directly accessed. A new
127 image implementation can use this to store its image data.
128 i_img_destroy() will myfree() this pointer if it's non-null.
132 tags - a structure storing the image's tags. This should only be
133 accessed via the i_tags_*() functions.
137 ext_data - a pointer for use internal to an image implementation.
138 This should be freed by the image's destroy handler.
142 im_data - data internal to Imager. This is initialized by
147 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
148 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
149 of the required image functions. An image implementation should
150 initialize these between calling i_img_alloc() and i_img_init().
154 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
155 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
156 paletted image function.
160 i_f_destroy - custom image destruction function. This should be used
161 to release memory if necessary.
165 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
169 i_f_psamp_bits - implements i_psamp_bits() for this image.
175 From: File imdatatypes.h
184 =item i_arc(im, x, y, rad, d1, d2, color)
187 Fills an arc centered at (x,y) with radius I<rad> covering the range
188 of angles in degrees from d1 to d2, with the color.
194 =item i_arc_aa(im, x, y, rad, d1, d2, color)
197 Antialias fills an arc centered at (x,y) with radius I<rad> covering
198 the range of angles in degrees from d1 to d2, with the color.
204 =item i_arc_aa_cfill(im, x, y, rad, d1, d2, fill)
207 Antialias fills an arc centered at (x,y) with radius I<rad> covering
208 the range of angles in degrees from d1 to d2, with the fill object.
214 =item i_arc_cfill(im, x, y, rad, d1, d2, fill)
217 Fills an arc centered at (x,y) with radius I<rad> covering the range
218 of angles in degrees from d1 to d2, with the fill object.
224 =item i_box(im, x1, y1, x2, y2, color)
227 Outlines the box from (x1,y1) to (x2,y2) inclusive with I<color>.
233 =item i_box_cfill(im, x1, y1, x2, y2, fill)
236 Fills the box from (x1,y1) to (x2,y2) inclusive with fill.
242 =item i_box_filled(im, x1, y1, x2, y2, color)
245 Fills the box from (x1,y1) to (x2,y2) inclusive with color.
251 =item i_circle_aa(im, x, y, rad, color)
254 Antialias fills a circle centered at (x,y) for radius I<rad> with
261 =item i_flood_cfill(im, seedx, seedy, fill)
264 Flood fills the 4-connected region starting from the point (seedx,
267 Returns false if (seedx, seedy) are outside the image.
273 =item i_flood_cfill_border(im, seedx, seedy, fill, border)
276 Flood fills the 4-connected region starting from the point (seedx,
277 seedy) with I<fill>, the fill stops when it reaches pixels of color
280 Returns false if (seedx, seedy) are outside the image.
286 =item i_flood_fill(im, seedx, seedy, color)
289 Flood fills the 4-connected region starting from the point (seedx,
290 seedy) with I<color>.
292 Returns false if (seedx, seedy) are outside the image.
298 =item i_flood_fill_border(im, seedx, seedy, color, border)
301 Flood fills the 4-connected region starting from the point (seedx,
302 seedy) with I<color>, fill stops when the fill reaches a pixels with
305 Returns false if (seedx, seedy) are outside the image.
311 =item i_glin(im, l, r, y, colors)
314 Retrieves (r-l) pixels starting from (l,y) into I<colors>.
316 Returns the number of pixels retrieved.
322 =item i_glinf(im, l, r, y, colors)
325 Retrieves (r-l) pixels starting from (l,y) into I<colors> as floating
328 Returns the number of pixels retrieved.
334 =item i_gpal(im, x, r, y, indexes)
337 Reads palette indexes for the horizontal line (x, y) to (r-1, y) into
340 Returns the number of indexes read.
342 Always returns 0 for direct color images.
348 =item i_gpix(im, x, y, color)
351 Retrieves the I<color> of the pixel (x,y).
353 Returns 0 if the pixel was retrieved, or -1 if not.
359 =item i_gpixf(im, x, y, fcolor)
362 Retrieves the color of the pixel (x,y) as a floating point color into
365 Returns 0 if the pixel was retrieved, or -1 if not.
371 =item i_gsamp(im, l, r, y, samp, chans, chan_count)
374 Reads sample values from im for the horizontal line (l, y) to (r-1,y)
375 for the channels specified by chans, an array of int with chan_count
378 If chans is NULL then the first chan_count channels are retrieved for
381 Returns the number of samples read (which should be (r-l) *
388 =item i_gsampf(im, l, r, y, samp, chans, chan_count)
391 Reads floating point sample values from im for the horizontal line (l,
392 y) to (r-1,y) for the channels specified by chans, an array of int
393 with chan_count elements.
395 If chans is NULL then the first chan_count channels are retrieved for
398 Returns the number of samples read (which should be (r-l) *
405 =item i_line(im, x1, y1, x2, y2, val, endp)
408 Draw a line to image using bresenhams linedrawing algorithm
410 im - image to draw to
411 x1 - starting x coordinate
412 y1 - starting x coordinate
413 x2 - starting x coordinate
414 y2 - starting x coordinate
415 val - color to write to image
416 endp - endpoint flag (boolean)
422 =item i_line_aa(im, x1, x2, y1, y2, color, endp)
425 Antialias draws a line from (x1,y1) to (x2, y2) in color.
427 The point (x2, y2) is drawn only if endp is set.
433 =item i_plin(im, l, r, y, colors)
436 Sets (r-l) pixels starting from (l,y) using (r-l) values from
439 Returns the number of pixels set.
445 =item i_plinf(im, l, r, fcolors)
448 Sets (r-l) pixels starting from (l,y) using (r-l) floating point
449 colors from I<colors>.
451 Returns the number of pixels set.
457 =item i_ppal(im, x, r, y, indexes)
460 Writes palette indexes for the horizontal line (x, y) to (r-1, y) from
463 Returns the number of indexes written.
465 Always returns 0 for direct color images.
471 =item i_ppix(im, x, y, color)
474 Sets the pixel at (x,y) to I<color>.
476 Returns 0 if the pixel was drawn, or -1 if not.
478 Does no alpha blending, just copies the channels from the supplied
485 =item i_ppixf(im, x, y, fcolor)
488 Sets the pixel at (x,y) to the floating point color I<fcolor>.
490 Returns 0 if the pixel was drawn, or -1 if not.
492 Does no alpha blending, just copies the channels from the supplied
502 =head2 Error handling
506 =item i_clear_error()
509 Clears the error stack.
511 Called by any imager function before doing any other processing.
517 =item i_push_error(int code, char const *msg)
520 Called by an imager function to push an error message onto the stack.
522 No message is pushed if the stack is full (since this means someone
523 forgot to call i_clear_error(), or that a function that doesn't do
524 error handling is calling function that does.).
530 =item i_push_errorf(int code, char const *fmt, ...)
533 A version of i_push_error() that does printf() like formating.
539 =item i_push_errorvf(int code, char const *fmt, va_list ap)
542 Intended for use by higher level functions, takes a varargs pointer
543 and a format to produce the finally pushed error message.
556 =item i_get_image_file_limits(&width, &height, &bytes)
559 Retrieves the file limits set by i_set_image_file_limits().
565 =item i_int_check_image_file_limits(width, height, channels, sample_size)
568 Checks the size of a file in memory against the configured image file
571 This also range checks the values to those permitted by Imager and
572 checks for overflows in calculating the size.
574 Returns non-zero if the file is within limits.
576 This function is intended to be called by image file read functions.
582 =item i_set_image_file_limits(width, height, bytes)
585 Set limits on the sizes of images read by Imager.
587 Setting a limit to 0 means that limit is ignored.
589 Negative limits result in failure.
591 Returns non-zero on success.
604 =item i_fill_destroy(fill)
607 Call to destroy any fill object.
613 =item i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, count, segs)
617 Creates a new general fill which fills with a fountain fill.
621 From: File filters.im
623 =item i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
626 Creates a new hatched fill with the fg color used for the 1 bits in
627 the hatch and bg for the 0 bits. If combine is non-zero alpha values
630 If cust_hatch is non-NULL it should be a pointer to 8 bytes of the
631 hash definition, with the high-bits to the left.
633 If cust_hatch is NULL then one of the standard hatches is used.
635 (dx, dy) are an offset into the hatch which can be used to unalign adjoining areas, or to align the origin of a hatch with the the side of a filled area.
641 =item i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
644 Creates a new hatched fill with the fg color used for the 1 bits in
645 the hatch and bg for the 0 bits. If combine is non-zero alpha values
648 If cust_hatch is non-NULL it should be a pointer to 8 bytes of the
649 hash definition, with the high-bits to the left.
651 If cust_hatch is NULL then one of the standard hatches is used.
653 (dx, dy) are an offset into the hatch which can be used to unalign adjoining areas, or to align the origin of a hatch with the the side of a filled area.
659 =item i_new_fill_image(im, matrix, xoff, yoff, combine)
662 Create an image based fill.
664 matrix is an array of 9 doubles representing a transformation matrix.
666 xoff and yoff are the offset into the image to start filling from.
672 =item i_new_fill_solid(color, combine)
675 Create a solid fill based on an 8-bit color.
677 If combine is non-zero then alpha values will be combined.
683 =item i_new_fill_solidf(color, combine)
686 Create a solid fill based on a float color.
688 If combine is non-zero then alpha values will be combined.
704 Creates a new image that is a copy of src.
706 Tags are not copied, only the image data.
714 =item i_copyto(dest, src, x1, y1, x2, y2, tx, ty)
717 Copies image data from the area (x1,y1)-[x2,y2] in the source image to
718 a rectangle the same size with it's top-left corner at (tx,ty) in the
721 If x1 > x2 or y1 > y2 then the corresponding co-ordinates are swapped.
727 =item i_copyto_trans(im, src, x1, y1, x2, y2, tx, ty, trans)
730 (x1,y1) (x2,y2) specifies the region to copy (in the source coordinates)
731 (tx,ty) specifies the upper left corner for the target image.
732 pass NULL in trans for non transparent i_colors.
738 =item i_img_info(im, info)
741 Return image information
744 info - pointer to array to return data
746 info is an array of 4 integers with the following values:
751 info[3] - channel mask
757 =item i_rubthru(im, src, tx, ty, src_minx, src_miny, src_maxx, src_maxy )
760 Takes the sub image I<src[src_minx, src_maxx)[src_miny, src_maxy)> and
761 overlays it at (I<tx>,I<ty>) on the image object.
763 The alpha channel of each pixel in I<src> is used to control how much
764 the existing colour in I<im> is replaced, if it is 255 then the colour
765 is completely replaced, if it is 0 then the original colour is left
770 From: File rubthru.im
775 =head2 Image creation
779 =item i_img_16_new(x, y, ch)
782 Create a new 16-bit/sample image.
784 Returns the image on success, or NULL on failure.
793 =head2 Image creation/destruction
797 =item i_img_8_new(x, y, ch)
801 Creates a new image object I<x> pixels wide, and I<y> pixels high with
808 =item i_img_destroy(img)
811 Destroy an image object
817 =item i_img_double_new(int x, int y, int ch)
819 Creates a new double per sample image.
823 From: File imgdouble.c
825 =item i_img_pal_new(x, y, channels, maxpal)
828 Creates a new paletted image of the supplied dimensions.
830 I<maxpal> is the maximum palette size and should normally be 256.
832 Returns a new image or NULL on failure.
838 =item i_sametype(i_img *im, int xsize, int ysize)
841 Returns an image of the same type (sample size, channels, paletted/direct).
843 For paletted images the palette is copied from the source.
849 =item i_sametype_chans(i_img *im, int xsize, int ysize, int channels)
852 Returns an image of the same type (sample size).
854 For paletted images the equivalent direct type is returned.
863 =head2 Image Implementation
869 Allocates a new i_img structure.
871 When implementing a new image type perform the following steps in your
872 image object creation function:
878 allocate the image with i_img_alloc().
882 initialize any function pointers or other data as needed, you can
883 overwrite the whole block if you need to.
887 initialize Imager's internal data by calling i_img_init() on the image
896 =item i_img_init(img)
898 Imager interal initialization of images.
900 Currently this does very little, in the future it may be used to
901 support threads, or color profiles.
910 =head2 Image Information
914 =item i_img_color_channels(im)
917 The number of channels holding color information.
921 From: File immacros.h
923 =item i_img_has_alpha(im)
926 Return true if the image has an alpha channel.
930 From: File immacros.h
935 =head2 Image quantization
939 =item i_quant_makemap(quant, imgs, count)
942 Analyzes the I<count> images in I<imgs> according to the rules in
943 I<quant> to build a color map (optimal or not depending on
950 =item i_quant_translate(quant, img)
953 Quantize the image given the palette in quant.
955 On success returns a pointer to a memory block of img->xsize *
956 img->ysize i_palidx entries.
958 On failure returns NULL.
960 You should call myfree() on the returned block when you're done with
963 This function will fail if the supplied palette contains no colors.
969 =item i_quant_transparent(quant, data, img, trans_index)
972 Dither the alpha channel on I<img> into the palette indexes in
973 I<data>. Pixels to be transparent are replaced with I<trans_pixel>.
975 The method used depends on the tr_* members of quant.
988 =item i_loog(level, format, ...)
990 This is an internal function called by the mm_log() macro.
996 =item mm_log((level, format, ...))
998 This is the main entry point to logging. Note that the extra set of
999 parentheses are required due to limitations in C89 macros.
1001 This will format a string with the current file and line number to the
1002 log file if logging is enabled.
1011 =head2 Paletted images
1015 =item i_addcolors(im, colors, count)
1018 Adds colors to the image's palette.
1020 On success returns the index of the lowest color added.
1022 On failure returns -1.
1024 Always fails for direct color images.
1030 =item i_colorcount(im)
1033 Returns the number of colors in the image's palette.
1035 Returns -1 for direct images.
1041 =item i_findcolor(im, color, &entry)
1044 Searches the images palette for the given color.
1046 On success sets *I<entry> to the index of the color, and returns true.
1048 On failure returns false.
1050 Always fails on direct color images.
1056 =item i_getcolors(im, index, colors, count)
1059 Retrieves I<count> colors starting from I<index> in the image's
1062 On success stores the colors into I<colors> and returns true.
1064 On failure returns false.
1066 Always fails for direct color images.
1068 Fails if there are less than I<index>+I<count> colors in the image's
1075 =item i_maxcolors(im)
1078 Returns the maximum number of colors the palette can hold for the
1081 Returns -1 for direct color images.
1087 =item i_setcolors(im, index, colors, count)
1090 Sets I<count> colors starting from I<index> in the image's palette.
1092 On sucess returns true.
1094 On failure returns false.
1096 The image must have at least I<index>+I<count> colors in it's palette
1097 for this to succeed.
1099 Always fails on direct color images.
1112 =item i_tags_delbycode(tags, code)
1115 Delete any tags with the given code.
1117 Returns the number of tags deleted.
1123 =item i_tags_delbyname(tags, name)
1126 Delete any tags with the given name.
1128 Returns the number of tags deleted.
1134 =item i_tags_delete(tags, index)
1137 Delete a tag by index.
1139 Returns true on success.
1145 =item i_tags_destroy(tags)
1148 Destroys the given tags structure. Called by i_img_destroy().
1154 =item i_tags_find(tags, name, start, &entry)
1157 Searchs for a tag of the given I<name> starting from index I<start>.
1159 On success returns true and sets *I<entry>.
1161 On failure returns false.
1167 =item i_tags_findn(tags, code, start, &entry)
1170 Searchs for a tag of the given I<code> starting from index I<start>.
1172 On success returns true and sets *I<entry>.
1174 On failure returns false.
1180 =item i_tags_get_color(tags, name, code, &value)
1183 Retrieve a tag specified by name or code as color.
1185 On success sets the i_color *I<value> to the color and returns true.
1187 On failure returns false.
1193 =item i_tags_get_float(tags, name, code, value)
1196 Retrieves a tag as a floating point value.
1198 If the tag has a string value then that is parsed as a floating point
1199 number, otherwise the integer value of the tag is used.
1201 On success sets *I<value> and returns true.
1203 On failure returns false.
1209 =item i_tags_get_int(tags, name, code, &value)
1212 Retrieve a tag specified by name or code as an integer.
1214 On success sets the int *I<value> to the integer and returns true.
1216 On failure returns false.
1222 =item i_tags_get_string(tags, name, code, value, value_size)
1225 Retrieves a tag by name or code as a string.
1227 On success copies the string to value for a max of value_size and
1230 On failure returns false.
1232 value_size must be at least large enough for a string representation
1235 The copied value is always NUL terminated.
1241 =item i_tags_new(i_img_tags *tags)
1244 Initialize a tags structure. Should not be used if the tags structure
1245 has been previously used.
1247 This should be called tags member of an i_img object on creation (in
1248 i_img_*_new() functions).
1250 To destroy the contents use i_tags_destroy()
1256 =item i_tags_set(tags, name, data, size)
1259 Sets the given tag to the string I<data>
1265 =item i_tags_set_color(tags, name, code, &value)
1268 Stores the given color as a tag with the given name and code.
1274 =item i_tags_set_float(tags, name, code, value)
1277 Equivalent to i_tags_set_float2(tags, name, code, value, 30).
1283 =item i_tags_set_float2(tags, name, code, value, places)
1286 Sets the tag with the given name and code to the given floating point
1289 Since tags are strings or ints, we convert the value to a string before
1290 storage at the precision specified by C<places>.
1296 =item i_tags_setn(tags, name, idata)
1299 Sets the given tag to the integer I<idata>
1308 =head2 Uncategorized functions
1312 =item i_img_get_height(im)
1315 Returns the height in pixels of the image.
1321 =item i_img_get_width(im)
1324 Returns the width in pixels of the image.
1330 =item i_img_getchannels(im)
1333 Get the number of channels in I<im>.
1339 =item i_img_getmask(im)
1342 Get the image channel mask for I<im>.
1348 =item i_img_setmask(im, ch_mask)
1351 Set the image channel mask for I<im> to I<ch_mask>.
1364 The following API functions are undocumented so far, hopefully this
1392 Tony Cook <tony@imager.perl.org>
1396 Imager, Imager::ExtUtils, Imager::Inline