]> git.imager.perl.org - imager.git/blobdiff - imdatatypes.h
add i_errors()/im_errors() to the API
[imager.git] / imdatatypes.h
index 8e9cdd36e5d517611550b1aaafdaf085094c206a..32c92d14e78acbe810f1d01810074443a15c778b 100644 (file)
@@ -1,11 +1,13 @@
 #ifndef _DATATYPES_H_
 #define _DATATYPES_H_
 
+#include <stddef.h>
 #include "imconfig.h"
-#include "imio.h"
 
 #define MAXCHANNELS 4
 
+typedef struct im_context_tag *im_context_t;
+
 /* used for palette indices in some internal code (which might be 
    exposed at some point
 */
@@ -22,6 +24,64 @@ typedef struct { i_sample_t c,m,y,k; } cmyk_color;
 
 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
 
+/*
+=item i_img_dim
+=category Data Types
+=synopsis i_img_dim x, y;
+=order 90
+
+A signed integer type that represents an image dimension or ordinate.
+
+May be larger than int on some platforms.
+
+=cut
+*/
+
+typedef ptrdiff_t i_img_dim;
+
+/*
+=item i_color
+=category Data Types
+=synopsis i_color black;
+=synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
+
+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<c.gray.gray_color>
+
+=item *
+
+C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
+
+=item *
+
+C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
+
+=item *
+
+C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<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
+
+=cut
+*/
+
 typedef union {
   gray_color gray;
   rgb_color rgb;
@@ -40,6 +100,17 @@ typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
 
+/*
+=item i_fcolor
+=category Data Types
+
+This is the double/sample color type.
+
+Its layout exactly corresponds to i_color.
+
+=cut
+*/
+
 typedef union {
   i_fgray_color_t gray;
   i_frgb_color_t rgb;
@@ -76,22 +147,22 @@ typedef struct {
 } i_img_tags;
 
 typedef struct i_img_ i_img;
-typedef int (*i_f_ppix_t)(i_img *im, int x, int y, const i_color *pix);
-typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, const i_fcolor *pix);
-typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, const i_color *vals);
-typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, const i_fcolor *vals);
-typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix);
-typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix);
-typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals);
-typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
-
-typedef int (*i_f_gsamp_t)(i_img *im, int x, int r, int y, i_sample_t *samp,
+typedef int (*i_f_ppix_t)(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
+typedef int (*i_f_ppixf_t)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
+typedef i_img_dim (*i_f_plin_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_color *vals);
+typedef i_img_dim (*i_f_plinf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_fcolor *vals);
+typedef int (*i_f_gpix_t)(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
+typedef int (*i_f_gpixf_t)(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
+typedef i_img_dim (*i_f_glin_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_color *vals);
+typedef i_img_dim (*i_f_glinf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_fcolor *vals);
+
+typedef i_img_dim (*i_f_gsamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_sample_t *samp,
                            const int *chans, int chan_count);
-typedef int (*i_f_gsampf_t)(i_img *im, int x, int r, int y, i_fsample_t *samp,
+typedef i_img_dim (*i_f_gsampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_fsample_t *samp,
                             const int *chan, int chan_count);
 
-typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
-typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, const i_palidx *vals);
+typedef i_img_dim (*i_f_gpal_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
+typedef i_img_dim (*i_f_ppal_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
 typedef int (*i_f_colorcount_t)(i_img *im);
@@ -102,17 +173,22 @@ typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
 
 typedef void (*i_f_destroy_t)(i_img *im);
 
-typedef int (*i_f_gsamp_bits_t)(i_img *im, int x, int r, int y, unsigned *samp,
+typedef i_img_dim (*i_f_gsamp_bits_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, unsigned *samp,
                            const int *chans, int chan_count, int bits);
-typedef int (*i_f_psamp_bits_t)(i_img *im, int x, int r, int y, unsigned const *samp,
+typedef i_img_dim (*i_f_psamp_bits_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, unsigned const *samp,
                                 const int *chans, int chan_count, int bits);
-
-typedef int i_img_dim;
+typedef i_img_dim
+(*i_f_psamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, 
+               const i_sample_t *samp, const int *chan, int chan_count);
+typedef i_img_dim
+(*i_f_psampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
+               const i_fsample_t *samp, const int *chan, int chan_count);
 
 /*
 =item i_img
 =category Data Types
 =synopsis i_img *img;
+=order 10
 
 This is Imager's image type.
 
@@ -122,57 +198,57 @@ It contains the following members:
 
 =item *
 
-channels - the number of channels in the image
+C<channels> - the number of channels in the image
 
 =item *
 
-xsize, ysize - the width and height of the image in pixels
+C<xsize>, C<ysize> - the width and height of the image in pixels
 
 =item *
 
-bytes - the number of bytes used to store the image data.  Undefined
+C<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
+C<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
+C<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
+C<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.
+C<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
+C<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
+C<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.
+C<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
+C<im_data> - data internal to Imager.  This is initialized by
 i_img_init().
 
 =item *
@@ -201,6 +277,22 @@ i_f_gsamp_bits - implements i_gsamp_bits() for this image.
 
 i_f_psamp_bits - implements i_psamp_bits() for this image.
 
+=item *
+
+i_f_psamp - implements psamp() for this image.
+
+=item *
+
+i_f_psampf - implements psamp() for this image.
+
+=item *
+
+C<im_data> - image specific data internal to Imager.
+
+=item *
+
+C<context> - the Imager API context this image belongs to.
+
 =back
 
 =cut
@@ -248,7 +340,14 @@ struct i_img_ {
   i_f_gsamp_bits_t i_f_gsamp_bits;
   i_f_psamp_bits_t i_f_psamp_bits;
 
+  /* as of 0.88 */
+  i_f_psamp_t i_f_psamp;
+  i_f_psampf_t i_f_psampf;
+
   void *im_data;
+
+  /* 0.91 */
+  im_context_t context;
 };
 
 /* ext_data for paletted images
@@ -270,27 +369,17 @@ typedef struct {
 
 */
 
-
-
-
-
 /* bitmap mask */
 
 struct i_bitmap {
-  int xsize,ysize;
+  i_img_dim xsize,ysize;
   char *data;
 };
 
-struct i_bitmap* btm_new(int xsize,int ysize);
+struct i_bitmap* btm_new(i_img_dim xsize,i_img_dim ysize);
 void btm_destroy(struct i_bitmap *btm);
-int btm_test(struct i_bitmap *btm,int x,int y);
-void btm_set(struct i_bitmap *btm,int x,int y);
-
-
-
-
-
-
+int btm_test(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
+void btm_set(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
 
 
 /* Stack/Linked list */
@@ -304,21 +393,16 @@ struct llink {
 struct llist {
   struct llink *h,*t;
   int multip;          /* # of copies in a single chain  */
-  int ssize;           /* size of each small element     */
+  size_t ssize;                /* size of each small element     */
   int count;           /* number of elements on the list */
 };
 
 
-/* Links */
-
-struct llink *llink_new( struct llink* p,int size );
-int  llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
-
 /* Lists */
 
-struct llist *llist_new( int multip, int ssize );
+struct llist *llist_new( int multip, size_t ssize );
 void llist_destroy( struct llist *l );
-void llist_push( struct llist *l, void *data );
+void llist_push( struct llist *l, const void *data );
 void llist_dump( struct llist *l );
 int llist_pop( struct llist *l,void *data );
 
@@ -356,16 +440,26 @@ enum bounding_box_index_t {
 struct i_fill_tag;
 
 typedef void (*i_fill_with_color_f)
-     (struct i_fill_tag *fill, int x, int y, int width, int channels, 
+(struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels, 
       i_color *data);
 typedef void (*i_fill_with_fcolor_f)
-     (struct i_fill_tag *fill, int x, int y, int width, int channels,
+     (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
       i_fcolor *data);
 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
+
+/* combine functions modify their target and are permitted to modify
+   the source to prevent having to perform extra copying/memory
+   allocations, etc
+   The out array has I<channels> channels.
+
+   The in array has I<channels> channels + an alpha channel if one
+   isn't included in I<channels>.
+*/
+
 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels, 
-                                 int count);
+                                 i_img_dim count);
 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
-                                  int count);
+                                  i_img_dim count);
 
 /* fountain fill types */
 typedef enum {
@@ -411,16 +505,28 @@ typedef enum {
   i_fts_circle
 } i_ft_supersample;
 
+/*
+=item i_fill_t
+=category Data Types
+=synopsis i_fill_t *fill;
+
+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.
+
+=cut
+*/
 
 typedef struct i_fill_tag
 {
   /* called for 8-bit/sample image (and maybe lower) */
   /* this may be NULL, if so call fill_with_fcolor */
-  i_fill_with_color_f fill_with_color;
+  i_fill_with_color_f f_fill_with_color;
 
   /* called for other sample sizes */
   /* this must be non-NULL */
-  i_fill_with_fcolor_f fill_with_fcolor;
+  i_fill_with_fcolor_f f_fill_with_fcolor;
 
   /* called if non-NULL to release any extra resources */
   i_fill_destroy_f destroy;
@@ -479,12 +585,6 @@ typedef struct TT_Fonthandle_ TT_Fonthandle;
 
 #endif
 
-#ifdef HAVE_FT2
-
-typedef struct FT2_Fonthandle FT2_Fonthandle;
-
-#endif
-
 /* transparency handling for quantized output */
 typedef enum i_transp_tag {
   tr_none, /* ignore any alpha channel */
@@ -500,6 +600,9 @@ typedef enum i_make_colors_tag {
   mc_addi, /* Addi's algorithm */
   mc_median_cut, /* median cut - similar to giflib, hopefully */
   mc_mono, /* fixed mono color map */
+  mc_gray, /* 256 gray map */
+  mc_gray4, /* four step gray map */
+  mc_gray16, /* sixteen step gray map */
   mc_mask = 0xFF /* (mask for generator) */
 } i_make_colors;
 
@@ -539,12 +642,10 @@ typedef enum i_ord_dith_tag
   od_custom /* custom 8x8 map */
 } i_ord_dith;
 
-typedef struct i_gif_pos_tag {
-  int x, y;
-} i_gif_pos;
-
 /* passed into i_writegif_gen() to control quantization */
 typedef struct i_quantize_tag {
+  int version;
+
   /* how to handle transparency */
   i_transp transp;
   /* the threshold at which to make pixels opaque */
@@ -580,58 +681,88 @@ typedef struct i_quantize_tag {
 
   /* the amount of perturbation to use for translate is mc_perturb */
   int perturb;
+  /* version 2 members after here */
 } i_quantize;
 
-typedef struct i_gif_opts {
-  /* each image has a local color map */
-  int each_palette;
+/* distance measures used by some filters */
+enum {
+  i_dmeasure_euclidean = 0,
+  i_dmeasure_euclidean_squared = 1,
+  i_dmeasure_manhatten = 2,
+  i_dmeasure_limit = 2,
+};
 
-  /* images are interlaced */
-  int interlace;
+#include "iolayert.h"
 
-  /* time for which image is displayed 
-   (in 1/100 seconds)
-   default: 0
-  */
-  int delay_count;
-  int *delays;
+/* error message information returned by im_errors() */
 
-  /* user input flags 
-     default: 0
-   */
-  int user_input_count;
-  char *user_input_flags;
+typedef struct {
+  char *msg;
+  int code;
+} i_errmsg;
 
-  /* disposal
-     default: 0 */
-  int disposal_count;
-  char *disposal;
+typedef struct i_render_tag i_render;
 
-  /* this is added to the color table when we make an image transparent */
-  i_color tran_color;
+#ifdef IMAGER_FORMAT_ATTR
+#define I_FORMAT_ATTR(format_index, va_index) \
+  __attribute ((format (printf, format_index, va_index)))
+#else
+#define I_FORMAT_ATTR(format_index, va_index)
+#endif
 
-  /* image positions */
-  int position_count;
-  i_gif_pos *positions;
+#ifdef _MSC_VER
+#  ifndef vsnprintf
+#  define vsnprintf _vsnprintf
+#  endif
+#  ifndef snprintf
+#  define snprintf _snprintf
+#  endif
+#endif
 
-  /* Netscape loop extension - number of loops */
-  int loop_count;
+/*
+=item i_DF
+=category Data Types
+=synopsis printf("left %" i_DF "\n", i_DFc(x));
+=order 95
 
-  /* should be eliminate unused colors? */
-  int eliminate_unused;
-} i_gif_opts;
+This is a constant string that can be used with functions like
+printf() to format i_img_dim values after they're been cast with i_DFc().
 
-/* distance measures used by some filters */
-enum {
-  i_dmeasure_euclidean = 0,
-  i_dmeasure_euclidean_squared = 1,
-  i_dmeasure_manhatten = 2,
-  i_dmeasure_limit = 2,
-};
+Does not include the leading C<%>.
 
-#include "iolayert.h"
+=cut
+
+=item i_DFc
+=category Data Types
+=order 95
+
+Cast an C<i_img_dim> value to a type for use with the i_DF format
+string.
+
+=cut
+
+=item i_DFp
+=category Data Types
+=synopsis printf("point (" i_DFp ")\n", i_DFcp(x, y));
+=order 95
+
+Format a pair of C<i_img_dim> values.  This format string I<does>
+include the leading C<%>.
+
+=cut
+
+=item i_DFcp
+=category Data Types
+=order 95
+
+Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
+
+=cut
+ */
 
-#include "rendert.h"
+#define i_DFc(x) ((i_dim_format_t)(x))
+#define i_DFcp(x, y) i_DFc(x), i_DFc(y)
+#define i_DFp "%" i_DF ", %" i_DF
 
 #endif