Commit | Line | Data |
---|---|---|
02d1d628 AMH |
1 | #ifndef _IMAGE_H_ |
2 | #define _IMAGE_H_ | |
3 | ||
e11d297f | 4 | #include "imconfig.h" |
7ac6a2e9 | 5 | #include "imio.h" |
02d1d628 AMH |
6 | #include "iolayer.h" |
7 | #include "log.h" | |
8 | #include "stackmach.h" | |
9 | ||
10 | ||
11 | #ifndef _MSC_VER | |
12 | #include <unistd.h> | |
13 | #endif | |
14 | #include <string.h> | |
15 | #include <stdio.h> | |
16 | #include <math.h> | |
17 | #include <stdlib.h> | |
18 | ||
19 | #ifdef SUNOS | |
20 | #include <strings.h> | |
21 | #endif | |
22 | ||
23 | #ifndef PI | |
24 | #define PI 3.14159265358979323846 | |
25 | #endif | |
26 | ||
27 | #ifndef MAXINT | |
28 | #define MAXINT 2147483647 | |
29 | #endif | |
30 | ||
31 | #include "datatypes.h" | |
32 | ||
33 | undef_int i_has_format(char *frmt); | |
34 | ||
35 | /* constructors and destructors */ | |
36 | ||
37 | i_color *ICL_new_internal( unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
38 | i_color *ICL_set_internal(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
39 | void ICL_info (i_color *cl); | |
40 | void ICL_DESTROY (i_color *cl); | |
41 | void ICL_add (i_color *dst, i_color *src, int ch); | |
42 | ||
faa9b3e7 TC |
43 | extern i_fcolor *i_fcolor_new(double r, double g, double b, double a); |
44 | extern void i_fcolor_destroy(i_fcolor *cl); | |
45 | ||
6607600c TC |
46 | extern void i_rgb_to_hsvf(i_fcolor *color); |
47 | extern void i_hsv_to_rgbf(i_fcolor *color); | |
efdc2568 TC |
48 | extern void i_rgb_to_hsv(i_color *color); |
49 | extern void i_hsv_to_rgb(i_color *color); | |
6607600c | 50 | |
02d1d628 AMH |
51 | i_img *IIM_new(int x,int y,int ch); |
52 | void IIM_DESTROY(i_img *im); | |
53 | i_img *i_img_new( void ); | |
54 | i_img *i_img_empty(i_img *im,int x,int y); | |
55 | i_img *i_img_empty_ch(i_img *im,int x,int y,int ch); | |
56 | void i_img_exorcise(i_img *im); | |
57 | void i_img_destroy(i_img *im); | |
58 | ||
59 | void i_img_info(i_img *im,int *info); | |
60 | ||
faa9b3e7 | 61 | extern i_img *i_sametype(i_img *im, int xsize, int ysize); |
dff75dee | 62 | extern i_img *i_sametype_chans(i_img *im, int xsize, int ysize, int channels); |
faa9b3e7 TC |
63 | |
64 | i_img *i_img_pal_new(int x, int y, int ch, int maxpal); | |
65 | ||
02d1d628 AMH |
66 | /* Image feature settings */ |
67 | ||
68 | void i_img_setmask (i_img *im,int ch_mask); | |
69 | int i_img_getmask (i_img *im); | |
70 | int i_img_getchannels(i_img *im); | |
71 | ||
72 | /* Base functions */ | |
73 | ||
da1c841c | 74 | #if 0 |
02d1d628 AMH |
75 | int i_ppix(i_img *im,int x,int y,i_color *val); |
76 | int i_gpix(i_img *im,int x,int y,i_color *val); | |
faa9b3e7 TC |
77 | int i_ppixf(i_img *im,int x,int y,i_color *val); |
78 | int i_gpixf(i_img *im,int x,int y,i_color *val); | |
da1c841c | 79 | #endif |
02d1d628 | 80 | |
faa9b3e7 TC |
81 | #define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val))) |
82 | #define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val))) | |
83 | #define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val))) | |
84 | #define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val))) | |
85 | ||
86 | #if 0 | |
02d1d628 AMH |
87 | int i_ppix_d(i_img *im,int x,int y,i_color *val); |
88 | int i_gpix_d(i_img *im,int x,int y,i_color *val); | |
f261c328 TC |
89 | int i_plin_d(i_img *im,int l, int r, int y, i_color *val); |
90 | int i_glin_d(i_img *im,int l, int r, int y, i_color *val); | |
faa9b3e7 | 91 | #endif |
f261c328 TC |
92 | |
93 | #define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val)) | |
94 | #define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val)) | |
faa9b3e7 TC |
95 | #define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val)) |
96 | #define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val)) | |
97 | ||
98 | #define i_gsamp(im, l, r, y, samps, chans, count) \ | |
99 | (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count))) | |
100 | #define i_gsampf(im, l, r, y, samps, chans, count) \ | |
101 | (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count))) | |
102 | ||
da1c841c AMH |
103 | #define i_psamp(im, l, r, y, samps, chans, count) \ |
104 | (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count))) | |
105 | #define i_psampf(im, l, r, y, samps, chans, count) \ | |
106 | (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count))) | |
107 | ||
108 | ||
109 | ||
110 | ||
faa9b3e7 TC |
111 | #define i_findcolor(im, color, entry) \ |
112 | (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0) | |
113 | ||
114 | #define i_gpal(im, l, r, y, vals) \ | |
115 | (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0) | |
116 | #define i_ppal(im, l, r, y, vals) \ | |
117 | (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0) | |
118 | #define i_addcolors(im, colors, count) \ | |
261f91c5 | 119 | (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1) |
faa9b3e7 TC |
120 | #define i_getcolors(im, index, color, count) \ |
121 | (((im)->i_f_getcolors) ? \ | |
122 | ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0) | |
123 | #define i_setcolors(im, index, color, count) \ | |
124 | (((im)->i_f_setcolors) ? \ | |
125 | ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0) | |
126 | #define i_colorcount(im) \ | |
127 | (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1) | |
128 | #define i_maxcolors(im) \ | |
129 | (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1) | |
130 | #define i_findcolor(im, color, entry) \ | |
131 | (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0) | |
132 | ||
133 | #define i_img_virtual(im) ((im)->virtual) | |
134 | #define i_img_type(im) ((im)->type) | |
135 | #define i_img_bits(im) ((im)->bits) | |
02d1d628 | 136 | |
f1ac5027 TC |
137 | /* Generic fills */ |
138 | struct i_fill_tag; | |
139 | ||
140 | typedef void (*i_fill_with_color_f) | |
141 | (struct i_fill_tag *fill, int x, int y, int width, int channels, | |
43c5dacb | 142 | i_color *data); |
f1ac5027 TC |
143 | typedef void (*i_fill_with_fcolor_f) |
144 | (struct i_fill_tag *fill, int x, int y, int width, int channels, | |
43c5dacb | 145 | i_fcolor *data); |
f1ac5027 | 146 | typedef void (*i_fill_destroy_f)(struct i_fill_tag *fill); |
efdc2568 TC |
147 | typedef void (*i_fill_combine_f)(i_color *out, i_color *in, int channels, |
148 | int count); | |
149 | typedef void (*i_fill_combinef_f)(i_fcolor *out, i_fcolor *in, int channels, | |
150 | int count); | |
151 | ||
f1ac5027 TC |
152 | |
153 | typedef struct i_fill_tag | |
154 | { | |
155 | /* called for 8-bit/sample image (and maybe lower) */ | |
156 | /* this may be NULL, if so call fill_with_fcolor */ | |
157 | i_fill_with_color_f fill_with_color; | |
158 | ||
159 | /* called for other sample sizes */ | |
160 | /* this must be non-NULL */ | |
161 | i_fill_with_fcolor_f fill_with_fcolor; | |
162 | ||
163 | /* called if non-NULL to release any extra resources */ | |
164 | i_fill_destroy_f destroy; | |
165 | ||
166 | /* if non-zero the caller will fill data with the original data | |
167 | from the image */ | |
efdc2568 TC |
168 | i_fill_combine_f combine; |
169 | i_fill_combinef_f combinef; | |
f1ac5027 TC |
170 | } i_fill_t; |
171 | ||
efdc2568 TC |
172 | typedef enum { |
173 | ic_none, | |
174 | ic_normal, | |
175 | ic_multiply, | |
176 | ic_dissolve, | |
177 | ic_add, | |
178 | ic_subtract, | |
179 | ic_diff, | |
180 | ic_lighten, | |
181 | ic_darken, | |
182 | ic_hue, | |
183 | ic_sat, | |
184 | ic_value, | |
185 | ic_color | |
186 | } i_combine_t; | |
187 | ||
f1ac5027 TC |
188 | extern i_fill_t *i_new_fill_solidf(i_fcolor *c, int combine); |
189 | extern i_fill_t *i_new_fill_solid(i_color *c, int combine); | |
190 | extern i_fill_t * | |
191 | i_new_fill_hatch(i_color *fg, i_color *bg, int combine, int hatch, | |
192 | unsigned char *cust_hatch, int dx, int dy); | |
193 | extern i_fill_t * | |
194 | i_new_fill_hatchf(i_fcolor *fg, i_fcolor *bg, int combine, int hatch, | |
195 | unsigned char *cust_hatch, int dx, int dy); | |
f576ce7e TC |
196 | extern i_fill_t * |
197 | i_new_fill_image(i_img *im, double *matrix, int xoff, int yoff, int combine); | |
f1ac5027 TC |
198 | extern void i_fill_destroy(i_fill_t *fill); |
199 | ||
02d1d628 AMH |
200 | float i_gpix_pch(i_img *im,int x,int y,int ch); |
201 | ||
202 | /* functions for drawing primitives */ | |
203 | ||
204 | void i_box (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
205 | void i_box_filled (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
f1ac5027 | 206 | void i_box_cfill(i_img *im, int x1, int y1, int x2, int y2, i_fill_t *fill); |
aa833c97 | 207 | void i_line (i_img *im,int x1,int y1,int x2,int y2,i_color *val, int endp); |
b437ce0a | 208 | void i_line_aa (i_img *im,int x1,int y1,int x2,int y2,i_color *val, int endp); |
02d1d628 | 209 | void i_arc (i_img *im,int x,int y,float rad,float d1,float d2,i_color *val); |
f1ac5027 | 210 | void i_arc_cfill(i_img *im,int x,int y,float rad,float d1,float d2,i_fill_t *fill); |
6af18d2b | 211 | void i_circle_aa (i_img *im,float x, float y,float rad,i_color *val); |
02d1d628 AMH |
212 | void i_copyto (i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty); |
213 | void i_copyto_trans(i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty,i_color *trans); | |
214 | void i_copy (i_img *im,i_img *src); | |
71dc4a83 AMH |
215 | int i_rubthru (i_img *im, i_img *src, int tx, int ty, int src_minx, int src_miny, int src_maxx, int src_maxy); |
216 | ||
02d1d628 | 217 | |
142c26ff | 218 | undef_int i_flipxy (i_img *im, int direction); |
faa9b3e7 TC |
219 | extern i_img *i_rotate90(i_img *im, int degrees); |
220 | extern i_img *i_rotate_exact(i_img *im, double amount); | |
0d3b936e | 221 | extern i_img *i_rotate_exact_bg(i_img *im, double amount, i_color *backp, i_fcolor *fbackp); |
faa9b3e7 | 222 | extern i_img *i_matrix_transform(i_img *im, int xsize, int ysize, double *matrix); |
0d3b936e | 223 | extern i_img *i_matrix_transform_bg(i_img *im, int xsize, int ysize, double *matrix, i_color *backp, i_fcolor *fbackp); |
142c26ff | 224 | |
02d1d628 AMH |
225 | void i_bezier_multi(i_img *im,int l,double *x,double *y,i_color *val); |
226 | void i_poly_aa (i_img *im,int l,double *x,double *y,i_color *val); | |
43c5dacb | 227 | void i_poly_aa_cfill(i_img *im,int l,double *x,double *y,i_fill_t *fill); |
02d1d628 | 228 | |
a321d497 AMH |
229 | undef_int i_flood_fill (i_img *im,int seedx,int seedy,i_color *dcol); |
230 | undef_int i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill); | |
231 | ||
02d1d628 AMH |
232 | |
233 | /* image processing functions */ | |
234 | ||
235 | void i_gaussian (i_img *im,float stdev); | |
236 | void i_conv (i_img *im,float *coeff,int len); | |
b6381851 | 237 | void i_unsharp_mask(i_img *im, double stddev, double scale); |
02d1d628 | 238 | |
f5991c03 TC |
239 | /* colour manipulation */ |
240 | extern int i_convert(i_img *im, i_img *src, float *coeff, int outchan, int inchan); | |
faa9b3e7 | 241 | extern void i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask); |
f5991c03 | 242 | |
02d1d628 AMH |
243 | float i_img_diff (i_img *im1,i_img *im2); |
244 | ||
245 | /* font routines */ | |
246 | ||
4cb58f1b | 247 | undef_int i_init_fonts( int t1log ); |
02d1d628 | 248 | |
3e882362 TC |
249 | /* |
250 | describes an axis of a MM font. | |
251 | Modelled on FT2's FT_MM_Axis. | |
252 | It would be nice to have a default entry too, but FT2 | |
253 | doesn't support it. | |
254 | */ | |
255 | typedef struct i_font_mm_axis_tag { | |
256 | char const *name; | |
257 | int minimum; | |
258 | int maximum; | |
259 | } i_font_mm_axis; | |
260 | ||
261 | #define IM_FONT_MM_MAX_AXES 4 | |
262 | ||
263 | /* | |
264 | multiple master information for a font, if any | |
265 | modelled on FT2's FT_Multi_Master. | |
266 | */ | |
267 | typedef struct i_font_mm_tag { | |
268 | int num_axis; | |
269 | int num_designs; /* provided but not necessarily useful */ | |
270 | i_font_mm_axis axis[IM_FONT_MM_MAX_AXES]; | |
271 | } i_font_mm; | |
272 | ||
02d1d628 AMH |
273 | #ifdef HAVE_LIBT1 |
274 | #include <t1lib.h> | |
275 | ||
b33c08f8 | 276 | undef_int i_init_t1( int t1log ); |
02d1d628 AMH |
277 | int i_t1_new( char *pfb, char *afm ); |
278 | int i_t1_destroy( int font_id ); | |
1bd75e4c TC |
279 | undef_int i_t1_cp( i_img *im, int xb, int yb, int channel, int fontnum, float points, char* str, int len, int align, int utf8, char const *flags ); |
280 | undef_int i_t1_text( i_img *im, int xb, int yb, i_color *cl, int fontnum, float points, char* str, int len, int align, int utf8, char const *flags ); | |
3799c4d1 | 281 | int i_t1_bbox( int fontnum, float point, char *str, int len, int cords[6], int utf8, char const *flags ); |
02d1d628 AMH |
282 | void i_t1_set_aa( int st ); |
283 | void close_t1( void ); | |
3799c4d1 TC |
284 | int i_t1_has_chars(int font_num, char const *text, int len, int utf8, char *out); |
285 | extern int i_t1_face_name(int font_num, char *name_buf, size_t name_buf_size); | |
286 | extern int i_t1_glyph_name(int font_num, unsigned long ch, char *name_buf, | |
287 | size_t name_buf_size); | |
02d1d628 AMH |
288 | #endif |
289 | ||
290 | #ifdef HAVE_LIBTT | |
291 | ||
4f68b48f | 292 | struct TT_Fonthandle_; |
02d1d628 AMH |
293 | |
294 | typedef struct TT_Fonthandle_ TT_Fonthandle; | |
295 | ||
b33c08f8 | 296 | undef_int i_init_tt( void ); |
02d1d628 AMH |
297 | TT_Fonthandle* i_tt_new(char *fontname); |
298 | void i_tt_destroy( TT_Fonthandle *handle ); | |
9ab6338b TC |
299 | undef_int i_tt_cp( TT_Fonthandle *handle,i_img *im,int xb,int yb,int channel,float points,char const* txt,int len,int smooth, int utf8, int align); |
300 | undef_int i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char const* txt, int len, int smooth, int utf8, int align); | |
4f68b48f | 301 | undef_int i_tt_bbox( TT_Fonthandle *handle, float points,char *txt,int len,int cords[6], int utf8); |
eeaa33fd | 302 | int i_tt_has_chars(TT_Fonthandle *handle, char const *text, int len, int utf8, char *out); |
3799c4d1 TC |
303 | void i_tt_dump_names(TT_Fonthandle *handle); |
304 | int i_tt_face_name(TT_Fonthandle *handle, char *name_buf, | |
305 | size_t name_buf_size); | |
306 | int i_tt_glyph_name(TT_Fonthandle *handle, unsigned long ch, char *name_buf, | |
307 | size_t name_buf_size); | |
02d1d628 AMH |
308 | |
309 | #endif /* End of freetype headers */ | |
310 | ||
faa9b3e7 TC |
311 | #ifdef HAVE_FT2 |
312 | ||
313 | typedef struct FT2_Fonthandle FT2_Fonthandle; | |
314 | extern int i_ft2_init(void); | |
315 | extern FT2_Fonthandle * i_ft2_new(char *name, int index); | |
316 | extern void i_ft2_destroy(FT2_Fonthandle *handle); | |
317 | extern int i_ft2_setdpi(FT2_Fonthandle *handle, int xdpi, int ydpi); | |
318 | extern int i_ft2_getdpi(FT2_Fonthandle *handle, int *xdpi, int *ydpi); | |
319 | extern int i_ft2_settransform(FT2_Fonthandle *handle, double *matrix); | |
320 | extern int i_ft2_sethinting(FT2_Fonthandle *handle, int hinting); | |
321 | extern int i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth, | |
4f68b48f | 322 | char const *text, int len, int *bbox, int utf8); |
5973b414 TC |
323 | extern int i_ft2_bbox_r(FT2_Fonthandle *handle, double cheight, double cwidth, |
324 | char const *text, int len, int vlayout, int utf8, int *bbox); | |
faa9b3e7 TC |
325 | extern int i_ft2_text(FT2_Fonthandle *handle, i_img *im, int tx, int ty, |
326 | i_color *cl, double cheight, double cwidth, | |
4f68b48f TC |
327 | char const *text, int len, int align, int aa, |
328 | int vlayout, int utf8); | |
faa9b3e7 TC |
329 | extern int i_ft2_cp(FT2_Fonthandle *handle, i_img *im, int tx, int ty, |
330 | int channel, double cheight, double cwidth, | |
4f68b48f | 331 | char const *text, int len, int align, int aa, int vlayout, |
faa9b3e7 | 332 | int utf8); |
4f68b48f | 333 | extern int i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, int len, |
3dec2c92 | 334 | int utf8, char *work); |
3799c4d1 TC |
335 | extern int i_ft2_face_name(FT2_Fonthandle *handle, char *name_buf, |
336 | size_t name_buf_size); | |
042cdaea | 337 | extern int i_ft2_can_face_name(void); |
a4168bea TC |
338 | extern int i_ft2_glyph_name(FT2_Fonthandle *handle, unsigned long ch, |
339 | char *name_buf, size_t name_buf_size, | |
340 | int reliable_only); | |
3799c4d1 TC |
341 | extern int i_ft2_can_do_glyph_names(void); |
342 | extern int i_ft2_face_has_glyph_names(FT2_Fonthandle *handle); | |
02d1d628 | 343 | |
3e882362 TC |
344 | extern int i_ft2_get_multiple_masters(FT2_Fonthandle *handle, |
345 | i_font_mm *mm); | |
346 | extern int | |
347 | i_ft2_is_multiple_master(FT2_Fonthandle *handle); | |
348 | extern int | |
349 | i_ft2_set_mm_coords(FT2_Fonthandle *handle, int coord_count, long *coords); | |
faa9b3e7 | 350 | #endif |
02d1d628 | 351 | |
faa9b3e7 | 352 | #ifdef WIN32 |
02d1d628 | 353 | |
faa9b3e7 TC |
354 | extern int i_wf_bbox(char *face, int size, char *text, int length, int *bbox); |
355 | extern int i_wf_text(char *face, i_img *im, int tx, int ty, i_color *cl, | |
356 | int size, char *text, int len, int align, int aa); | |
357 | extern int i_wf_cp(char *face, i_img *im, int tx, int ty, int channel, | |
358 | int size, char *text, int len, int align, int aa); | |
8457948a | 359 | extern int i_wf_addfont(char const *file); |
02d1d628 | 360 | |
faa9b3e7 | 361 | #endif |
02d1d628 AMH |
362 | |
363 | /* functions for reading and writing formats */ | |
364 | ||
365 | /* general reader callback | |
366 | userdata - data the user passed into the reader | |
367 | buffer - the buffer to fill with data | |
368 | need - the amount of data needed | |
369 | want - the amount of space we have to store data | |
370 | fill buffer and return the number of bytes read, 0 for eof, -1 for error | |
371 | */ | |
372 | ||
373 | typedef int (*i_read_callback_t)(char *userdata, char *buffer, int need, | |
374 | int want); | |
375 | ||
376 | /* i_gen_reader() translates the low-level requests from whatever library | |
377 | into buffered requests. | |
378 | but the called function can always bypass buffering by only ever | |
379 | reading I<need> bytes. | |
380 | */ | |
381 | #define CBBUFSIZ 4096 | |
382 | ||
383 | typedef struct { | |
384 | i_read_callback_t cb; | |
385 | char *userdata; | |
386 | char buffer[CBBUFSIZ]; | |
387 | int length; | |
388 | int cpos; | |
389 | } i_gen_read_data; | |
390 | ||
391 | extern int i_gen_reader(i_gen_read_data *info, char *buffer, int need); | |
392 | extern i_gen_read_data *i_gen_read_data_new(i_read_callback_t cb, char *userdata); | |
b33c08f8 | 393 | extern void i_free_gen_read_data(i_gen_read_data *); |
02d1d628 AMH |
394 | |
395 | /* general writer callback | |
396 | userdata - the data the user passed into the writer | |
397 | data - the data to write | |
398 | data_size - the number of bytes to write | |
399 | write the data, return non-zero on success, zero on failure. | |
400 | */ | |
401 | typedef int (*i_write_callback_t)(char *userdata, char const *data, int size); | |
402 | ||
403 | typedef struct { | |
404 | i_write_callback_t cb; | |
405 | char *userdata; | |
406 | char buffer[CBBUFSIZ]; | |
407 | int maxlength; | |
408 | int filledto; | |
409 | } i_gen_write_data; | |
410 | ||
411 | extern int i_gen_writer(i_gen_write_data *info, char const *data, int size); | |
412 | extern i_gen_write_data *i_gen_write_data_new(i_write_callback_t cb, char *userdata, int maxlength); | |
b33c08f8 | 413 | extern int i_free_gen_write_data(i_gen_write_data *, int flush); |
02d1d628 AMH |
414 | |
415 | /* transparency handling for quantized output */ | |
416 | typedef enum i_transp_tag { | |
417 | tr_none, /* ignore any alpha channel */ | |
418 | tr_threshold, /* threshold the transparency - uses tr_threshold */ | |
419 | tr_errdiff, /* error diffusion */ | |
420 | tr_ordered /* an ordered dither */ | |
421 | } i_transp; | |
422 | ||
423 | /* controls how we build the colour map */ | |
424 | typedef enum i_make_colors_tag { | |
425 | mc_none, /* user supplied colour map only */ | |
426 | mc_web_map, /* Use the 216 colour web colour map */ | |
427 | mc_addi, /* Addi's algorithm */ | |
97c4effc | 428 | mc_median_cut, /* median cut - similar to giflib, hopefully */ |
02d1d628 AMH |
429 | mc_mask = 0xFF /* (mask for generator) */ |
430 | } i_make_colors; | |
431 | ||
432 | /* controls how we translate the colours */ | |
433 | typedef enum i_translate_tag { | |
434 | pt_giflib, /* get gif lib to do it (ignores make_colours) */ | |
435 | pt_closest, /* just use the closest match within the hashbox */ | |
436 | pt_perturb, /* randomly perturb the data - uses perturb_size*/ | |
437 | pt_errdiff /* error diffusion dither - uses errdiff */ | |
438 | } i_translate; | |
439 | ||
440 | /* Which error diffusion map to use */ | |
441 | typedef enum i_errdiff_tag { | |
442 | ed_floyd, /* floyd-steinberg */ | |
443 | ed_jarvis, /* Jarvis, Judice and Ninke */ | |
444 | ed_stucki, /* Stucki */ | |
445 | ed_custom, /* the map found in ed_map|width|height|orig */ | |
446 | ed_mask = 0xFF, /* mask to get the map */ | |
447 | ed_bidir = 0x100 /* change direction for each row */ | |
448 | } i_errdiff; | |
449 | ||
450 | /* which ordered dither map to use | |
451 | currently only available for transparency | |
452 | I don't know of a way to do ordered dither of an image against some | |
453 | general palette | |
454 | */ | |
455 | typedef enum i_ord_dith_tag | |
456 | { | |
457 | od_random, /* sort of random */ | |
458 | od_dot8, /* large dot */ | |
459 | od_dot4, | |
460 | od_hline, | |
461 | od_vline, | |
462 | od_slashline, /* / line dither */ | |
463 | od_backline, /* \ line dither */ | |
34ba4c5b | 464 | od_tiny, /* small checkerbox */ |
02d1d628 AMH |
465 | od_custom /* custom 8x8 map */ |
466 | } i_ord_dith; | |
467 | ||
468 | typedef struct i_gif_pos_tag { | |
469 | int x, y; | |
470 | } i_gif_pos; | |
471 | ||
472 | /* passed into i_writegif_gen() to control quantization */ | |
473 | typedef struct i_quantize_tag { | |
474 | /* how to handle transparency */ | |
475 | i_transp transp; | |
476 | /* the threshold at which to make pixels opaque */ | |
477 | int tr_threshold; | |
478 | i_errdiff tr_errdiff; | |
479 | i_ord_dith tr_orddith; | |
480 | unsigned char tr_custom[64]; | |
481 | ||
482 | /* how to make the colour map */ | |
483 | i_make_colors make_colors; | |
484 | ||
485 | /* any existing colours | |
486 | mc_existing is an existing colour table | |
487 | mc_count is the number of existing colours | |
488 | mc_size is the total size of the array that mc_existing points | |
489 | at - this must be at least 256 | |
490 | */ | |
491 | i_color *mc_colors; | |
492 | int mc_size; | |
493 | int mc_count; | |
494 | ||
495 | /* how we translate the colours */ | |
496 | i_translate translate; | |
497 | ||
498 | /* the error diffusion map to use if translate is mc_errdiff */ | |
499 | i_errdiff errdiff; | |
500 | /* the following define the error diffusion values to use if | |
501 | errdiff is ed_custom. ed_orig is the column on the top row that | |
502 | represents the current | |
503 | */ | |
504 | int *ed_map; | |
505 | int ed_width, ed_height, ed_orig; | |
506 | ||
507 | /* the amount of perturbation to use for translate is mc_perturb */ | |
508 | int perturb; | |
509 | } i_quantize; | |
510 | ||
511 | typedef struct i_gif_opts { | |
512 | /* each image has a local color map */ | |
513 | int each_palette; | |
514 | ||
515 | /* images are interlaced */ | |
516 | int interlace; | |
517 | ||
518 | /* time for which image is displayed | |
519 | (in 1/100 seconds) | |
520 | default: 0 | |
521 | */ | |
522 | int delay_count; | |
523 | int *delays; | |
524 | ||
525 | /* user input flags | |
526 | default: 0 | |
527 | */ | |
528 | int user_input_count; | |
529 | char *user_input_flags; | |
530 | ||
531 | /* disposal | |
532 | default: 0 */ | |
533 | int disposal_count; | |
534 | char *disposal; | |
535 | ||
536 | /* this is added to the color table when we make an image transparent */ | |
537 | i_color tran_color; | |
538 | ||
539 | /* image positions */ | |
540 | int position_count; | |
541 | i_gif_pos *positions; | |
542 | ||
543 | /* Netscape loop extension - number of loops */ | |
544 | int loop_count; | |
bf9dd17c TC |
545 | |
546 | /* should be eliminate unused colors? */ | |
547 | int eliminate_unused; | |
02d1d628 AMH |
548 | } i_gif_opts; |
549 | ||
550 | extern void quant_makemap(i_quantize *quant, i_img **imgs, int count); | |
551 | extern i_palidx *quant_translate(i_quantize *quant, i_img *img); | |
552 | extern void quant_transparent(i_quantize *quant, i_palidx *indices, i_img *img, i_palidx trans_index); | |
553 | ||
faa9b3e7 TC |
554 | extern i_img *i_img_pal_new(int x, int y, int channels, int maxpal); |
555 | extern i_img *i_img_pal_new_low(i_img *im, int x, int y, int channels, int maxpal); | |
556 | extern i_img *i_img_to_pal(i_img *src, i_quantize *quant); | |
557 | extern i_img *i_img_to_rgb(i_img *src); | |
558 | extern i_img *i_img_masked_new(i_img *targ, i_img *mask, int x, int y, | |
559 | int w, int h); | |
560 | extern i_img *i_img_16_new(int x, int y, int ch); | |
561 | extern i_img *i_img_16_new_low(i_img *im, int x, int y, int ch); | |
365ea842 TC |
562 | extern i_img *i_img_double_new(int x, int y, int ch); |
563 | extern i_img *i_img_double_new_low(i_img *im, int x, int y, int ch); | |
faa9b3e7 | 564 | |
e10bf46e AMH |
565 | |
566 | char * i_test_format_probe(io_glue *data, int length); | |
567 | ||
568 | ||
02d1d628 | 569 | #ifdef HAVE_LIBJPEG |
dd55acc8 AMH |
570 | i_img * |
571 | i_readjpeg_wiol(io_glue *ig, int length, char** iptc_itext, int *itlength); | |
572 | undef_int i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor); | |
02d1d628 AMH |
573 | #endif /* HAVE_LIBJPEG */ |
574 | ||
575 | #ifdef HAVE_LIBTIFF | |
04418ecc | 576 | i_img * i_readtiff_wiol(io_glue *ig, int length); |
10461f9a | 577 | i_img ** i_readtiff_multi_wiol(io_glue *ig, int length, int *count); |
02d1d628 | 578 | undef_int i_writetiff_wiol(i_img *im, io_glue *ig); |
10461f9a | 579 | undef_int i_writetiff_multi_wiol(io_glue *ig, i_img **imgs, int count); |
4c2d6970 | 580 | undef_int i_writetiff_wiol_faxable(i_img *im, io_glue *ig, int fine); |
10461f9a | 581 | undef_int i_writetiff_multi_wiol_faxable(io_glue *ig, i_img **imgs, int count, int fine); |
02d1d628 AMH |
582 | |
583 | #endif /* HAVE_LIBTIFF */ | |
584 | ||
585 | #ifdef HAVE_LIBPNG | |
04418ecc AMH |
586 | i_img *i_readpng_wiol(io_glue *ig, int length); |
587 | undef_int i_writepng_wiol(i_img *im, io_glue *ig); | |
02d1d628 AMH |
588 | #endif /* HAVE_LIBPNG */ |
589 | ||
590 | #ifdef HAVE_LIBGIF | |
faa9b3e7 | 591 | i_img *i_readgif(int fd, int **colour_table, int *colours); |
10461f9a | 592 | i_img *i_readgif_wiol(io_glue *ig, int **colour_table, int *colours); |
faa9b3e7 TC |
593 | i_img *i_readgif_scalar(char *data, int length, int **colour_table, int *colours); |
594 | i_img *i_readgif_callback(i_read_callback_t callback, char *userdata, int **colour_table, int *colours); | |
595 | extern i_img **i_readgif_multi(int fd, int *count); | |
596 | extern i_img **i_readgif_multi_scalar(char *data, int length, int *count); | |
597 | extern i_img **i_readgif_multi_callback(i_read_callback_t callback, char *userdata, int *count); | |
10461f9a | 598 | extern i_img **i_readgif_multi_wiol(io_glue *ig, int *count); |
02d1d628 AMH |
599 | undef_int i_writegif(i_img *im,int fd,int colors,int pixdev,int fixedlen,i_color fixed[]); |
600 | undef_int i_writegifmc(i_img *im,int fd,int colors); | |
601 | undef_int i_writegifex(i_img *im,int fd); | |
97c4effc TC |
602 | undef_int i_writegif_gen(i_quantize *quant, int fd, i_img **imgs, int count); |
603 | undef_int i_writegif_callback(i_quantize *quant, i_write_callback_t cb, char *userdata, int maxbuffer, i_img **imgs, int count); | |
604 | undef_int i_writegif_wiol(io_glue *ig, i_quantize *quant, | |
10461f9a | 605 | i_img **imgs, int count); |
02d1d628 AMH |
606 | void i_qdist(i_img *im); |
607 | ||
608 | #endif /* HAVE_LIBGIF */ | |
609 | ||
04418ecc | 610 | i_img * i_readraw_wiol(io_glue *ig, int x, int y, int datachannels, int storechannels, int intrl); |
895dbd34 | 611 | undef_int i_writeraw_wiol(i_img* im, io_glue *ig); |
02d1d628 | 612 | |
04418ecc | 613 | i_img * i_readpnm_wiol(io_glue *ig, int length); |
067d6bdc | 614 | undef_int i_writeppm_wiol(i_img *im, io_glue *ig); |
02d1d628 | 615 | |
1ec86afa | 616 | extern int i_writebmp_wiol(i_img *im, io_glue *ig); |
d08b8f85 | 617 | extern i_img *i_readbmp_wiol(io_glue *ig); |
02d1d628 | 618 | |
84e51293 AMH |
619 | int tga_header_verify(unsigned char headbuf[18]); |
620 | ||
1ec86afa | 621 | i_img * i_readtga_wiol(io_glue *ig, int length); |
febba01f | 622 | undef_int i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen); |
1ec86afa | 623 | |
737a830c AMH |
624 | i_img * i_readrgb_wiol(io_glue *ig, int length); |
625 | undef_int i_writergb_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen); | |
626 | ||
04418ecc AMH |
627 | i_img * i_scaleaxis(i_img *im, float Value, int Axis); |
628 | i_img * i_scale_nn(i_img *im, float scx, float scy); | |
629 | i_img * i_haar(i_img *im); | |
630 | int i_count_colors(i_img *im,int maxc); | |
02d1d628 | 631 | |
04418ecc | 632 | i_img * i_transform(i_img *im, int *opx,int opxl,int *opy,int opyl,double parm[],int parmlen); |
02d1d628 AMH |
633 | |
634 | struct rm_op; | |
04418ecc AMH |
635 | i_img * i_transform2(int width, int height, int channels, |
636 | struct rm_op *ops, int ops_count, | |
637 | double *n_regs, int n_regs_count, | |
638 | i_color *c_regs, int c_regs_count, | |
639 | i_img **in_imgs, int in_imgs_count); | |
febba01f | 640 | |
02d1d628 AMH |
641 | /* filters */ |
642 | ||
643 | void i_contrast(i_img *im, float intensity); | |
644 | void i_hardinvert(i_img *im); | |
645 | void i_noise(i_img *im, float amount, unsigned char type); | |
646 | void i_bumpmap(i_img *im,i_img *bump,int channel,int light_x,int light_y,int strength); | |
b2778574 AMH |
647 | void i_bumpmap_complex(i_img *im, i_img *bump, int channel, int tx, int ty, float Lx, float Ly, |
648 | float Lz, float cd, float cs, float n, i_color *Ia, i_color *Il, i_color *Is); | |
02d1d628 AMH |
649 | void i_postlevels(i_img *im,int levels); |
650 | void i_mosaic(i_img *im,int size); | |
651 | void i_watermark(i_img *im,i_img *wmark,int tx,int ty,int pixdiff); | |
652 | void i_autolevels(i_img *im,float lsat,float usat,float skew); | |
653 | void i_radnoise(i_img *im,int xo,int yo,float rscale,float ascale); | |
654 | void i_turbnoise(i_img *im,float xo,float yo,float scale); | |
655 | void i_gradgen(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure); | |
656 | void i_nearest_color(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure); | |
dff75dee | 657 | i_img *i_diff_image(i_img *im, i_img *im2, int mindist); |
6607600c TC |
658 | typedef enum { |
659 | i_fst_linear, | |
660 | i_fst_curved, | |
661 | i_fst_sine, | |
662 | i_fst_sphere_up, | |
663 | i_fst_sphere_down, | |
664 | i_fst_end | |
665 | } i_fountain_seg_type; | |
666 | typedef enum { | |
667 | i_fc_direct, | |
668 | i_fc_hue_up, | |
669 | i_fc_hue_down, | |
670 | i_fc_end | |
671 | } i_fountain_color; | |
672 | typedef struct { | |
673 | double start, middle, end; | |
674 | i_fcolor c[2]; | |
675 | i_fountain_seg_type type; | |
676 | i_fountain_color color; | |
677 | } i_fountain_seg; | |
678 | typedef enum { | |
679 | i_fr_none, | |
680 | i_fr_sawtooth, | |
681 | i_fr_triangle, | |
682 | i_fr_saw_both, | |
683 | i_fr_tri_both | |
684 | } i_fountain_repeat; | |
685 | typedef enum { | |
686 | i_ft_linear, | |
687 | i_ft_bilinear, | |
688 | i_ft_radial, | |
689 | i_ft_radial_square, | |
690 | i_ft_revolution, | |
691 | i_ft_conical, | |
692 | i_ft_end | |
693 | } i_fountain_type; | |
694 | typedef enum { | |
695 | i_fts_none, | |
696 | i_fts_grid, | |
697 | i_fts_random, | |
698 | i_fts_circle | |
699 | } i_ft_supersample; | |
700 | void i_fountain(i_img *im, double xa, double ya, double xb, double yb, | |
701 | i_fountain_type type, i_fountain_repeat repeat, | |
702 | int combine, int super_sample, double ssample_param, | |
703 | int count, i_fountain_seg *segs); | |
f1ac5027 TC |
704 | extern i_fill_t * |
705 | i_new_fill_fount(double xa, double ya, double xb, double yb, | |
706 | i_fountain_type type, i_fountain_repeat repeat, | |
707 | int combine, int super_sample, double ssample_param, | |
708 | int count, i_fountain_seg *segs); | |
02d1d628 AMH |
709 | |
710 | /* Debug only functions */ | |
711 | ||
712 | void malloc_state( void ); | |
713 | ||
714 | /* this is sort of obsolete now */ | |
715 | ||
716 | typedef struct { | |
717 | undef_int (*i_has_format)(char *frmt); | |
718 | i_color*(*ICL_set)(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
719 | void (*ICL_info)(i_color *cl); | |
720 | ||
721 | i_img*(*i_img_new)( void ); | |
722 | i_img*(*i_img_empty)(i_img *im,int x,int y); | |
723 | i_img*(*i_img_empty_ch)(i_img *im,int x,int y,int ch); | |
724 | void(*i_img_exorcise)(i_img *im); | |
725 | ||
726 | void(*i_img_info)(i_img *im,int *info); | |
727 | ||
728 | void(*i_img_setmask)(i_img *im,int ch_mask); | |
729 | int (*i_img_getmask)(i_img *im); | |
730 | ||
da1c841c | 731 | /* |
02d1d628 AMH |
732 | int (*i_ppix)(i_img *im,int x,int y,i_color *val); |
733 | int (*i_gpix)(i_img *im,int x,int y,i_color *val); | |
da1c841c | 734 | */ |
02d1d628 | 735 | void(*i_box)(i_img *im,int x1,int y1,int x2,int y2,i_color *val); |
aa833c97 | 736 | void(*i_line)(i_img *im,int x1,int y1,int x2,int y2,i_color *val,int endp); |
02d1d628 AMH |
737 | void(*i_arc)(i_img *im,int x,int y,float rad,float d1,float d2,i_color *val); |
738 | void(*i_copyto)(i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty); | |
739 | void(*i_copyto_trans)(i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty,i_color *trans); | |
faa9b3e7 | 740 | int(*i_rubthru)(i_img *im,i_img *src,int tx,int ty); |
02d1d628 AMH |
741 | |
742 | } symbol_table_t; | |
743 | ||
848ba81a TC |
744 | /* error handling |
745 | see error.c for documentation | |
746 | the error information is currently global | |
747 | */ | |
748 | typedef struct { | |
749 | char *msg; | |
750 | int code; | |
751 | } i_errmsg; | |
a743c0a6 | 752 | |
848ba81a TC |
753 | typedef void (*i_error_cb)(int code, char const *msg); |
754 | typedef void (*i_failed_cb)(i_errmsg *msgs); | |
755 | extern i_error_cb i_set_error_cb(i_error_cb); | |
756 | extern i_failed_cb i_set_failed_cb(i_failed_cb); | |
757 | extern void i_set_argv0(char const *); | |
758 | extern int i_set_errors_fatal(int new_fatal); | |
faa9b3e7 | 759 | extern i_errmsg *i_errors(void); |
848ba81a TC |
760 | |
761 | extern void i_push_error(int code, char const *msg); | |
762 | extern void i_push_errorf(int code, char const *fmt, ...); | |
763 | extern void i_push_errorvf(int code, char const *fmt, va_list); | |
faa9b3e7 | 764 | extern void i_clear_error(void); |
848ba81a | 765 | extern int i_failed(int code, char const *msg); |
02d1d628 | 766 | |
faa9b3e7 TC |
767 | /* image tag processing */ |
768 | extern void i_tags_new(i_img_tags *tags); | |
97c4effc TC |
769 | extern int i_tags_addn(i_img_tags *tags, char const *name, int code, |
770 | int idata); | |
771 | extern int i_tags_add(i_img_tags *tags, char const *name, int code, | |
772 | char const *data, int size, int idata); | |
faa9b3e7 | 773 | extern void i_tags_destroy(i_img_tags *tags); |
97c4effc TC |
774 | extern int i_tags_find(i_img_tags *tags, char const *name, int start, |
775 | int *entry); | |
faa9b3e7 TC |
776 | extern int i_tags_findn(i_img_tags *tags, int code, int start, int *entry); |
777 | extern int i_tags_delete(i_img_tags *tags, int entry); | |
97c4effc | 778 | extern int i_tags_delbyname(i_img_tags *tags, char const *name); |
faa9b3e7 | 779 | extern int i_tags_delbycode(i_img_tags *tags, int code); |
97c4effc | 780 | extern int i_tags_get_float(i_img_tags *tags, char const *name, int code, |
fd9a31d2 | 781 | double *value); |
97c4effc | 782 | extern int i_tags_set_float(i_img_tags *tags, char const *name, int code, |
fd9a31d2 | 783 | double value); |
2e41e30b TC |
784 | extern int i_tags_set_float2(i_img_tags *tags, char const *name, int code, |
785 | double value, int places); | |
97c4effc TC |
786 | extern int i_tags_get_int(i_img_tags *tags, char const *name, int code, |
787 | int *value); | |
788 | extern int i_tags_get_string(i_img_tags *tags, char const *name, int code, | |
fd9a31d2 | 789 | char *value, size_t value_size); |
97c4effc TC |
790 | extern int i_tags_get_color(i_img_tags *tags, char const *name, int code, |
791 | i_color *value); | |
792 | extern int i_tags_set_color(i_img_tags *tags, char const *name, int code, | |
793 | i_color const *value); | |
fd9a31d2 | 794 | extern void i_tags_print(i_img_tags *tags); |
02d1d628 AMH |
795 | |
796 | #endif |