13 Imager's per-thread context.
18 typedef struct im_context_tag *im_context_t;
24 Represents a slot in the context object.
29 typedef ptrdiff_t im_slot_t;
30 typedef void (*im_slot_destroy_t)(void *);
32 /* used for palette indices in some internal code (which might be
35 typedef unsigned char i_palidx;
37 /* We handle 2 types of sample, this is hopefully the most common, and the
38 smaller of the ones we support */
39 typedef unsigned char i_sample_t;
41 typedef struct { i_sample_t gray_color; } gray_color;
42 typedef struct { i_sample_t r,g,b; } rgb_color;
43 typedef struct { i_sample_t r,g,b,a; } rgba_color;
44 typedef struct { i_sample_t c,m,y,k; } cmyk_color;
46 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
51 =synopsis i_img_dim x, y;
54 A signed integer type that represents an image dimension or ordinate.
56 May be larger than int on some platforms.
61 typedef ptrdiff_t i_img_dim;
66 =synopsis i_img_dim_u limit;
69 An unsigned variant of L</i_img_dim>.
74 typedef size_t i_img_dim_u;
76 #define i_img_dim_MAX ((i_img_dim)(~(i_img_dim_u)0 >> 1))
81 =synopsis i_color black;
82 =synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
84 Type for 8-bit/sample color.
90 i_color is a union of:
96 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
100 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
104 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
108 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
109 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
110 reading/writing files.
114 channels - an array of four channels, eg C<c.channels[2]>.
126 i_sample_t channel[MAXCHANNELS];
130 /* this is the larger sample type, it should be able to accurately represent
131 any sample size we use */
132 typedef double i_fsample_t;
134 typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
135 typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
136 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
137 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
143 This is the double/sample color type.
145 Its layout exactly corresponds to i_color.
151 i_fgray_color_t gray;
153 i_frgba_color_t rgba;
154 i_fcmyk_color_t cmyk;
155 i_fsample_t channel[MAXCHANNELS];
159 i_direct_type, /* direct colour, keeps RGB values per pixel */
160 i_palette_type /* keeps a palette index per pixel */
164 /* bits per sample, not per pixel */
165 /* a paletted image might have one bit per sample */
168 i_double_bits = sizeof(double) * 8
172 char *name; /* name of a given tag, might be NULL */
173 int code; /* number of a given tag, -1 if it has no meaning */
174 char *data; /* value of a given tag if it's not an int, may be NULL */
175 int size; /* size of the data */
176 int idata; /* value of a given tag if data is NULL */
180 int count; /* how many tags have been set */
181 int alloc; /* how many tags have been allocated for */
185 typedef struct i_img_ i_img;
186 typedef int (*i_f_ppix_t)(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
187 typedef int (*i_f_ppixf_t)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
188 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);
189 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);
190 typedef int (*i_f_gpix_t)(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
191 typedef int (*i_f_gpixf_t)(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
192 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);
193 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);
195 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,
196 const int *chans, int chan_count);
197 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,
198 const int *chan, int chan_count);
200 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);
201 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);
202 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
203 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
204 typedef int (*i_f_colorcount_t)(i_img *im);
205 typedef int (*i_f_maxcolors_t)(i_img *im);
206 typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
207 typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
210 typedef void (*i_f_destroy_t)(i_img *im);
212 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,
213 const int *chans, int chan_count, int bits);
214 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,
215 const int *chans, int chan_count, int bits);
217 (*i_f_psamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
218 const i_sample_t *samp, const int *chan, int chan_count);
220 (*i_f_psampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
221 const i_fsample_t *samp, const int *chan, int chan_count);
226 =synopsis i_img *img;
229 This is Imager's image type.
231 It contains the following members:
237 C<channels> - the number of channels in the image
241 C<xsize>, C<ysize> - the width and height of the image in pixels
245 C<bytes> - the number of bytes used to store the image data. Undefined
246 where virtual is non-zero.
250 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
251 channels 1 and 2 are writable. There may be bits set for which there
252 are no channels in the image.
256 C<bits> - the number of bits stored per sample. Should be one of
257 i_8_bits, i_16_bits, i_double_bits.
261 C<type> - either i_direct_type for direct color images, or i_palette_type
266 C<virtual> - if zero then this image is-self contained. If non-zero
267 then this image could be an interface to some other implementation.
271 C<idata> - the image data. This should not be directly accessed. A new
272 image implementation can use this to store its image data.
273 i_img_destroy() will myfree() this pointer if it's non-null.
277 C<tags> - a structure storing the image's tags. This should only be
278 accessed via the i_tags_*() functions.
282 C<ext_data> - a pointer for use internal to an image implementation.
283 This should be freed by the image's destroy handler.
287 C<im_data> - data internal to Imager. This is initialized by
292 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
293 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
294 of the required image functions. An image implementation should
295 initialize these between calling i_img_alloc() and i_img_init().
299 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
300 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
301 paletted image function.
305 i_f_destroy - custom image destruction function. This should be used
306 to release memory if necessary.
310 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
314 i_f_psamp_bits - implements i_psamp_bits() for this image.
318 i_f_psamp - implements psamp() for this image.
322 i_f_psampf - implements psamp() for this image.
326 C<im_data> - image specific data internal to Imager.
330 C<context> - the Imager API context this image belongs to.
339 i_img_dim xsize,ysize;
341 unsigned int ch_mask;
344 int virtual; /* image might not keep any data, must use functions */
345 unsigned char *idata; /* renamed to force inspection of existing code */
346 /* can be NULL if virtual is non-zero */
351 /* interface functions */
353 i_f_ppixf_t i_f_ppixf;
355 i_f_plinf_t i_f_plinf;
357 i_f_gpixf_t i_f_gpixf;
359 i_f_glinf_t i_f_glinf;
360 i_f_gsamp_t i_f_gsamp;
361 i_f_gsampf_t i_f_gsampf;
363 /* only valid for type == i_palette_type */
366 i_f_addcolors_t i_f_addcolors;
367 i_f_getcolors_t i_f_getcolors;
368 i_f_colorcount_t i_f_colorcount;
369 i_f_maxcolors_t i_f_maxcolors;
370 i_f_findcolor_t i_f_findcolor;
371 i_f_setcolors_t i_f_setcolors;
373 i_f_destroy_t i_f_destroy;
376 i_f_gsamp_bits_t i_f_gsamp_bits;
377 i_f_psamp_bits_t i_f_psamp_bits;
380 i_f_psamp_t i_f_psamp;
381 i_f_psampf_t i_f_psampf;
386 im_context_t context;
389 /* ext_data for paletted images
392 int count; /* amount of space used in palette (in entries) */
393 int alloc; /* amount of space allocated for palette (in entries) */
399 The types in here so far are:
401 doubly linked bucket list - pretty efficient
402 octtree - no idea about goodness
411 i_img_dim xsize,ysize;
415 struct i_bitmap* btm_new(i_img_dim xsize,i_img_dim ysize);
416 void btm_destroy(struct i_bitmap *btm);
417 int btm_test(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
418 void btm_set(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
421 /* Stack/Linked list */
426 int fill; /* Number used in this link */
431 int multip; /* # of copies in a single chain */
432 size_t ssize; /* size of each small element */
433 int count; /* number of elements on the list */
439 struct llist *llist_new( int multip, size_t ssize );
440 void llist_destroy( struct llist *l );
441 void llist_push( struct llist *l, const void *data );
442 void llist_dump( struct llist *l );
443 int llist_pop( struct llist *l,void *data );
455 struct octt *octt_new(void);
456 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
457 void octt_dump(struct octt *ct);
458 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
459 void octt_delete(struct octt *ct);
460 void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
462 /* font bounding box results */
463 enum bounding_box_index_t {
479 Represents a polygon. Has the following members:
485 C<x>, C<y> - arrays of x and y locations of vertices.
489 C<count> - the number of entries in the C<x> and C<y> arrays.
496 typedef struct i_polygon_tag {
503 =item i_poly_fill_mode_t
506 Control how polygons are filled. Has the following values:
512 C<i_pfm_evenodd> - simple even-odd fills.
516 C<i_pfm_nonzero> - non-zero winding rule fills.
523 typedef enum i_poly_fill_mode_tag {
526 } i_poly_fill_mode_t;
531 typedef void (*i_fill_with_color_f)
532 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
534 typedef void (*i_fill_with_fcolor_f)
535 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
537 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
539 /* combine functions modify their target and are permitted to modify
540 the source to prevent having to perform extra copying/memory
542 The out array has I<channels> channels.
544 The in array has I<channels> channels + an alpha channel if one
545 isn't included in I<channels>.
548 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
550 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
553 /* fountain fill types */
561 } i_fountain_seg_type;
569 double start, middle, end;
571 i_fountain_seg_type type;
572 i_fountain_color color;
600 =synopsis i_fill_t *fill;
602 This is the "abstract" base type for Imager's fill types.
604 Unless you're implementing a new fill type you'll typically treat this
610 typedef struct i_fill_tag
612 /* called for 8-bit/sample image (and maybe lower) */
613 /* this may be NULL, if so call fill_with_fcolor */
614 i_fill_with_color_f f_fill_with_color;
616 /* called for other sample sizes */
617 /* this must be non-NULL */
618 i_fill_with_fcolor_f f_fill_with_fcolor;
620 /* called if non-NULL to release any extra resources */
621 i_fill_destroy_f destroy;
623 /* if non-zero the caller will fill data with the original data
625 i_fill_combine_f combine;
626 i_fill_combinef_f combinef;
649 =synopsis i_mutex_t mutex;
651 Opaque type for Imager's mutex API.
655 typedef struct i_mutex_tag *i_mutex_t;
658 describes an axis of a MM font.
659 Modelled on FT2's FT_MM_Axis.
660 It would be nice to have a default entry too, but FT2
663 typedef struct i_font_mm_axis_tag {
669 #define IM_FONT_MM_MAX_AXES 4
672 multiple master information for a font, if any
673 modelled on FT2's FT_Multi_Master.
675 typedef struct i_font_mm_tag {
677 int num_designs; /* provided but not necessarily useful */
678 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
683 struct TT_Fonthandle_;
685 typedef struct TT_Fonthandle_ TT_Fonthandle;
693 An enumerated type for controlling how transparency is handled during
696 This has the following possible values:
702 C<tr_none> - ignore the alpha channel
706 C<tr_threshold> - simple transparency thresholding.
710 C<tr_errdiff> - use error diffusion to control which pixels are
715 C<tr_ordered> - use ordered dithering to control which pixels are
723 /* transparency handling for quantized output */
724 typedef enum i_transp_tag {
725 tr_none, /* ignore any alpha channel */
726 tr_threshold, /* threshold the transparency - uses tr_threshold */
727 tr_errdiff, /* error diffusion */
728 tr_ordered /* an ordered dither */
735 An enumerated type used to control the method used for produce the
742 C<mc_none> - the user supplied map is used.
746 C<mc_web_map> - use the classic web map. Any existing fixed colors
751 C<mc_median_cut> - use median cut
755 C<mono> - use a fixed black and white map.
759 C<gray> - 256 step gray map.
763 C<gray4> - 4 step gray map.
767 C<gray16> - 16 step gray map.
774 typedef enum i_make_colors_tag {
775 mc_none, /* user supplied colour map only */
776 mc_web_map, /* Use the 216 colour web colour map */
777 mc_addi, /* Addi's algorithm */
778 mc_median_cut, /* median cut - similar to giflib, hopefully */
779 mc_mono, /* fixed mono color map */
780 mc_gray, /* 256 gray map */
781 mc_gray4, /* four step gray map */
782 mc_gray16, /* sixteen step gray map */
783 mc_mask = 0xFF /* (mask for generator) */
790 An enumerated type that controls how colors are translated:
796 C<pt_giflib> - obsolete, forces C<make_colors> to use median cut and
797 acts like C<pt_closest>.
801 C<pt_closest> - always use the closest color.
805 C<pt_perturb> - add random values to each sample and find the closest
810 C<pt_errdiff> - error diffusion dither.
817 /* controls how we translate the colours */
818 typedef enum i_translate_tag {
819 pt_giflib, /* get gif lib to do it (ignores make_colours) */
820 pt_closest, /* just use the closest match within the hashbox */
821 pt_perturb, /* randomly perturb the data - uses perturb_size*/
822 pt_errdiff /* error diffusion dither - uses errdiff */
829 Controls the type of error diffusion to use:
835 C<ed_floyd> - floyd-steinberg
839 C<ed_jarvis> - Jarvis, Judice and Ninke
843 C<ed_stucki> - Stucki
847 C<ed_custom> - not usable for transparency dithering, allows a custom
848 error diffusion map to be used.
852 C<ed_bidir> - or with the error diffusion type to use alternate
853 directions on each line of the dither.
860 /* Which error diffusion map to use */
861 typedef enum i_errdiff_tag {
862 ed_floyd, /* floyd-steinberg */
863 ed_jarvis, /* Jarvis, Judice and Ninke */
864 ed_stucki, /* Stucki */
865 ed_custom, /* the map found in ed_map|width|height|orig */
866 ed_mask = 0xFF, /* mask to get the map */
867 ed_bidir = 0x100 /* change direction for each row */
874 Which ordered dither map to use, currently only available for
875 transparency. Values are:
881 C<od_random> - a pre-generated random map.
885 C<od_dot8> - large dot dither.
889 C<od_dot4> - smaller dot dither
893 C<od_hline> - horizontal line dither.
897 C<od_vline> - vertical line dither.
901 C<od_slashline> - C</> line dither.
905 C<od_backline> - C<\> line dither.
909 C<od_tiny> - small checkbox dither
913 C<od_custom> - custom dither map.
919 I don't know of a way to do ordered dither of an image against some
922 typedef enum i_ord_dith_tag
924 od_random, /* sort of random */
925 od_dot8, /* large dot */
929 od_slashline, /* / line dither */
930 od_backline, /* \ line dither */
931 od_tiny, /* small checkerbox */
932 od_custom /* custom 8x8 map */
939 A structure type used to supply image quantization, ie. when
940 converting a direct color image to a paletted image.
942 This has the following members:
948 C<transp> - how to handle transparency, see L</i_transp>.
952 C<threshold> - when C<transp> is C<tr_threshold>, this is the alpha
953 level at which pixels become transparent.
957 C<tr_errdiff> - when C<transp> is C<tr_errdiff> this controls the type
958 of error diffusion to be done. This may not be C<ed_custom> for this
963 C<tr_orddith> - when C<transp> is C<tr_ordered> this controls the
964 patten used for dithering transparency.
968 C<tr_custom> - when C<tr_orddith> is C<tr_custom> this is the ordered
973 C<make_colors> - the method used to generate the color palette, see
978 C<mc_colors> - an array of C<mc_size> L</i_color> entries used to
979 define the fixed colors (controlled by C<mc_count> and to return the
980 generated color list.
984 C<mc_size> - the size of the buffer allocated to C<mc_colors> in
985 C<sizeof(i_color)> units.
989 C<mc_count> - the number of initialized colors in C<mc_colors>.
993 C<translate> - how RGB colors are translated to palette indexes, see
998 C<errdiff> - when C<translate> is C<pt_errdiff> this controls the type
999 of error diffusion to be done.
1003 C<ed_map>, C<ed_width>, C<ed_height>, C<ed_orig> - when C<errdiff> is
1004 C<ed_custom> this controls the error diffusion map. C<ed_map> is an
1005 array of C<ed_width * ed_height> integers. C<ed_orig> is the position
1006 of the current pixel in the error diffusion map, always on the top
1011 C<perturb> - the amount to perturb pixels when C<translate> is
1018 typedef struct i_quantize_tag {
1021 /* how to handle transparency */
1023 /* the threshold at which to make pixels opaque */
1025 i_errdiff tr_errdiff;
1026 i_ord_dith tr_orddith;
1027 unsigned char tr_custom[64];
1029 /* how to make the colour map */
1030 i_make_colors make_colors;
1032 /* any existing colours
1033 mc_existing is an existing colour table
1034 mc_count is the number of existing colours
1035 mc_size is the total size of the array that mc_existing points
1036 at - this must be at least 256
1042 /* how we translate the colours */
1043 i_translate translate;
1045 /* the error diffusion map to use if translate is mc_errdiff */
1047 /* the following define the error diffusion values to use if
1048 errdiff is ed_custom. ed_orig is the column on the top row that
1049 represents the current
1052 int ed_width, ed_height, ed_orig;
1054 /* the amount of perturbation to use for translate is mc_perturb */
1056 /* version 2 members after here */
1059 /* distance measures used by some filters */
1061 i_dmeasure_euclidean = 0,
1062 i_dmeasure_euclidean_squared = 1,
1063 i_dmeasure_manhatten = 2,
1064 i_dmeasure_limit = 2,
1067 #include "iolayert.h"
1069 /* error message information returned by im_errors() */
1076 typedef struct i_render_tag i_render;
1079 =item i_color_model_t
1080 =category Data Types
1083 Returned by L</i_img_color_model(im)> to indicate the color model of
1086 An enumerated type with the following possible values:
1092 C<icm_unknown> - the image has no usable color data. In future
1093 versions of Imager this will be returned in a few limited cases,
1094 eg. when the source image is CMYK and the user has requested no color
1095 translation is done.
1099 C<icm_gray> - gray scale with no alpha channel.
1103 C<icm_gray_alpha> - gray scale with an alpha channel.
1111 C<icm_rgb_alpha> - RGB with an alpha channel.
1126 #ifdef IMAGER_FORMAT_ATTR
1127 #define I_FORMAT_ATTR(format_index, va_index) \
1128 __attribute ((format (printf, format_index, va_index)))
1130 #define I_FORMAT_ATTR(format_index, va_index)
1135 # define vsnprintf _vsnprintf
1138 # define snprintf _snprintf
1144 =category Data Types
1145 =synopsis printf("left %" i_DF "\n", i_DFc(x));
1148 This is a constant string that can be used with functions like
1149 printf() to format i_img_dim values after they're been cast with i_DFc().
1151 Does not include the leading C<%>.
1156 =category Data Types
1159 Cast an C<i_img_dim> value to a type for use with the i_DF format
1165 =category Data Types
1166 =synopsis printf("point (" i_DFp ")\n", i_DFcp(x, y));
1169 Format a pair of C<i_img_dim> values. This format string I<does>
1170 include the leading C<%>.
1175 =category Data Types
1178 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
1183 #define i_DFc(x) ((i_dim_format_t)(x))
1184 #define i_DFcp(x, y) i_DFc(x), i_DFc(y)
1185 #define i_DFp "%" i_DF ", %" i_DF