9 /* used for palette indices in some internal code (which might be
12 typedef unsigned char i_palidx;
14 /* We handle 2 types of sample, this is hopefully the most common, and the
15 smaller of the ones we support */
16 typedef unsigned char i_sample_t;
18 typedef struct { i_sample_t gray_color; } gray_color;
19 typedef struct { i_sample_t r,g,b; } rgb_color;
20 typedef struct { i_sample_t r,g,b,a; } rgba_color;
21 typedef struct { i_sample_t c,m,y,k; } cmyk_color;
23 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
28 =synopsis i_img_dim x, y;
31 A signed integer type that represents an image dimension or ordinate.
33 May be larger than int on some platforms.
38 typedef ptrdiff_t i_img_dim;
43 =synopsis i_color black;
44 =synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
46 Type for 8-bit/sample color.
52 i_color is a union of:
58 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
62 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
66 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
70 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
71 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
72 reading/writing files.
76 channels - an array of four channels, eg C<c.channels[2]>.
88 i_sample_t channel[MAXCHANNELS];
92 /* this is the larger sample type, it should be able to accurately represent
93 any sample size we use */
94 typedef double i_fsample_t;
96 typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
97 typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
98 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
99 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
105 This is the double/sample color type.
107 Its layout exactly corresponds to i_color.
113 i_fgray_color_t gray;
115 i_frgba_color_t rgba;
116 i_fcmyk_color_t cmyk;
117 i_fsample_t channel[MAXCHANNELS];
121 i_direct_type, /* direct colour, keeps RGB values per pixel */
122 i_palette_type /* keeps a palette index per pixel */
126 /* bits per sample, not per pixel */
127 /* a paletted image might have one bit per sample */
130 i_double_bits = sizeof(double) * 8
134 char *name; /* name of a given tag, might be NULL */
135 int code; /* number of a given tag, -1 if it has no meaning */
136 char *data; /* value of a given tag if it's not an int, may be NULL */
137 int size; /* size of the data */
138 int idata; /* value of a given tag if data is NULL */
142 int count; /* how many tags have been set */
143 int alloc; /* how many tags have been allocated for */
147 typedef struct i_img_ i_img;
148 typedef int (*i_f_ppix_t)(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
149 typedef int (*i_f_ppixf_t)(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
150 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);
151 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);
152 typedef int (*i_f_gpix_t)(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
153 typedef int (*i_f_gpixf_t)(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
154 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);
155 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);
157 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,
158 const int *chans, int chan_count);
159 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,
160 const int *chan, int chan_count);
162 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);
163 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);
164 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
165 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
166 typedef int (*i_f_colorcount_t)(i_img *im);
167 typedef int (*i_f_maxcolors_t)(i_img *im);
168 typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
169 typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
172 typedef void (*i_f_destroy_t)(i_img *im);
174 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,
175 const int *chans, int chan_count, int bits);
176 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,
177 const int *chans, int chan_count, int bits);
182 =synopsis i_img *img;
185 This is Imager's image type.
187 It contains the following members:
193 C<channels> - the number of channels in the image
197 C<xsize>, C<ysize> - the width and height of the image in pixels
201 C<bytes> - the number of bytes used to store the image data. Undefined
202 where virtual is non-zero.
206 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
207 channels 1 and 2 are writable. There may be bits set for which there
208 are no channels in the image.
212 C<bits> - the number of bits stored per sample. Should be one of
213 i_8_bits, i_16_bits, i_double_bits.
217 C<type> - either i_direct_type for direct color images, or i_palette_type
222 C<virtual> - if zero then this image is-self contained. If non-zero
223 then this image could be an interface to some other implementation.
227 C<idata> - the image data. This should not be directly accessed. A new
228 image implementation can use this to store its image data.
229 i_img_destroy() will myfree() this pointer if it's non-null.
233 C<tags> - a structure storing the image's tags. This should only be
234 accessed via the i_tags_*() functions.
238 C<ext_data> - a pointer for use internal to an image implementation.
239 This should be freed by the image's destroy handler.
243 C<im_data> - data internal to Imager. This is initialized by
248 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
249 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
250 of the required image functions. An image implementation should
251 initialize these between calling i_img_alloc() and i_img_init().
255 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
256 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
257 paletted image function.
261 i_f_destroy - custom image destruction function. This should be used
262 to release memory if necessary.
266 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
270 i_f_psamp_bits - implements i_psamp_bits() for this image.
279 i_img_dim xsize,ysize;
281 unsigned int ch_mask;
284 int virtual; /* image might not keep any data, must use functions */
285 unsigned char *idata; /* renamed to force inspection of existing code */
286 /* can be NULL if virtual is non-zero */
291 /* interface functions */
293 i_f_ppixf_t i_f_ppixf;
295 i_f_plinf_t i_f_plinf;
297 i_f_gpixf_t i_f_gpixf;
299 i_f_glinf_t i_f_glinf;
300 i_f_gsamp_t i_f_gsamp;
301 i_f_gsampf_t i_f_gsampf;
303 /* only valid for type == i_palette_type */
306 i_f_addcolors_t i_f_addcolors;
307 i_f_getcolors_t i_f_getcolors;
308 i_f_colorcount_t i_f_colorcount;
309 i_f_maxcolors_t i_f_maxcolors;
310 i_f_findcolor_t i_f_findcolor;
311 i_f_setcolors_t i_f_setcolors;
313 i_f_destroy_t i_f_destroy;
316 i_f_gsamp_bits_t i_f_gsamp_bits;
317 i_f_psamp_bits_t i_f_psamp_bits;
322 /* ext_data for paletted images
325 int count; /* amount of space used in palette (in entries) */
326 int alloc; /* amount of space allocated for palette (in entries) */
332 The types in here so far are:
334 doubly linked bucket list - pretty efficient
335 octtree - no idea about goodness
344 i_img_dim xsize,ysize;
348 struct i_bitmap* btm_new(i_img_dim xsize,i_img_dim ysize);
349 void btm_destroy(struct i_bitmap *btm);
350 int btm_test(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
351 void btm_set(struct i_bitmap *btm,i_img_dim x,i_img_dim y);
354 /* Stack/Linked list */
359 int fill; /* Number used in this link */
364 int multip; /* # of copies in a single chain */
365 size_t ssize; /* size of each small element */
366 int count; /* number of elements on the list */
372 struct llist *llist_new( int multip, size_t ssize );
373 void llist_destroy( struct llist *l );
374 void llist_push( struct llist *l, const void *data );
375 void llist_dump( struct llist *l );
376 int llist_pop( struct llist *l,void *data );
388 struct octt *octt_new(void);
389 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
390 void octt_dump(struct octt *ct);
391 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
392 void octt_delete(struct octt *ct);
393 void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
395 /* font bounding box results */
396 enum bounding_box_index_t {
411 typedef void (*i_fill_with_color_f)
412 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
414 typedef void (*i_fill_with_fcolor_f)
415 (struct i_fill_tag *fill, i_img_dim x, i_img_dim y, i_img_dim width, int channels,
417 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
419 /* combine functions modify their target and are permitted to modify
420 the source to prevent having to perform extra copying/memory
422 The out array has I<channels> channels.
424 The in array has I<channels> channels + an alpha channel if one
425 isn't included in I<channels>.
428 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
430 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
433 /* fountain fill types */
441 } i_fountain_seg_type;
449 double start, middle, end;
451 i_fountain_seg_type type;
452 i_fountain_color color;
480 =synopsis i_fill_t *fill;
482 This is the "abstract" base type for Imager's fill types.
484 Unless you're implementing a new fill type you'll typically treat this
490 typedef struct i_fill_tag
492 /* called for 8-bit/sample image (and maybe lower) */
493 /* this may be NULL, if so call fill_with_fcolor */
494 i_fill_with_color_f f_fill_with_color;
496 /* called for other sample sizes */
497 /* this must be non-NULL */
498 i_fill_with_fcolor_f f_fill_with_fcolor;
500 /* called if non-NULL to release any extra resources */
501 i_fill_destroy_f destroy;
503 /* if non-zero the caller will fill data with the original data
505 i_fill_combine_f combine;
506 i_fill_combinef_f combinef;
526 describes an axis of a MM font.
527 Modelled on FT2's FT_MM_Axis.
528 It would be nice to have a default entry too, but FT2
531 typedef struct i_font_mm_axis_tag {
537 #define IM_FONT_MM_MAX_AXES 4
540 multiple master information for a font, if any
541 modelled on FT2's FT_Multi_Master.
543 typedef struct i_font_mm_tag {
545 int num_designs; /* provided but not necessarily useful */
546 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
551 struct TT_Fonthandle_;
553 typedef struct TT_Fonthandle_ TT_Fonthandle;
557 /* transparency handling for quantized output */
558 typedef enum i_transp_tag {
559 tr_none, /* ignore any alpha channel */
560 tr_threshold, /* threshold the transparency - uses tr_threshold */
561 tr_errdiff, /* error diffusion */
562 tr_ordered /* an ordered dither */
565 /* controls how we build the colour map */
566 typedef enum i_make_colors_tag {
567 mc_none, /* user supplied colour map only */
568 mc_web_map, /* Use the 216 colour web colour map */
569 mc_addi, /* Addi's algorithm */
570 mc_median_cut, /* median cut - similar to giflib, hopefully */
571 mc_mono, /* fixed mono color map */
572 mc_mask = 0xFF /* (mask for generator) */
575 /* controls how we translate the colours */
576 typedef enum i_translate_tag {
577 pt_giflib, /* get gif lib to do it (ignores make_colours) */
578 pt_closest, /* just use the closest match within the hashbox */
579 pt_perturb, /* randomly perturb the data - uses perturb_size*/
580 pt_errdiff /* error diffusion dither - uses errdiff */
583 /* Which error diffusion map to use */
584 typedef enum i_errdiff_tag {
585 ed_floyd, /* floyd-steinberg */
586 ed_jarvis, /* Jarvis, Judice and Ninke */
587 ed_stucki, /* Stucki */
588 ed_custom, /* the map found in ed_map|width|height|orig */
589 ed_mask = 0xFF, /* mask to get the map */
590 ed_bidir = 0x100 /* change direction for each row */
593 /* which ordered dither map to use
594 currently only available for transparency
595 I don't know of a way to do ordered dither of an image against some
598 typedef enum i_ord_dith_tag
600 od_random, /* sort of random */
601 od_dot8, /* large dot */
605 od_slashline, /* / line dither */
606 od_backline, /* \ line dither */
607 od_tiny, /* small checkerbox */
608 od_custom /* custom 8x8 map */
611 typedef struct i_gif_pos_tag {
615 /* passed into i_writegif_gen() to control quantization */
616 typedef struct i_quantize_tag {
619 /* how to handle transparency */
621 /* the threshold at which to make pixels opaque */
623 i_errdiff tr_errdiff;
624 i_ord_dith tr_orddith;
625 unsigned char tr_custom[64];
627 /* how to make the colour map */
628 i_make_colors make_colors;
630 /* any existing colours
631 mc_existing is an existing colour table
632 mc_count is the number of existing colours
633 mc_size is the total size of the array that mc_existing points
634 at - this must be at least 256
640 /* how we translate the colours */
641 i_translate translate;
643 /* the error diffusion map to use if translate is mc_errdiff */
645 /* the following define the error diffusion values to use if
646 errdiff is ed_custom. ed_orig is the column on the top row that
647 represents the current
650 int ed_width, ed_height, ed_orig;
652 /* the amount of perturbation to use for translate is mc_perturb */
654 /* version 2 members after here */
657 typedef struct i_gif_opts {
658 /* each image has a local color map */
661 /* images are interlaced */
664 /* time for which image is displayed
674 int user_input_count;
675 char *user_input_flags;
682 /* this is added to the color table when we make an image transparent */
685 /* image positions */
687 i_gif_pos *positions;
689 /* Netscape loop extension - number of loops */
692 /* should be eliminate unused colors? */
693 int eliminate_unused;
696 /* distance measures used by some filters */
698 i_dmeasure_euclidean = 0,
699 i_dmeasure_euclidean_squared = 1,
700 i_dmeasure_manhatten = 2,
701 i_dmeasure_limit = 2,
704 #include "iolayert.h"
706 typedef struct i_render_tag i_render;
708 #ifdef IMAGER_FORMAT_ATTR
709 #define I_FORMAT_ATTR(format_index, va_index) \
710 __attribute ((format (printf, format_index, va_index)))
712 #define I_FORMAT_ATTR(format_index, va_index)
718 =synopsis printf("left %" i_DF "\n", i_DFc(x));
721 This is a constant string that can be used with functions like
722 printf() to format i_img_dim values after they're been cast with i_DFc().
724 Does not include the leading C<%>.
732 Cast an C<i_img_dim> value to a type for use with the i_DF format
739 =synopsis printf("point (" i_DFp ")\n", i_DFcp(x, y));
742 Format a pair of C<i_img_dim> values. This format string I<does>
743 include the leading C<%>.
751 Casts two C<i_img_dim> values for use with the i_DF (or i_DFp) format.
756 #define i_DFc(x) ((i_dim_format_t)(x))
757 #define i_DFcp(x, y) i_DFc(x), i_DFc(y)
758 #define i_DFp "%" i_DF ", %" i_DF