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_color black;
29 =synopsis black.rgba.r = black.rgba.g = black.rgba.b = black.rgba.a = 0;
31 Type for 8-bit/sample color.
37 i_color is a union of:
43 gray - contains a single element gray_color, eg. C<c.gray.gray_color>
47 C<rgb> - contains three elements C<r>, C<g>, C<b>, eg. C<c.rgb.r>
51 C<rgba> - contains four elements C<r>, C<g>, C<b>, C<a>, eg. C<c.rgba.a>
55 C<cmyk> - contains four elements C<c>, C<m>, C<y>, C<k>,
56 eg. C<c.cmyk.y>. Note that Imager never uses CMYK colors except when
57 reading/writing files.
61 channels - an array of four channels, eg C<c.channels[2]>.
73 i_sample_t channel[MAXCHANNELS];
77 /* this is the larger sample type, it should be able to accurately represent
78 any sample size we use */
79 typedef double i_fsample_t;
81 typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
82 typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
83 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
84 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
90 This is the double/sample color type.
92 Its layout exactly corresponds to i_color.
100 i_frgba_color_t rgba;
101 i_fcmyk_color_t cmyk;
102 i_fsample_t channel[MAXCHANNELS];
106 i_direct_type, /* direct colour, keeps RGB values per pixel */
107 i_palette_type /* keeps a palette index per pixel */
111 /* bits per sample, not per pixel */
112 /* a paletted image might have one bit per sample */
115 i_double_bits = sizeof(double) * 8
119 char *name; /* name of a given tag, might be NULL */
120 int code; /* number of a given tag, -1 if it has no meaning */
121 char *data; /* value of a given tag if it's not an int, may be NULL */
122 int size; /* size of the data */
123 int idata; /* value of a given tag if data is NULL */
127 int count; /* how many tags have been set */
128 int alloc; /* how many tags have been allocated for */
132 typedef struct i_img_ i_img;
133 typedef int (*i_f_ppix_t)(i_img *im, int x, int y, const i_color *pix);
134 typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, const i_fcolor *pix);
135 typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, const i_color *vals);
136 typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, const i_fcolor *vals);
137 typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix);
138 typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix);
139 typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals);
140 typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
142 typedef int (*i_f_gsamp_t)(i_img *im, int x, int r, int y, i_sample_t *samp,
143 const int *chans, int chan_count);
144 typedef int (*i_f_gsampf_t)(i_img *im, int x, int r, int y, i_fsample_t *samp,
145 const int *chan, int chan_count);
147 typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
148 typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, const i_palidx *vals);
149 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
150 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
151 typedef int (*i_f_colorcount_t)(i_img *im);
152 typedef int (*i_f_maxcolors_t)(i_img *im);
153 typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
154 typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
157 typedef void (*i_f_destroy_t)(i_img *im);
159 typedef int (*i_f_gsamp_bits_t)(i_img *im, int x, int r, int y, unsigned *samp,
160 const int *chans, int chan_count, int bits);
161 typedef int (*i_f_psamp_bits_t)(i_img *im, int x, int r, int y, unsigned const *samp,
162 const int *chans, int chan_count, int bits);
167 =synopsis i_img_dim x;
170 A signed integer type that represents an image dimension or ordinate.
172 May be larger than int on some platforms.
176 typedef int i_img_dim;
181 =synopsis i_img *img;
184 This is Imager's image type.
186 It contains the following members:
192 C<channels> - the number of channels in the image
196 C<xsize>, C<ysize> - the width and height of the image in pixels
200 C<bytes> - the number of bytes used to store the image data. Undefined
201 where virtual is non-zero.
205 C<ch_mask> - a mask of writable channels. eg. if this is 6 then only
206 channels 1 and 2 are writable. There may be bits set for which there
207 are no channels in the image.
211 C<bits> - the number of bits stored per sample. Should be one of
212 i_8_bits, i_16_bits, i_double_bits.
216 C<type> - either i_direct_type for direct color images, or i_palette_type
221 C<virtual> - if zero then this image is-self contained. If non-zero
222 then this image could be an interface to some other implementation.
226 C<idata> - the image data. This should not be directly accessed. A new
227 image implementation can use this to store its image data.
228 i_img_destroy() will myfree() this pointer if it's non-null.
232 C<tags> - a structure storing the image's tags. This should only be
233 accessed via the i_tags_*() functions.
237 C<ext_data> - a pointer for use internal to an image implementation.
238 This should be freed by the image's destroy handler.
242 C<im_data> - data internal to Imager. This is initialized by
247 i_f_ppix, i_f_ppixf, i_f_plin, i_f_plinf, i_f_gpix, i_f_gpixf,
248 i_f_glin, i_f_glinf, i_f_gsamp, i_f_gampf - implementations for each
249 of the required image functions. An image implementation should
250 initialize these between calling i_img_alloc() and i_img_init().
254 i_f_gpal, i_f_ppal, i_f_addcolors, i_f_getcolors, i_f_colorcount,
255 i_f_maxcolors, i_f_findcolor, i_f_setcolors - implementations for each
256 paletted image function.
260 i_f_destroy - custom image destruction function. This should be used
261 to release memory if necessary.
265 i_f_gsamp_bits - implements i_gsamp_bits() for this image.
269 i_f_psamp_bits - implements i_psamp_bits() for this image.
278 i_img_dim xsize,ysize;
280 unsigned int ch_mask;
283 int virtual; /* image might not keep any data, must use functions */
284 unsigned char *idata; /* renamed to force inspection of existing code */
285 /* can be NULL if virtual is non-zero */
290 /* interface functions */
292 i_f_ppixf_t i_f_ppixf;
294 i_f_plinf_t i_f_plinf;
296 i_f_gpixf_t i_f_gpixf;
298 i_f_glinf_t i_f_glinf;
299 i_f_gsamp_t i_f_gsamp;
300 i_f_gsampf_t i_f_gsampf;
302 /* only valid for type == i_palette_type */
305 i_f_addcolors_t i_f_addcolors;
306 i_f_getcolors_t i_f_getcolors;
307 i_f_colorcount_t i_f_colorcount;
308 i_f_maxcolors_t i_f_maxcolors;
309 i_f_findcolor_t i_f_findcolor;
310 i_f_setcolors_t i_f_setcolors;
312 i_f_destroy_t i_f_destroy;
315 i_f_gsamp_bits_t i_f_gsamp_bits;
316 i_f_psamp_bits_t i_f_psamp_bits;
321 /* ext_data for paletted images
324 int count; /* amount of space used in palette (in entries) */
325 int alloc; /* amount of space allocated for palette (in entries) */
331 The types in here so far are:
333 doubly linked bucket list - pretty efficient
334 octtree - no idea about goodness
347 struct i_bitmap* btm_new(int xsize,int ysize);
348 void btm_destroy(struct i_bitmap *btm);
349 int btm_test(struct i_bitmap *btm,int x,int y);
350 void btm_set(struct i_bitmap *btm,int x,int y);
353 /* Stack/Linked list */
358 int fill; /* Number used in this link */
363 int multip; /* # of copies in a single chain */
364 int ssize; /* size of each small element */
365 int count; /* number of elements on the list */
371 struct llink *llink_new( struct llink* p,int size );
372 int llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
376 struct llist *llist_new( int multip, int ssize );
377 void llist_destroy( struct llist *l );
378 void llist_push( struct llist *l, void *data );
379 void llist_dump( struct llist *l );
380 int llist_pop( struct llist *l,void *data );
392 struct octt *octt_new(void);
393 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
394 void octt_dump(struct octt *ct);
395 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
396 void octt_delete(struct octt *ct);
397 void octt_histo(struct octt *ct, unsigned int **col_usage_it_adr);
399 /* font bounding box results */
400 enum bounding_box_index_t {
415 typedef void (*i_fill_with_color_f)
416 (struct i_fill_tag *fill, int x, int y, int width, int channels,
418 typedef void (*i_fill_with_fcolor_f)
419 (struct i_fill_tag *fill, int x, int y, int width, int channels,
421 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
423 /* combine functions modify their target and are permitted to modify
424 the source to prevent having to perform extra copying/memory
426 The out array has I<channels> channels.
428 The in array has I<channels> channels + an alpha channel if one
429 isn't included in I<channels>.
432 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
434 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
437 /* fountain fill types */
445 } i_fountain_seg_type;
453 double start, middle, end;
455 i_fountain_seg_type type;
456 i_fountain_color color;
484 =synopsis i_fill_t *fill;
486 This is the "abstract" base type for Imager's fill types.
488 Unless you're implementing a new fill type you'll typically treat this
494 typedef struct i_fill_tag
496 /* called for 8-bit/sample image (and maybe lower) */
497 /* this may be NULL, if so call fill_with_fcolor */
498 i_fill_with_color_f f_fill_with_color;
500 /* called for other sample sizes */
501 /* this must be non-NULL */
502 i_fill_with_fcolor_f f_fill_with_fcolor;
504 /* called if non-NULL to release any extra resources */
505 i_fill_destroy_f destroy;
507 /* if non-zero the caller will fill data with the original data
509 i_fill_combine_f combine;
510 i_fill_combinef_f combinef;
530 describes an axis of a MM font.
531 Modelled on FT2's FT_MM_Axis.
532 It would be nice to have a default entry too, but FT2
535 typedef struct i_font_mm_axis_tag {
541 #define IM_FONT_MM_MAX_AXES 4
544 multiple master information for a font, if any
545 modelled on FT2's FT_Multi_Master.
547 typedef struct i_font_mm_tag {
549 int num_designs; /* provided but not necessarily useful */
550 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
555 struct TT_Fonthandle_;
557 typedef struct TT_Fonthandle_ TT_Fonthandle;
563 typedef struct FT2_Fonthandle FT2_Fonthandle;
567 /* transparency handling for quantized output */
568 typedef enum i_transp_tag {
569 tr_none, /* ignore any alpha channel */
570 tr_threshold, /* threshold the transparency - uses tr_threshold */
571 tr_errdiff, /* error diffusion */
572 tr_ordered /* an ordered dither */
575 /* controls how we build the colour map */
576 typedef enum i_make_colors_tag {
577 mc_none, /* user supplied colour map only */
578 mc_web_map, /* Use the 216 colour web colour map */
579 mc_addi, /* Addi's algorithm */
580 mc_median_cut, /* median cut - similar to giflib, hopefully */
581 mc_mono, /* fixed mono color map */
582 mc_mask = 0xFF /* (mask for generator) */
585 /* controls how we translate the colours */
586 typedef enum i_translate_tag {
587 pt_giflib, /* get gif lib to do it (ignores make_colours) */
588 pt_closest, /* just use the closest match within the hashbox */
589 pt_perturb, /* randomly perturb the data - uses perturb_size*/
590 pt_errdiff /* error diffusion dither - uses errdiff */
593 /* Which error diffusion map to use */
594 typedef enum i_errdiff_tag {
595 ed_floyd, /* floyd-steinberg */
596 ed_jarvis, /* Jarvis, Judice and Ninke */
597 ed_stucki, /* Stucki */
598 ed_custom, /* the map found in ed_map|width|height|orig */
599 ed_mask = 0xFF, /* mask to get the map */
600 ed_bidir = 0x100 /* change direction for each row */
603 /* which ordered dither map to use
604 currently only available for transparency
605 I don't know of a way to do ordered dither of an image against some
608 typedef enum i_ord_dith_tag
610 od_random, /* sort of random */
611 od_dot8, /* large dot */
615 od_slashline, /* / line dither */
616 od_backline, /* \ line dither */
617 od_tiny, /* small checkerbox */
618 od_custom /* custom 8x8 map */
621 typedef struct i_gif_pos_tag {
625 /* passed into i_writegif_gen() to control quantization */
626 typedef struct i_quantize_tag {
629 /* how to handle transparency */
631 /* the threshold at which to make pixels opaque */
633 i_errdiff tr_errdiff;
634 i_ord_dith tr_orddith;
635 unsigned char tr_custom[64];
637 /* how to make the colour map */
638 i_make_colors make_colors;
640 /* any existing colours
641 mc_existing is an existing colour table
642 mc_count is the number of existing colours
643 mc_size is the total size of the array that mc_existing points
644 at - this must be at least 256
650 /* how we translate the colours */
651 i_translate translate;
653 /* the error diffusion map to use if translate is mc_errdiff */
655 /* the following define the error diffusion values to use if
656 errdiff is ed_custom. ed_orig is the column on the top row that
657 represents the current
660 int ed_width, ed_height, ed_orig;
662 /* the amount of perturbation to use for translate is mc_perturb */
664 /* version 2 members after here */
667 typedef struct i_gif_opts {
668 /* each image has a local color map */
671 /* images are interlaced */
674 /* time for which image is displayed
684 int user_input_count;
685 char *user_input_flags;
692 /* this is added to the color table when we make an image transparent */
695 /* image positions */
697 i_gif_pos *positions;
699 /* Netscape loop extension - number of loops */
702 /* should be eliminate unused colors? */
703 int eliminate_unused;
706 /* distance measures used by some filters */
708 i_dmeasure_euclidean = 0,
709 i_dmeasure_euclidean_squared = 1,
710 i_dmeasure_manhatten = 2,
711 i_dmeasure_limit = 2,
714 #include "iolayert.h"