Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 521 lines (421 sloc) 13.306 kb
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
1 #ifndef _DATATYPES_H_
2 #define _DATATYPES_H_
3
7ac6a2e9 » Tony Cook
2004-10-25 - renamed io.h to imio.h to prevent problems building under cygwin.
4 #include "imio.h"
92bda632 » Tony Cook
2006-01-10 - start of external Imager API access:
5 #include "imconfig.h"
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
6
7 #define MAXCHANNELS 4
8
faa9b3e7 » Tony Cook
2001-08-13 Egads
9 /* used for palette indices in some internal code (which might be
10 exposed at some point
11 */
12 typedef unsigned char i_palidx;
13
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;
17
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;
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
22
23 typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
24
25 typedef union {
26 gray_color gray;
27 rgb_color rgb;
28 rgba_color rgba;
29 cmyk_color cmyk;
faa9b3e7 » Tony Cook
2001-08-13 Egads
30 i_sample_t channel[MAXCHANNELS];
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
31 unsigned int ui;
32 } i_color;
33
faa9b3e7 » Tony Cook
2001-08-13 Egads
34 /* this is the larger sample type, it should be able to accurately represent
35 any sample size we use */
36 typedef double i_fsample_t;
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
37
faa9b3e7 » Tony Cook
2001-08-13 Egads
38 typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
39 typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
40 typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
41 typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
42
43 typedef union {
44 i_fgray_color_t gray;
45 i_frgb_color_t rgb;
46 i_frgba_color_t rgba;
47 i_fcmyk_color_t cmyk;
48 i_fsample_t channel[MAXCHANNELS];
49 } i_fcolor;
50
51 typedef enum {
52 i_direct_type, /* direct colour, keeps RGB values per pixel */
26fd367b » Tony Cook
2002-05-01 various changes from trying to build on testdrive
53 i_palette_type /* keeps a palette index per pixel */
faa9b3e7 » Tony Cook
2001-08-13 Egads
54 } i_img_type_t;
55
56 typedef enum {
57 /* bits per sample, not per pixel */
58 /* a paletted image might have one bit per sample */
59 i_8_bits = 8,
60 i_16_bits = 16,
26fd367b » Tony Cook
2002-05-01 various changes from trying to build on testdrive
61 i_double_bits = sizeof(double) * 8
faa9b3e7 » Tony Cook
2001-08-13 Egads
62 } i_img_bits_t;
63
64 typedef struct {
65 char *name; /* name of a given tag, might be NULL */
66 int code; /* number of a given tag, -1 if it has no meaning */
67 char *data; /* value of a given tag if it's not an int, may be NULL */
68 int size; /* size of the data */
69 int idata; /* value of a given tag if data is NULL */
70 } i_img_tag;
71
72 typedef struct {
73 int count; /* how many tags have been set */
74 int alloc; /* how many tags have been allocated for */
75 i_img_tag *tags;
76 } i_img_tags;
77
78 typedef struct i_img_ i_img;
97ac0a96 » Tony Cook
2006-01-11 - constify the Imager API
79 typedef int (*i_f_ppix_t)(i_img *im, int x, int y, const i_color *pix);
80 typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, const i_fcolor *pix);
81 typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, const i_color *vals);
82 typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, const i_fcolor *vals);
faa9b3e7 » Tony Cook
2001-08-13 Egads
83 typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix);
84 typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix);
85 typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals);
86 typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
87
88 typedef int (*i_f_gsamp_t)(i_img *im, int x, int r, int y, i_sample_t *samp,
18accb2a » Tony Cook
2002-03-25 Ticket #369 - writing grayscale images to GIF
89 const int *chans, int chan_count);
faa9b3e7 » Tony Cook
2001-08-13 Egads
90 typedef int (*i_f_gsampf_t)(i_img *im, int x, int r, int y, i_fsample_t *samp,
18accb2a » Tony Cook
2002-03-25 Ticket #369 - writing grayscale images to GIF
91 const int *chan, int chan_count);
faa9b3e7 » Tony Cook
2001-08-13 Egads
92
93 typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
97ac0a96 » Tony Cook
2006-01-11 - constify the Imager API
94 typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, const i_palidx *vals);
95 typedef int (*i_f_addcolors_t)(i_img *im, const i_color *colors, int count);
faa9b3e7 » Tony Cook
2001-08-13 Egads
96 typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
97 typedef int (*i_f_colorcount_t)(i_img *im);
98 typedef int (*i_f_maxcolors_t)(i_img *im);
97ac0a96 » Tony Cook
2006-01-11 - constify the Imager API
99 typedef int (*i_f_findcolor_t)(i_img *im, const i_color *color, i_palidx *entry);
100 typedef int (*i_f_setcolors_t)(i_img *im, int index, const i_color *colors,
faa9b3e7 » Tony Cook
2001-08-13 Egads
101 int count);
102
103 typedef void (*i_f_destroy_t)(i_img *im);
104
105 struct i_img_ {
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
106 int channels;
107 int xsize,ysize,bytes;
108 unsigned int ch_mask;
faa9b3e7 » Tony Cook
2001-08-13 Egads
109 i_img_bits_t bits;
110 i_img_type_t type;
111 int virtual; /* image might not keep any data, must use functions */
112 unsigned char *idata; /* renamed to force inspection of existing code */
113 /* can be NULL if virtual is non-zero */
114 i_img_tags tags;
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
115
116 void *ext_data;
117
faa9b3e7 » Tony Cook
2001-08-13 Egads
118 /* interface functions */
119 i_f_ppix_t i_f_ppix;
120 i_f_ppixf_t i_f_ppixf;
121 i_f_plin_t i_f_plin;
122 i_f_plinf_t i_f_plinf;
123 i_f_gpix_t i_f_gpix;
124 i_f_gpixf_t i_f_gpixf;
125 i_f_glin_t i_f_glin;
126 i_f_glinf_t i_f_glinf;
127 i_f_gsamp_t i_f_gsamp;
128 i_f_gsampf_t i_f_gsampf;
129
130 /* only valid for type == i_palette_type */
131 i_f_gpal_t i_f_gpal;
132 i_f_ppal_t i_f_ppal;
133 i_f_addcolors_t i_f_addcolors;
134 i_f_getcolors_t i_f_getcolors;
135 i_f_colorcount_t i_f_colorcount;
136 i_f_maxcolors_t i_f_maxcolors;
137 i_f_findcolor_t i_f_findcolor;
138 i_f_setcolors_t i_f_setcolors;
139
140 i_f_destroy_t i_f_destroy;
141 };
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
142
faa9b3e7 » Tony Cook
2001-08-13 Egads
143 /* ext_data for paletted images
144 */
145 typedef struct {
146 int count; /* amount of space used in palette (in entries) */
147 int alloc; /* amount of space allocated for palette (in entries) */
148 i_color *pal;
149 int last_found;
150 } i_img_pal_ext;
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
151
faa9b3e7 » Tony Cook
2001-08-13 Egads
152 /* Helper datatypes
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
153 The types in here so far are:
154
155 doubly linked bucket list - pretty efficient
156 octtree - no idea about goodness
157
158 needed: hashes.
159
160 */
161
162
163
164
165
166 /* bitmap mask */
167
168 struct i_bitmap {
169 int xsize,ysize;
170 char *data;
171 };
172
173 struct i_bitmap* btm_new(int xsize,int ysize);
174 void btm_destroy(struct i_bitmap *btm);
175 int btm_test(struct i_bitmap *btm,int x,int y);
176 void btm_set(struct i_bitmap *btm,int x,int y);
177
178
179
180
181
182
183
184
185 /* Stack/Linked list */
186
187 struct llink {
188 struct llink *p,*n;
189 void *data;
190 int fill; /* Number used in this link */
191 };
192
193 struct llist {
194 struct llink *h,*t;
195 int multip; /* # of copies in a single chain */
196 int ssize; /* size of each small element */
197 int count; /* number of elements on the list */
198 };
199
200
201 /* Links */
202
203 struct llink *llink_new( struct llink* p,int size );
204 int llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
205
206 /* Lists */
207
208 struct llist *llist_new( int multip, int ssize );
209 void llist_destroy( struct llist *l );
210 void llist_push( struct llist *l, void *data );
211 void llist_dump( struct llist *l );
212 int llist_pop( struct llist *l,void *data );
213
214
215
216
217 /* Octtree */
218
219 struct octt {
220 struct octt *t[8];
221 int cnt;
222 };
223
faa9b3e7 » Tony Cook
2001-08-13 Egads
224 struct octt *octt_new(void);
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
225 int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
226 void octt_dump(struct octt *ct);
227 void octt_count(struct octt *ct,int *tot,int max,int *overflow);
228 void octt_delete(struct octt *ct);
229
3799c4d1 » Tony Cook
2002-12-31 - implemented i_t1_has_chars(), tests for same
230 /* font bounding box results */
231 enum bounding_box_index_t {
232 BBOX_NEG_WIDTH,
233 BBOX_GLOBAL_DESCENT,
234 BBOX_POS_WIDTH,
235 BBOX_GLOBAL_ASCENT,
236 BBOX_DESCENT,
237 BBOX_ASCENT,
238 BBOX_ADVANCE_WIDTH,
dc35bde9 » Tony Cook
2005-04-24 - Imager::Font::BBox objects now have right_bearing() and display_wid…
239 BBOX_RIGHT_BEARING,
3799c4d1 » Tony Cook
2002-12-31 - implemented i_t1_has_chars(), tests for same
240 BOUNDING_BOX_COUNT
241 };
242
92bda632 » Tony Cook
2006-01-10 - start of external Imager API access:
243 /* Generic fills */
244 struct i_fill_tag;
245
246 typedef void (*i_fill_with_color_f)
247 (struct i_fill_tag *fill, int x, int y, int width, int channels,
248 i_color *data);
249 typedef void (*i_fill_with_fcolor_f)
250 (struct i_fill_tag *fill, int x, int y, int width, int channels,
251 i_fcolor *data);
252 typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill);
253 typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels,
254 int count);
255 typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels,
256 int count);
257
258 /* fountain fill types */
259 typedef enum {
260 i_fst_linear,
261 i_fst_curved,
262 i_fst_sine,
263 i_fst_sphere_up,
264 i_fst_sphere_down,
265 i_fst_end
266 } i_fountain_seg_type;
267 typedef enum {
268 i_fc_direct,
269 i_fc_hue_up,
270 i_fc_hue_down,
271 i_fc_end
272 } i_fountain_color;
273 typedef struct {
274 double start, middle, end;
275 i_fcolor c[2];
276 i_fountain_seg_type type;
277 i_fountain_color color;
278 } i_fountain_seg;
279 typedef enum {
280 i_fr_none,
281 i_fr_sawtooth,
282 i_fr_triangle,
283 i_fr_saw_both,
284 i_fr_tri_both
285 } i_fountain_repeat;
286 typedef enum {
287 i_ft_linear,
288 i_ft_bilinear,
289 i_ft_radial,
290 i_ft_radial_square,
291 i_ft_revolution,
292 i_ft_conical,
293 i_ft_end
294 } i_fountain_type;
295 typedef enum {
296 i_fts_none,
297 i_fts_grid,
298 i_fts_random,
299 i_fts_circle
300 } i_ft_supersample;
301
302
303 typedef struct i_fill_tag
304 {
305 /* called for 8-bit/sample image (and maybe lower) */
306 /* this may be NULL, if so call fill_with_fcolor */
307 i_fill_with_color_f fill_with_color;
308
309 /* called for other sample sizes */
310 /* this must be non-NULL */
311 i_fill_with_fcolor_f fill_with_fcolor;
312
313 /* called if non-NULL to release any extra resources */
314 i_fill_destroy_f destroy;
315
316 /* if non-zero the caller will fill data with the original data
317 from the image */
318 i_fill_combine_f combine;
319 i_fill_combinef_f combinef;
320 } i_fill_t;
321
322 typedef enum {
323 ic_none,
324 ic_normal,
325 ic_multiply,
326 ic_dissolve,
327 ic_add,
328 ic_subtract,
329 ic_diff,
330 ic_lighten,
331 ic_darken,
332 ic_hue,
333 ic_sat,
334 ic_value,
335 ic_color
336 } i_combine_t;
337
338 /*
339 describes an axis of a MM font.
340 Modelled on FT2's FT_MM_Axis.
341 It would be nice to have a default entry too, but FT2
342 doesn't support it.
343 */
344 typedef struct i_font_mm_axis_tag {
345 char const *name;
346 int minimum;
347 int maximum;
348 } i_font_mm_axis;
349
350 #define IM_FONT_MM_MAX_AXES 4
351
352 /*
353 multiple master information for a font, if any
354 modelled on FT2's FT_Multi_Master.
355 */
356 typedef struct i_font_mm_tag {
357 int num_axis;
358 int num_designs; /* provided but not necessarily useful */
359 i_font_mm_axis axis[IM_FONT_MM_MAX_AXES];
360 } i_font_mm;
361
362 #ifdef HAVE_LIBTT
363
364 struct TT_Fonthandle_;
365
366 typedef struct TT_Fonthandle_ TT_Fonthandle;
367
368 #endif
369
370 #ifdef HAVE_FT2
371
372 typedef struct FT2_Fonthandle FT2_Fonthandle;
373
374 #endif
375
376 /* transparency handling for quantized output */
377 typedef enum i_transp_tag {
378 tr_none, /* ignore any alpha channel */
379 tr_threshold, /* threshold the transparency - uses tr_threshold */
380 tr_errdiff, /* error diffusion */
381 tr_ordered /* an ordered dither */
382 } i_transp;
383
384 /* controls how we build the colour map */
385 typedef enum i_make_colors_tag {
386 mc_none, /* user supplied colour map only */
387 mc_web_map, /* Use the 216 colour web colour map */
388 mc_addi, /* Addi's algorithm */
389 mc_median_cut, /* median cut - similar to giflib, hopefully */
390 mc_mask = 0xFF /* (mask for generator) */
391 } i_make_colors;
392
393 /* controls how we translate the colours */
394 typedef enum i_translate_tag {
395 pt_giflib, /* get gif lib to do it (ignores make_colours) */
396 pt_closest, /* just use the closest match within the hashbox */
397 pt_perturb, /* randomly perturb the data - uses perturb_size*/
398 pt_errdiff /* error diffusion dither - uses errdiff */
399 } i_translate;
400
401 /* Which error diffusion map to use */
402 typedef enum i_errdiff_tag {
403 ed_floyd, /* floyd-steinberg */
404 ed_jarvis, /* Jarvis, Judice and Ninke */
405 ed_stucki, /* Stucki */
406 ed_custom, /* the map found in ed_map|width|height|orig */
407 ed_mask = 0xFF, /* mask to get the map */
408 ed_bidir = 0x100 /* change direction for each row */
409 } i_errdiff;
410
411 /* which ordered dither map to use
412 currently only available for transparency
413 I don't know of a way to do ordered dither of an image against some
414 general palette
415 */
416 typedef enum i_ord_dith_tag
417 {
418 od_random, /* sort of random */
419 od_dot8, /* large dot */
420 od_dot4,
421 od_hline,
422 od_vline,
423 od_slashline, /* / line dither */
424 od_backline, /* \ line dither */
425 od_tiny, /* small checkerbox */
426 od_custom /* custom 8x8 map */
427 } i_ord_dith;
428
429 typedef struct i_gif_pos_tag {
430 int x, y;
431 } i_gif_pos;
432
433 /* passed into i_writegif_gen() to control quantization */
434 typedef struct i_quantize_tag {
435 /* how to handle transparency */
436 i_transp transp;
437 /* the threshold at which to make pixels opaque */
438 int tr_threshold;
439 i_errdiff tr_errdiff;
440 i_ord_dith tr_orddith;
441 unsigned char tr_custom[64];
442
443 /* how to make the colour map */
444 i_make_colors make_colors;
445
446 /* any existing colours
447 mc_existing is an existing colour table
448 mc_count is the number of existing colours
449 mc_size is the total size of the array that mc_existing points
450 at - this must be at least 256
451 */
452 i_color *mc_colors;
453 int mc_size;
454 int mc_count;
455
456 /* how we translate the colours */
457 i_translate translate;
458
459 /* the error diffusion map to use if translate is mc_errdiff */
460 i_errdiff errdiff;
461 /* the following define the error diffusion values to use if
462 errdiff is ed_custom. ed_orig is the column on the top row that
463 represents the current
464 */
465 int *ed_map;
466 int ed_width, ed_height, ed_orig;
467
468 /* the amount of perturbation to use for translate is mc_perturb */
469 int perturb;
470 } i_quantize;
471
472 typedef struct i_gif_opts {
473 /* each image has a local color map */
474 int each_palette;
475
476 /* images are interlaced */
477 int interlace;
478
479 /* time for which image is displayed
480 (in 1/100 seconds)
481 default: 0
482 */
483 int delay_count;
484 int *delays;
485
486 /* user input flags
487 default: 0
488 */
489 int user_input_count;
490 char *user_input_flags;
491
492 /* disposal
493 default: 0 */
494 int disposal_count;
495 char *disposal;
496
497 /* this is added to the color table when we make an image transparent */
498 i_color tran_color;
499
500 /* image positions */
501 int position_count;
502 i_gif_pos *positions;
503
504 /* Netscape loop extension - number of loops */
505 int loop_count;
506
507 /* should be eliminate unused colors? */
508 int eliminate_unused;
509 } i_gif_opts;
510
e310e5f9 » Tony Cook
2006-02-17 - more memory allocation integer overflow auditing
511 /* distance measures used by some filters */
512 enum {
513 i_dmeasure_euclidean = 0,
514 i_dmeasure_euclidean_squared = 1,
515 i_dmeasure_manhatten = 2,
516 i_dmeasure_limit = 2,
517 };
92bda632 » Tony Cook
2006-01-10 - start of external Imager API access:
518
0778adbf » Tony Cook
2006-03-22 More iolayers work:
519 #include "iolayert.h"
92bda632 » Tony Cook
2006-01-10 - start of external Imager API access:
520
02d1d628 » Arnar Mar Hrafnkelsson
2001-03-25 Initial revision
521 #endif
522
Something went wrong with that request. Please try again.