Commit | Line | Data |
---|---|---|
02d1d628 AMH |
1 | #ifndef _DATATYPES_H_ |
2 | #define _DATATYPES_H_ | |
3 | ||
4 | #include "io.h" | |
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 | */ | |
11 | typedef 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 */ | |
15 | typedef unsigned char i_sample_t; | |
16 | ||
17 | typedef struct { i_sample_t gray_color; } gray_color; | |
18 | typedef struct { i_sample_t r,g,b; } rgb_color; | |
19 | typedef struct { i_sample_t r,g,b,a; } rgba_color; | |
20 | typedef struct { i_sample_t c,m,y,k; } cmyk_color; | |
02d1d628 AMH |
21 | |
22 | typedef int undef_int; /* special value to put in typemaps to retun undef on 0 and 1 on 1 */ | |
23 | ||
24 | typedef 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 */ | |
35 | typedef double i_fsample_t; | |
02d1d628 | 36 | |
faa9b3e7 TC |
37 | typedef struct { i_fsample_t gray_color; } i_fgray_color_t; |
38 | typedef struct { i_fsample_t r, g, b; } i_frgb_color_t; | |
39 | typedef struct { i_fsample_t r, g, b, a; } i_frgba_color_t; | |
40 | typedef struct { i_fsample_t c, m, y, k; } i_fcmyk_color_t; | |
41 | ||
42 | typedef 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 | ||
50 | typedef 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 | ||
55 | typedef 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 | ||
63 | typedef 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 | ||
71 | typedef 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 | ||
77 | typedef struct i_img_ i_img; | |
78 | typedef int (*i_f_ppix_t)(i_img *im, int x, int y, i_color *pix); | |
79 | typedef int (*i_f_ppixf_t)(i_img *im, int x, int y, i_fcolor *pix); | |
80 | typedef int (*i_f_plin_t)(i_img *im, int x, int r, int y, i_color *vals); | |
81 | typedef int (*i_f_plinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals); | |
82 | typedef int (*i_f_gpix_t)(i_img *im, int x, int y, i_color *pix); | |
83 | typedef int (*i_f_gpixf_t)(i_img *im, int x, int y, i_fcolor *pix); | |
84 | typedef int (*i_f_glin_t)(i_img *im, int x, int r, int y, i_color *vals); | |
85 | typedef int (*i_f_glinf_t)(i_img *im, int x, int r, int y, i_fcolor *vals); | |
86 | ||
87 | typedef 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 | 89 | typedef 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 | |
92 | typedef int (*i_f_gpal_t)(i_img *im, int x, int r, int y, i_palidx *vals); | |
93 | typedef int (*i_f_ppal_t)(i_img *im, int x, int r, int y, i_palidx *vals); | |
94 | typedef int (*i_f_addcolors_t)(i_img *im, i_color *colors, int count); | |
95 | typedef int (*i_f_getcolors_t)(i_img *im, int i, i_color *, int count); | |
96 | typedef int (*i_f_colorcount_t)(i_img *im); | |
97 | typedef int (*i_f_maxcolors_t)(i_img *im); | |
98 | typedef int (*i_f_findcolor_t)(i_img *im, i_color *color, i_palidx *entry); | |
99 | typedef int (*i_f_setcolors_t)(i_img *im, int index, i_color *colors, | |
100 | int count); | |
101 | ||
102 | typedef void (*i_f_destroy_t)(i_img *im); | |
103 | ||
104 | struct 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 | */ | |
144 | typedef 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 | ||
167 | struct i_bitmap { | |
168 | int xsize,ysize; | |
169 | char *data; | |
170 | }; | |
171 | ||
172 | struct i_bitmap* btm_new(int xsize,int ysize); | |
173 | void btm_destroy(struct i_bitmap *btm); | |
174 | int btm_test(struct i_bitmap *btm,int x,int y); | |
175 | void btm_set(struct i_bitmap *btm,int x,int y); | |
176 | ||
177 | ||
178 | ||
179 | ||
180 | ||
181 | ||
182 | ||
183 | ||
184 | /* Stack/Linked list */ | |
185 | ||
186 | struct llink { | |
187 | struct llink *p,*n; | |
188 | void *data; | |
189 | int fill; /* Number used in this link */ | |
190 | }; | |
191 | ||
192 | struct 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 | ||
202 | struct llink *llink_new( struct llink* p,int size ); | |
203 | int llist_llink_push( struct llist *lst, struct llink *lnk, void *data ); | |
204 | ||
205 | /* Lists */ | |
206 | ||
207 | struct llist *llist_new( int multip, int ssize ); | |
208 | void llist_destroy( struct llist *l ); | |
209 | void llist_push( struct llist *l, void *data ); | |
210 | void llist_dump( struct llist *l ); | |
211 | int llist_pop( struct llist *l,void *data ); | |
212 | ||
213 | ||
214 | ||
215 | ||
216 | /* Octtree */ | |
217 | ||
218 | struct octt { | |
219 | struct octt *t[8]; | |
220 | int cnt; | |
221 | }; | |
222 | ||
faa9b3e7 | 223 | struct octt *octt_new(void); |
02d1d628 AMH |
224 | int octt_add(struct octt *ct,unsigned char r,unsigned char g,unsigned char b); |
225 | void octt_dump(struct octt *ct); | |
226 | void octt_count(struct octt *ct,int *tot,int max,int *overflow); | |
227 | void octt_delete(struct octt *ct); | |
228 | ||
229 | #endif | |
230 |