9 typedef struct im_context_tag *im_context_t;
11 typedef ptrdiff_t im_slot_t;
12 typedef void (*im_slot_destroy_t)(void *);
14 /* used for palette indices in some internal code (which might be
17 typedef unsigned char i_palidx;
19 /* We handle 2 types of sample, this is hopefully the most common, and the
20 smaller of the ones we support */
21 typedef unsigned char i_sample_t;
23 typedef struct { i_sample_t gray_color; } gray_color;
24 typedef struct { i_sample_t r,g,b; } rgb_color;
25 typedef struct { i_sample_t r,g,b,a; } rgba_color;
26 typedef struct { i_sample_t c,m,y,k; } cmyk_color;
28 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
33 =synopsis i_img_dim x, y;
36 A signed integer type that represents an image dimension or ordinate.
38 May be larger than int on some platforms.
43 typedef ptrdiff_t i_img_dim;
48 =synopsis i_color black;
49 =synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
51 Type for 8-bit/sample color.
57 i_color is a union of:
63 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
67 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
71 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
75 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
76 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
77 reading/writing files.
81 channels - an array of four channels, eg C<c.channels[2]>.
93 i_sample_t channel[MAXCHANNELS];
97 /* this is the larger sample type, it should be able to accurately represent
98 any sample size we use */
99 typedef double i_fsample_t;
101 typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
102 typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
103 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
104 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
110 This is the double/sample color type.
112 Its layout exactly corresponds to i_color.
118 i_fgray_color_t gray;
120 i_frgba_color_t rgba;
121 i_fcmyk_color_t cmyk;
122 i_fsample_t channel[MAXCHANNELS];
126 i_direct_type, /* direct colour, keeps RGB values per pixel */
127 i_palette_type /* keeps a palette index per pixel */
131 /* bits per sample, not per pixel */
132 /* a paletted image might have one bit per sample */
135 i_double_bits = sizeof(double) * 8
139 char *name; /* name of a given tag, might be NULL */
140 int code; /* number of a given tag, -1 if it has no meaning */
141 char *data; /* value of a given tag if it's not an int, may be NULL */
142 int size; /* size of the data */
143 int idata; /* value of a given tag if data is NULL */
147 int count; /* how many tags have been set */
148 int alloc; /* how many tags have been allocated for */
152 typedef struct i_img_ i_img;
153 typedef int (*i_f_ppix_t)(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
154 typedef int (*i_f_ppixf_t)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
155 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);
156 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);
157 typedef int (*i_f_gpix_t)(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
158 typedef int (*i_f_gpixf_t)(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
159 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);
160 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);
162 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,
163 const int *chans, int chan_count);
164 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,
165 const int *chan, int chan_count);
167 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);
168 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);
169 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
170 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
171 typedef int (*i_f_colorcount_t)(i_img *im);
172 typedef int (*i_f_maxcolors_t)(i_img *im);
173 typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
174 typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
177 typedef void (*i_f_destroy_t)(i_img *im);
179 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,
180 const int *chans, int chan_count, int bits);
181 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,
182 const int *chans, int chan_count, int bits);
184 (*i_f_psamp_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
185 const i_sample_t *samp, const int *chan, int chan_count);
187 (*i_f_psampf_t)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y,
188 const i_fsample_t *samp, const int *chan, int chan_count);
193 =synopsis i_img *img;
196 This is Imager's image type.
198 It contains the following members:
204 C<channels> - the number of channels in the image
208 C<xsize>, C<ysize> - the width and height of the image in pixels
212 C<bytes> - the number of bytes used to store the image data. Undefined
213 where virtual is non-zero.
217 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
218 channels 1 and 2 are writable. There may be bits set for which there
219 are no channels in the image.
223 C<bits> - the number of bits stored per sample. Should be one of
224 i_8_bits, i_16_bits, i_double_bits.
228 C<type> - either i_direct_type for direct color images, or i_palette_type
233 C<virtual> - if zero then this image is-self contained. If non-zero
234 then this image could be an interface to some other implementation.
238 C<idata> - the image data. This should not be directly accessed. A new
239 image implementation can use this to store its image data.
240 i_img_destroy() will myfree() this pointer if it's non-null.
244 C<tags> - a structure storing the image's tags. This should only be
245 accessed via the i_tags_*() functions.
249 C<ext_data> - a pointer for use internal to an image implementation.
250 This should be freed by the image's destroy handler.
254 C<im_data> - data internal to Imager. This is initialized by
259 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
260 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
261 of the required image functions. An image implementation should
262 initialize these between calling i_img_alloc() and i_img_init().
266 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
267 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
268 paletted image function.
272 i_f_destroy - custom image destruction function. This should be used
273 to release memory if necessary.
277 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
281 i_f_psamp_bits - implements i_psamp_bits() for this image.
285 i_f_psamp - implements psamp() for this image.
289 i_f_psampf - implements psamp() for this image.
293 C<im_data> - image specific data internal to Imager.
297 C<context> - the Imager API context this image belongs to.
306 i_img_dim xsize,ysize;
308 unsigned int ch_mask;
311 int virtual; /* image might not keep any data, must use functions */
312 unsigned char *idata; /* renamed to force inspection of existing code */
313 /* can be NULL if virtual is non-zero */
318 /* interface functions */
320 i_f_ppixf_t i_f_ppixf;
322 i_f_plinf_t i_f_plinf;
324 i_f_gpixf_t i_f_gpixf;
326 i_f_glinf_t i_f_glinf;
327 i_f_gsamp_t i_f_gsamp;
328 i_f_gsampf_t i_f_gsampf;
330 /* only valid for type == i_palette_type */
333 i_f_addcolors_t i_f_addcolors;
334 i_f_getcolors_t i_f_getcolors;
335 i_f_colorcount_t i_f_colorcount;
336 i_f_maxcolors_t i_f_maxcolors;
337 i_f_findcolor_t i_f_findcolor;
338 i_f_setcolors_t i_f_setcolors;
340 i_f_destroy_t i_f_destroy;
343 i_f_gsamp_bits_t i_f_gsamp_bits;
344 i_f_psamp_bits_t i_f_psamp_bits;
347 i_f_psamp_t i_f_psamp;
348 i_f_psampf_t i_f_psampf;
353 im_context_t context;
356 /* ext_data for paletted images
359 int count; /* amount of space used in palette (in entries) */
360 int alloc; /* amount of space allocated for palette (in entries) */
366 The types in here so far are:
368 doubly linked bucket list - pretty efficient
369 octtree - no idea about goodness
378 i_img_dim xsize,ysize;
382 struct i_bitmap* btm_new(i_img_dim xsize,i_img_dim ysize);
383 void btm_destroy(struct i_bitmap *btm);
384 int btm_test(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
385 void btm_set(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
388 /* Stack/Linked list */
393 int fill; /* Number used in this link */
398 int multip; /* # of copies in a single chain */
399 size_t ssize; /* size of each small element */
400 int count; /* number of elements on the list */
406 struct llist *llist_new( int multip, size_t ssize );
407 void llist_destroy( struct llist *l );
408 void llist_push( struct llist *l, const void *data );
409 void llist_dump( struct llist *l );
410 int llist_pop( struct llist *l,void *data );
422 struct octt *octt_new(void);
423 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
424 void octt_dump(struct octt *ct);
425 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
426 void octt_delete(struct octt *ct);
427 void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
429 /* font bounding box results */
430 enum bounding_box_index_t {
445 typedef void (*i_fill_with_color_f)
446 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
448 typedef void (*i_fill_with_fcolor_f)
449 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
451 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
453 /* combine functions modify their target and are permitted to modify
454 the source to prevent having to perform extra copying/memory
456 The out array has I<channels> channels.
458 The in array has I<channels> channels + an alpha channel if one
459 isn't included in I<channels>.
462 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
464 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
467 /* fountain fill types */
475 } i_fountain_seg_type;
483 double start, middle, end;
485 i_fountain_seg_type type;
486 i_fountain_color color;
514 =synopsis i_fill_t *fill;
516 This is the "abstract" base type for Imager's fill types.
518 Unless you're implementing a new fill type you'll typically treat this
524 typedef struct i_fill_tag
526 /* called for 8-bit/sample image (and maybe lower) */
527 /* this may be NULL, if so call fill_with_fcolor */
528 i_fill_with_color_f f_fill_with_color;
530 /* called for other sample sizes */
531 /* this must be non-NULL */
532 i_fill_with_fcolor_f f_fill_with_fcolor;
534 /* called if non-NULL to release any extra resources */
535 i_fill_destroy_f destroy;
537 /* if non-zero the caller will fill data with the original data
539 i_fill_combine_f combine;
540 i_fill_combinef_f combinef;
563 =synopsis i_mutex_t mutex;
565 Opaque type for Imager's mutex API.
569 typedef struct i_mutex_tag *i_mutex_t;
572 describes an axis of a MM font.
573 Modelled on FT2's FT_MM_Axis.
574 It would be nice to have a default entry too, but FT2
577 typedef struct i_font_mm_axis_tag {
583 #define IM_FONT_MM_MAX_AXES 4
586 multiple master information for a font, if any
587 modelled on FT2's FT_Multi_Master.
589 typedef struct i_font_mm_tag {
591 int num_designs; /* provided but not necessarily useful */
592 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
597 struct TT_Fonthandle_;
599 typedef struct TT_Fonthandle_ TT_Fonthandle;
603 /* transparency handling for quantized output */
604 typedef enum i_transp_tag {
605 tr_none, /* ignore any alpha channel */
606 tr_threshold, /* threshold the transparency - uses tr_threshold */
607 tr_errdiff, /* error diffusion */
608 tr_ordered /* an ordered dither */
611 /* controls how we build the colour map */
612 typedef enum i_make_colors_tag {
613 mc_none, /* user supplied colour map only */
614 mc_web_map, /* Use the 216 colour web colour map */
615 mc_addi, /* Addi's algorithm */
616 mc_median_cut, /* median cut - similar to giflib, hopefully */
617 mc_mono, /* fixed mono color map */
618 mc_gray, /* 256 gray map */
619 mc_gray4, /* four step gray map */
620 mc_gray16, /* sixteen step gray map */
621 mc_mask = 0xFF /* (mask for generator) */
624 /* controls how we translate the colours */
625 typedef enum i_translate_tag {
626 pt_giflib, /* get gif lib to do it (ignores make_colours) */
627 pt_closest, /* just use the closest match within the hashbox */
628 pt_perturb, /* randomly perturb the data - uses perturb_size*/
629 pt_errdiff /* error diffusion dither - uses errdiff */
632 /* Which error diffusion map to use */
633 typedef enum i_errdiff_tag {
634 ed_floyd, /* floyd-steinberg */
635 ed_jarvis, /* Jarvis, Judice and Ninke */
636 ed_stucki, /* Stucki */
637 ed_custom, /* the map found in ed_map|width|height|orig */
638 ed_mask = 0xFF, /* mask to get the map */
639 ed_bidir = 0x100 /* change direction for each row */
642 /* which ordered dither map to use
643 currently only available for transparency
644 I don't know of a way to do ordered dither of an image against some
647 typedef enum i_ord_dith_tag
649 od_random, /* sort of random */
650 od_dot8, /* large dot */
654 od_slashline, /* / line dither */
655 od_backline, /* \ line dither */
656 od_tiny, /* small checkerbox */
657 od_custom /* custom 8x8 map */
660 /* passed into i_writegif_gen() to control quantization */
661 typedef struct i_quantize_tag {
664 /* how to handle transparency */
666 /* the threshold at which to make pixels opaque */
668 i_errdiff tr_errdiff;
669 i_ord_dith tr_orddith;
670 unsigned char tr_custom[64];
672 /* how to make the colour map */
673 i_make_colors make_colors;
675 /* any existing colours
676 mc_existing is an existing colour table
677 mc_count is the number of existing colours
678 mc_size is the total size of the array that mc_existing points
679 at - this must be at least 256
685 /* how we translate the colours */
686 i_translate translate;
688 /* the error diffusion map to use if translate is mc_errdiff */
690 /* the following define the error diffusion values to use if
691 errdiff is ed_custom. ed_orig is the column on the top row that
692 represents the current
695 int ed_width, ed_height, ed_orig;
697 /* the amount of perturbation to use for translate is mc_perturb */
699 /* version 2 members after here */
702 /* distance measures used by some filters */
704 i_dmeasure_euclidean = 0,
705 i_dmeasure_euclidean_squared = 1,
706 i_dmeasure_manhatten = 2,
707 i_dmeasure_limit = 2,
710 #include "iolayert.h"
712 /* error message information returned by im_errors() */
719 typedef struct i_render_tag i_render;
721 #ifdef IMAGER_FORMAT_ATTR
722 #define I_FORMAT_ATTR(format_index, va_index) \
723 __attribute ((format (printf, format_index, va_index)))
725 #define I_FORMAT_ATTR(format_index, va_index)
730 # define vsnprintf _vsnprintf
733 # define snprintf _snprintf
740 =synopsis printf("left %" i_DF "\n", i_DFc(x));
743 This is a constant string that can be used with functions like
744 printf() to format i_img_dim values after they're been cast with i_DFc().
746 Does not include the leading C<%>.
754 Cast an C<i_img_dim> value to a type for use with the i_DF format
761 =synopsis printf("point (" i_DFp ")\n", i_DFcp(x, y));
764 Format a pair of C<i_img_dim> values. This format string I<does>
765 include the leading C<%>.
773 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
778 #define i_DFc(x) ((i_dim_format_t)(x))
779 #define i_DFcp(x, y) i_DFc(x), i_DFc(y)
780 #define i_DFp "%" i_DF ", %" i_DF