]> git.imager.perl.org - imager.git/blobdiff - lib/Imager/APIRef.pod
auto-convert the "other" parameter for opacity fills
[imager.git] / lib / Imager / APIRef.pod
index e92e4c49db8afd8a93003675003721f827e80a94..320f0648593a09eacb5cb0a1cd14ce2f47b48bc5 100644 (file)
@@ -6,54 +6,262 @@ you can find the documentation.
 
 =head1 NAME
 
-Imager::APIRef - Imager's C API.
+Imager::APIRef - Imager's C API - reference.
 
 =head1 SYNOPSIS
 
   i_color color;
-  color.rgba.red = 255; color.rgba.green = 0; color.rgba.blue = 255;
-  i_fill_t *fill = i_new_fill_...(...);
+  color.rgba.r = 255; color.rgba.g = 0; color.rgba.b = 255;
 
 
+  # Data Types
+  i_img *img;
+  i_color black;
+  black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
+  i_fill_t *fill;
+  i_img_dim x;
+
   # Drawing
   i_arc(im, 50, 50, 20, 45, 135, &color);
+  i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
   i_arc_aa(im, 50, 50, 35, 90, 135, &color);
   i_arc_aa_cfill(im, 50, 50, 35, 90, 135, fill);
-  i_arc_cfill(im, 50, 50, 35, 90, 135, fill);
+  i_circle_aa(im, 50, 50, 45, &color);
   i_box(im, 0, 0, im->xsize-1, im->ysize-1, &color).
-  i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
   i_box_filled(im, 0, 0, im->xsize-1, im->ysize-1, &color);
-  i_circle_aa(im, 50, 50, 45, &color);
-  i_flood_cfill(im, 50, 50, fill);
-  i_flood_cfill_border(im, 50, 50, fill, border);
+  i_box_cfill(im, 0, 0, im->xsize-1, im->ysize-1, fill);
   i_flood_fill(im, 50, 50, &color);
+  i_flood_cfill(im, 50, 50, fill);
   i_flood_fill_border(im, 50, 50, &color, &border);
+  i_flood_cfill_border(im, 50, 50, fill, border);
 
   # Error handling
+  i_clear_error();
+  i_push_error(0, "Yep, it's broken");
+  i_push_error(errno, "Error writing");
+  i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
 
   # Files
+  i_set_image_file_limits(500, 500, 1000000);
   i_get_image_file_limits(&width, &height, &bytes)
   i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
-  i_set_image_file_limits(500, 500, 1000000);
 
   # Fills
+  i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
+  i_fill_t *fill = i_new_fill_solid(&color, combine);
+  i_fill_t *fill = i_new_fill_hatch(&fg_color, &bg_color, combine, hatch, custom_hatch, dx, dy);
+  i_fill_t *fill = i_new_fill_hatchf(&fg_fcolor, &bg_fcolor, combine, hatch, custom_hatch, dx, dy);
+  i_fill_t *fill = i_new_fill_image(src_img, matrix, x_offset, y_offset, combine);
   fill = i_new_fill_fount(0, 0, 100, 100, i_ft_linear, i_ft_linear, 
                           i_fr_triangle, 0, i_fts_grid, 9, 1, segs);
+  i_fill_destroy(fill);
 
   # Image
 
-  # Image creation
+  # Image creation/destruction
+  i_img *img = i_img_8_new(width, height, channels);
+  i_img *img = i_sametype(src, width, height);
+  i_img *img = i_sametype_chans(src, width, height, channels);
+  i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
+  i_img *img = i_img_double_new(width, height, channels);
+  i_img *img = i_img_16_new(width, height, channels);
+  i_img_destroy(img)
+
+  # Image Implementation
+
+  # Image Information
+  // only channel 0 writeable 
+  i_img_setmask(img, 0x01);
+  int mask = i_img_getmask(img);
+  int channels = i_img_getchannels(img);
+  i_img_dim width = i_img_get_width(im);
+  i_img_dim height = i_img_get_height(im);
 
   # Image quantization
 
+  # Logging
+
   # Paletted images
 
   # Tags
-
-   i_fill_destroy(fill);
+  i_tags_set(&img->tags, "i_comment", -1);
+  i_tags_setn(&img->tags, "i_xres", 204);
+  i_tags_setn(&img->tags, "i_yres", 196);
 
 =head1 DESCRIPTION
 
+=head2 Data Types
+
+=over
+
+=item i_img
+
+This is Imager's image type.
+
+It contains the following members:
+
+=over
+
+=item *
+
+channels - the number of channels in the image
+
+=item *
+
+xsize, ysize - the width and height of the image in pixels
+
+=item *
+
+bytes - the number of bytes used to store the image data.  Undefined
+where virtual is non-zero.
+
+=item *
+
+ch_mask - a mask of writable channels.  eg. if this is 6 then only
+channels 1 and 2 are writable.  There may be bits set for which there
+are no channels in the image.
+
+=item *
+
+bits - the number of bits stored per sample.  Should be one of
+i_8_bits, i_16_bits, i_double_bits.
+
+=item *
+
+type - either i_direct_type for direct color images, or i_palette_type
+for paletted images.
+
+=item *
+
+virtual - if zero then this image is-self contained.  If non-zero then
+this image could be an interface to some other implementation.
+
+=item *
+
+idata - the image data.  This should not be directly accessed.  A new
+image implementation can use this to store its image data.
+i_img_destroy() will myfree() this pointer if it's non-null.
+
+=item *
+
+tags - a structure storing the image's tags.  This should only be
+accessed via the i_tags_*() functions.
+
+=item *
+
+ext_data - a pointer for use internal to an image implementation.
+This should be freed by the image's destroy handler.
+
+=item *
+
+im_data - data internal to Imager.  This is initialized by
+i_img_init().
+
+=item *
+
+i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
+i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
+of the required image functions.  An image implementation should
+initialize these between calling i_img_alloc() and i_img_init().
+
+=item *
+
+i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
+i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
+paletted image function.
+
+=item *
+
+i_f_destroy - custom image destruction function.  This should be used
+to release memory if necessary.
+
+=item *
+
+i_f_gsamp_bits - implements i_gsamp_bits() for this image.
+
+=item *
+
+i_f_psamp_bits - implements i_psamp_bits() for this image.
+
+=back
+
+
+=for comment
+From: File imdatatypes.h
+
+=item i_color
+
+Type for 8-bit/sample color.
+
+Samples as per;
+
+  i_color c;
+
+i_color is a union of:
+
+=over
+
+=item *
+
+gray - contains a single element gray_color, eg. c.gray.gray_color
+
+=item *
+
+rgb - contains three elements r, g, b, eg. c.rgb.r
+
+=item *
+
+rgba - contains four elements r, g, b, a, eg. c.rgba.a
+
+=item *
+
+cmyk - contains four elements c, m, y, k, eg. C<c.cmyk.y>.  Note that
+Imager never uses CMYK colors except when reading/writing files.
+
+=item *
+
+channels - an array of four channels, eg C<c.channels[2]>.
+
+=back
+
+
+=for comment
+From: File imdatatypes.h
+
+=item i_fcolor
+
+This is the double/sample color type.
+
+Its layout exactly corresponds to i_color.
+
+
+=for comment
+From: File imdatatypes.h
+
+=item i_fill_t
+
+This is the "abstract" base type for Imager's fill types.
+
+Unless you're implementing a new fill type you'll typically treat this
+as an opaque type.
+
+
+=for comment
+From: File imdatatypes.h
+
+=item i_img_dim
+
+A signed integer type that represents an image dimension or ordinate.
+
+May be larger than int on some platforms.
+
+
+=for comment
+From: File imdatatypes.h
+
+
+=back
+
 =head2 Drawing
 
 =over
@@ -382,7 +590,6 @@ From: File imext.c
 
 =item i_clear_error()
 
-
 Clears the error stack.
 
 Called by any imager function before doing any other processing.
@@ -393,8 +600,7 @@ From: File error.c
 
 =item i_push_error(int code, char const *msg)
 
-
-Called by an imager function to push an error message onto the stack.
+Called by an Imager function to push an error message onto the stack.
 
 No message is pushed if the stack is full (since this means someone
 forgot to call i_clear_error(), or that a function that doesn't do
@@ -406,9 +612,10 @@ From: File error.c
 
 =item i_push_errorf(int code, char const *fmt, ...)
 
-
 A version of i_push_error() that does printf() like formating.
 
+Does not support perl specific format codes.
+
 
 =for comment
 From: File error.c
@@ -419,6 +626,8 @@ From: File error.c
 Intended for use by higher level functions, takes a varargs pointer
 and a format to produce the finally pushed error message.
 
+Does not support perl specific format codes.
+
 
 =for comment
 From: File error.c
@@ -478,15 +687,6 @@ From: File limits.c
 
 =over
 
-=item i_fill_destroy(fill)
-
-
-Call to destroy any fill object.
-
-
-=for comment
-From: File fills.c
-
 =item i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, count, segs)
 
 
@@ -495,7 +695,7 @@ Creates a new general fill which fills with a fountain fill.
 
 
 =for comment
-From: File filters.c
+From: File filters.im
 
 =item i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
 
@@ -565,6 +765,14 @@ Create a solid fill based on a float color.
 If combine is non-zero then alpha values will be combined.
 
 
+=for comment
+From: File fills.c
+
+=item i_fill_destroy(fill)
+
+Call to destroy any fill object.
+
+
 =for comment
 From: File fills.c
 
@@ -599,7 +807,7 @@ If x1 > x2 or y1 > y2 then the corresponding co-ordinates are swapped.
 
 
 =for comment
-From: File image.c
+From: File paste.im
 
 =item i_copyto_trans(im, src, x1, y1, x2, y2, tx, ty, trans)
 
@@ -609,17 +817,6 @@ From: File image.c
 pass NULL in trans for non transparent i_colors.
 
 
-=for comment
-From: File image.c
-
-=item i_img_destroy(im)
-
-
-Destroy image and free data via exorcise.
-
-   im - Image pointer
-
-
 =for comment
 From: File image.c
 
@@ -655,12 +852,12 @@ unmodified.
 
 
 =for comment
-From: File image.c
+From: File rubthru.im
 
 
 =back
 
-=head2 Image creation
+=head2 Image creation/destruction
 
 =over
 
@@ -678,6 +875,7 @@ From: File img16.c
 =item i_img_8_new(x, y, ch)
 
 
+
 Creates a new image object I<x> pixels wide, and I<y> pixels high with
 I<ch> channels.
 
@@ -687,7 +885,6 @@ From: File image.c
 
 =item i_img_double_new(int x, int y, int ch)
 
-
 Creates a new double per sample image.
 
 
@@ -699,6 +896,8 @@ From: File imgdouble.c
 
 Creates a new paletted image of the supplied dimensions.
 
+I<maxpal> is the maximum palette size and should normally be 256.
+
 Returns a new image or NULL on failure.
 
 
@@ -724,6 +923,129 @@ Returns an image of the same type (sample size).
 For paletted images the equivalent direct type is returned.
 
 
+=for comment
+From: File image.c
+
+=item i_img_destroy(img)
+
+Destroy an image object
+
+
+=for comment
+From: File image.c
+
+
+=back
+
+=head2 Image Implementation
+
+=over
+
+=item i_img_alloc()
+
+Allocates a new i_img structure.
+
+When implementing a new image type perform the following steps in your
+image object creation function:
+
+=over
+
+=item 1.
+
+allocate the image with i_img_alloc().
+
+=item 2.
+
+initialize any function pointers or other data as needed, you can
+overwrite the whole block if you need to.
+
+=item 3.
+
+initialize Imager's internal data by calling i_img_init() on the image
+object.
+
+=back
+
+
+=for comment
+From: File image.c
+
+=item i_img_init(img)
+
+Imager interal initialization of images.
+
+Currently this does very little, in the future it may be used to
+support threads, or color profiles.
+
+
+=for comment
+From: File image.c
+
+
+=back
+
+=head2 Image Information
+
+=over
+
+=item i_img_color_channels(im)
+
+
+The number of channels holding color information.
+
+
+=for comment
+From: File immacros.h
+
+=item i_img_get_height(im)
+
+Returns the height in pixels of the image.
+
+
+=for comment
+From: File image.c
+
+=item i_img_get_width(im)
+
+Returns the width in pixels of the image.
+
+
+=for comment
+From: File image.c
+
+=item i_img_getchannels(im)
+
+Get the number of channels in I<im>.
+
+
+=for comment
+From: File image.c
+
+=item i_img_getmask(im)
+
+Get the image channel mask for I<im>.
+
+
+=for comment
+From: File image.c
+
+=item i_img_has_alpha(im)
+
+
+Return true if the image has an alpha channel.
+
+
+=for comment
+From: File immacros.h
+
+=item i_img_setmask(im, ch_mask)
+
+Set the image channel mask for I<im> to I<ch_mask>.
+
+The image channel mask gives some control over which channels can be
+written to in the image.
+
+
 =for comment
 From: File image.c
 
@@ -777,6 +1099,41 @@ The method used depends on the tr_* members of quant.
 From: File quant.c
 
 
+=back
+
+=head2 Logging
+
+=over
+
+=item i_lhead(file, line)
+
+This is an internal function called by the mm_log() macro.
+
+
+=for comment
+From: File log.c
+
+=item i_loog(level, format, ...)
+
+This is an internal function called by the mm_log() macro.
+
+
+=for comment
+From: File log.c
+
+=item mm_log((level, format, ...))
+
+This is the main entry point to logging. Note that the extra set of
+parentheses are required due to limitations in C89 macros.
+
+This will format a string with the current file and line number to the
+log file if logging is enabled.
+
+
+=for comment
+From: File log.h
+
+
 =back
 
 =head2 Paletted images
@@ -1026,9 +1383,13 @@ From: File tags.c
 
 =item i_tags_set(tags, name, data, size)
 
-
 Sets the given tag to the string I<data>
 
+If size is -1 then the strlen(I<data>) bytes are stored.
+
+Even on failure, if an existing tag I<name> exists, it will be
+removed.
+
 
 =for comment
 From: File tags.c
@@ -1066,9 +1427,11 @@ From: File tags.c
 
 =item i_tags_setn(tags, name, idata)
 
-
 Sets the given tag to the integer I<idata>
 
+Even on failure, if an existing tag I<name> exists, it will be
+removed.
+
 
 =for comment
 From: File tags.c