- extra concept index entries
[imager.git] / datatypes.h
CommitLineData
02d1d628
AMH
1#ifndef _DATATYPES_H_
2#define _DATATYPES_H_
3
7ac6a2e9 4#include "imio.h"
02d1d628
AMH
5
6#define MAXCHANNELS 4
7
faa9b3e7
TC
8/* used for palette indices in some internal code (which might be
9 exposed at some point
10*/
11typedef unsigned char i_palidx;
12
13/* We handle 2 types of sample, this is hopefully the most common, and the
14 smaller of the ones we support */
15typedef unsigned char i_sample_t;
16
17typedef struct { i_sample_t gray_color; } gray_color;
18typedef struct { i_sample_t r,g,b; } rgb_color;
19typedef struct { i_sample_t r,g,b,a; } rgba_color;
20typedef struct { i_sample_t c,m,y,k; } cmyk_color;
02d1d628
AMH
21
22typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */
23
24typedef union {
25 gray_color gray;
26 rgb_color rgb;
27 rgba_color rgba;
28 cmyk_color cmyk;
faa9b3e7 29 i_sample_t channel[MAXCHANNELS];
02d1d628
AMH
30 unsigned int ui;
31} i_color;
32
faa9b3e7
TC
33/* this is the larger sample type, it should be able to accurately represent
34 any sample size we use */
35typedef double i_fsample_t;
02d1d628 36
faa9b3e7
TC
37typedef struct { i_fsample_t gray_color; } i_fgray_color_t;
38typedef struct { i_fsample_t r, g, b; } i_frgb_color_t;
39typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t;
40typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t;
41
42typedef union {
43 i_fgray_color_t gray;
44 i_frgb_color_t rgb;
45 i_frgba_color_t rgba;
46 i_fcmyk_color_t cmyk;
47 i_fsample_t channel[MAXCHANNELS];
48} i_fcolor;
49
50typedef enum {
51 i_direct_type, /* direct colour, keeps RGB values per pixel */
26fd367b 52 i_palette_type /* keeps a palette index per pixel */
faa9b3e7
TC
53} i_img_type_t;
54
55typedef enum {
56 /* bits per sample, not per pixel */
57 /* a paletted image might have one bit per sample */
58 i_8_bits = 8,
59 i_16_bits = 16,
26fd367b 60 i_double_bits = sizeof(double) * 8
faa9b3e7
TC
61} i_img_bits_t;
62
63typedef struct {
64 char *name; /* name of a given tag, might be NULL */
65 int code; /* number of a given tag, -1 if it has no meaning */
66 char *data; /* value of a given tag if it's not an int, may be NULL */
67 int size; /* size of the data */
68 int idata; /* value of a given tag if data is NULL */
69} i_img_tag;
70
71typedef struct {
72 int count; /* how many tags have been set */
73 int alloc; /* how many tags have been allocated for */
74 i_img_tag *tags;
75} i_img_tags;
76
77typedef struct i_img_ i_img;
78typedef int (*i_f_ppix_t)(i_img *im, int x, int y, i_color *pix);
79typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, i_fcolor *pix);
80typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, i_color *vals);
81typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
82typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix);
83typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix);
84typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals);
85typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals);
86
87typedef int (*i_f_gsamp_t)(i_img *im, int x, int r, int y, i_sample_t *samp,
18accb2a 88 const int *chans, int chan_count);
faa9b3e7 89typedef int (*i_f_gsampf_t)(i_img *im, int x, int r, int y, i_fsample_t *samp,
18accb2a 90 const int *chan, int chan_count);
faa9b3e7
TC
91
92typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
93typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, i_palidx *vals);
94typedef int (*i_f_addcolors_t)(i_img *im, i_color *colors, int count);
95typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count);
96typedef int (*i_f_colorcount_t)(i_img *im);
97typedef int (*i_f_maxcolors_t)(i_img *im);
98typedef int (*i_f_findcolor_t)(i_img *im, i_color *color, i_palidx *entry);
99typedef int (*i_f_setcolors_t)(i_img *im, int index, i_color *colors,
100 int count);
101
102typedef void (*i_f_destroy_t)(i_img *im);
103
104struct i_img_ {
02d1d628
AMH
105 int channels;
106 int xsize,ysize,bytes;
02d1d628 107 unsigned int ch_mask;
faa9b3e7
TC
108 i_img_bits_t bits;
109 i_img_type_t type;
110 int virtual; /* image might not keep any data, must use functions */
111 unsigned char *idata; /* renamed to force inspection of existing code */
112 /* can be NULL if virtual is non-zero */
113 i_img_tags tags;
02d1d628 114
02d1d628 115 void *ext_data;
02d1d628 116
faa9b3e7
TC
117 /* interface functions */
118 i_f_ppix_t i_f_ppix;
119 i_f_ppixf_t i_f_ppixf;
120 i_f_plin_t i_f_plin;
121 i_f_plinf_t i_f_plinf;
122 i_f_gpix_t i_f_gpix;
123 i_f_gpixf_t i_f_gpixf;
124 i_f_glin_t i_f_glin;
125 i_f_glinf_t i_f_glinf;
126 i_f_gsamp_t i_f_gsamp;
127 i_f_gsampf_t i_f_gsampf;
128
129 /* only valid for type == i_palette_type */
130 i_f_gpal_t i_f_gpal;
131 i_f_ppal_t i_f_ppal;
132 i_f_addcolors_t i_f_addcolors;
133 i_f_getcolors_t i_f_getcolors;
134 i_f_colorcount_t i_f_colorcount;
135 i_f_maxcolors_t i_f_maxcolors;
136 i_f_findcolor_t i_f_findcolor;
137 i_f_setcolors_t i_f_setcolors;
138
139 i_f_destroy_t i_f_destroy;
140};
02d1d628 141
faa9b3e7
TC
142/* ext_data for paletted images
143 */
144typedef struct {
145 int count; /* amount of space used in palette (in entries) */
146 int alloc; /* amount of space allocated for palette (in entries) */
147 i_color *pal;
148 int last_found;
149} i_img_pal_ext;
02d1d628 150
faa9b3e7 151/* Helper datatypes
02d1d628
AMH
152 The types in here so far are:
153
154 doubly linked bucket list - pretty efficient
155 octtree - no idea about goodness
156
157 needed: hashes.
158
159*/
160
161
162
163
164
165/* bitmap mask */
166
167struct i_bitmap {
168 int xsize,ysize;
169 char *data;
170};
171
172struct i_bitmap* btm_new(int xsize,int ysize);
173void btm_destroy(struct i_bitmap *btm);
174int btm_test(struct i_bitmap *btm,int x,int y);
175void btm_set(struct i_bitmap *btm,int x,int y);
176
177
178
179
180
181
182
183
184/* Stack/Linked list */
185
186struct llink {
187 struct llink *p,*n;
188 void *data;
189 int fill; /* Number used in this link */
190};
191
192struct llist {
193 struct llink *h,*t;
194 int multip; /* # of copies in a single chain */
195 int ssize; /* size of each small element */
196 int count; /* number of elements on the list */
197};
198
199
200/* Links */
201
202struct llink *llink_new( struct llink* p,int size );
203int llist_llink_push( struct llist *lst, struct llink *lnk, void *data );
204
205/* Lists */
206
207struct llist *llist_new( int multip, int ssize );
208void llist_destroy( struct llist *l );
209void llist_push( struct llist *l, void *data );
210void llist_dump( struct llist *l );
211int llist_pop( struct llist *l,void *data );
212
213
214
215
216/* Octtree */
217
218struct octt {
219 struct octt *t[8];
220 int cnt;
221};
222
faa9b3e7 223struct octt *octt_new(void);
02d1d628
AMH
224int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b);
225void octt_dump(struct octt *ct);
226void octt_count(struct octt *ct,int *tot,int max,int *overflow);
227void octt_delete(struct octt *ct);
228
3799c4d1
TC
229/* font bounding box results */
230enum bounding_box_index_t {
231 BBOX_NEG_WIDTH,
232 BBOX_GLOBAL_DESCENT,
233 BBOX_POS_WIDTH,
234 BBOX_GLOBAL_ASCENT,
235 BBOX_DESCENT,
236 BBOX_ASCENT,
237 BBOX_ADVANCE_WIDTH,
dc35bde9 238 BBOX_RIGHT_BEARING,
3799c4d1
TC
239 BOUNDING_BOX_COUNT
240};
241
02d1d628
AMH
242#endif
243