Commit | Line | Data |
---|---|---|
02d1d628 AMH |
1 | #ifndef _IMAGE_H_ |
2 | #define _IMAGE_H_ | |
3 | ||
4 | #include "io.h" | |
5 | #include "iolayer.h" | |
6 | #include "log.h" | |
7 | #include "stackmach.h" | |
8 | ||
9 | ||
10 | #ifndef _MSC_VER | |
11 | #include <unistd.h> | |
12 | #endif | |
13 | #include <string.h> | |
14 | #include <stdio.h> | |
15 | #include <math.h> | |
16 | #include <stdlib.h> | |
17 | ||
18 | #ifdef SUNOS | |
19 | #include <strings.h> | |
20 | #endif | |
21 | ||
22 | #ifndef PI | |
23 | #define PI 3.14159265358979323846 | |
24 | #endif | |
25 | ||
26 | #ifndef MAXINT | |
27 | #define MAXINT 2147483647 | |
28 | #endif | |
29 | ||
30 | #include "datatypes.h" | |
31 | ||
32 | undef_int i_has_format(char *frmt); | |
33 | ||
34 | /* constructors and destructors */ | |
35 | ||
36 | i_color *ICL_new_internal( unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
37 | i_color *ICL_set_internal(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
38 | void ICL_info (i_color *cl); | |
39 | void ICL_DESTROY (i_color *cl); | |
40 | void ICL_add (i_color *dst, i_color *src, int ch); | |
41 | ||
42 | i_img *IIM_new(int x,int y,int ch); | |
43 | void IIM_DESTROY(i_img *im); | |
44 | i_img *i_img_new( void ); | |
45 | i_img *i_img_empty(i_img *im,int x,int y); | |
46 | i_img *i_img_empty_ch(i_img *im,int x,int y,int ch); | |
47 | void i_img_exorcise(i_img *im); | |
48 | void i_img_destroy(i_img *im); | |
49 | ||
50 | void i_img_info(i_img *im,int *info); | |
51 | ||
52 | /* Image feature settings */ | |
53 | ||
54 | void i_img_setmask (i_img *im,int ch_mask); | |
55 | int i_img_getmask (i_img *im); | |
56 | int i_img_getchannels(i_img *im); | |
57 | ||
58 | /* Base functions */ | |
59 | ||
60 | int i_ppix(i_img *im,int x,int y,i_color *val); | |
61 | int i_gpix(i_img *im,int x,int y,i_color *val); | |
62 | ||
63 | int i_ppix_d(i_img *im,int x,int y,i_color *val); | |
64 | int i_gpix_d(i_img *im,int x,int y,i_color *val); | |
65 | ||
66 | float i_gpix_pch(i_img *im,int x,int y,int ch); | |
67 | ||
68 | /* functions for drawing primitives */ | |
69 | ||
70 | void i_box (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
71 | void i_box_filled (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
72 | void i_draw (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
73 | void i_line_aa (i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
74 | void i_arc (i_img *im,int x,int y,float rad,float d1,float d2,i_color *val); | |
75 | void i_copyto (i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty); | |
76 | 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); | |
77 | void i_copy (i_img *im,i_img *src); | |
78 | void i_rubthru (i_img *im,i_img *src,int tx,int ty); | |
79 | ||
142c26ff AMH |
80 | undef_int i_flipxy (i_img *im, int direction); |
81 | ||
82 | ||
83 | ||
02d1d628 AMH |
84 | void i_bezier_multi(i_img *im,int l,double *x,double *y,i_color *val); |
85 | void i_poly_aa (i_img *im,int l,double *x,double *y,i_color *val); | |
86 | ||
87 | void i_flood_fill (i_img *im,int seedx,int seedy,i_color *dcol); | |
88 | ||
89 | /* image processing functions */ | |
90 | ||
91 | void i_gaussian (i_img *im,float stdev); | |
92 | void i_conv (i_img *im,float *coeff,int len); | |
93 | ||
94 | float i_img_diff (i_img *im1,i_img *im2); | |
95 | ||
96 | /* font routines */ | |
97 | ||
98 | undef_int i_init_fonts( void ); | |
99 | ||
100 | #ifdef HAVE_LIBT1 | |
101 | #include <t1lib.h> | |
102 | ||
103 | undef_int init_t1( void ); | |
104 | int i_t1_new( char *pfb, char *afm ); | |
105 | int i_t1_destroy( int font_id ); | |
106 | undef_int i_t1_cp( i_img *im, int xb, int yb, int channel, int fontnum, float points, char* str, int len, int align ); | |
107 | 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 ); | |
108 | void i_t1_bbox( int fontnum, float point, char *str, int len, int cords[6] ); | |
109 | void i_t1_set_aa( int st ); | |
110 | void close_t1( void ); | |
111 | ||
112 | #endif | |
113 | ||
114 | #ifdef HAVE_LIBTT | |
115 | ||
116 | #include <freetype.h> | |
117 | #define TT_CHC 5 | |
118 | ||
119 | struct TT_Instancehandle_ { | |
120 | TT_Instance instance; | |
121 | TT_Instance_Metrics imetrics; | |
122 | TT_Glyph_Metrics gmetrics[256]; | |
123 | TT_Glyph glyphs[256]; | |
124 | int smooth; | |
125 | int ptsize; | |
126 | int order; | |
127 | }; | |
128 | ||
129 | typedef struct TT_Instancehandle_ TT_Instancehandle; | |
130 | ||
131 | struct TT_Fonthandle_ { | |
132 | TT_Face face; | |
133 | TT_Face_Properties properties; | |
134 | TT_Instancehandle instanceh[TT_CHC]; | |
135 | TT_CharMap char_map; | |
136 | }; | |
137 | ||
138 | typedef struct TT_Fonthandle_ TT_Fonthandle; | |
139 | ||
140 | ||
141 | ||
142 | undef_int init_tt( void ); | |
143 | TT_Fonthandle* i_tt_new(char *fontname); | |
144 | void i_tt_destroy( TT_Fonthandle *handle ); | |
145 | undef_int i_tt_cp( TT_Fonthandle *handle,i_img *im,int xb,int yb,int channel,float points,char* txt,int len,int smooth); | |
146 | undef_int i_tt_text( TT_Fonthandle *handle, i_img *im, int xb, int yb, i_color *cl, float points, char* txt, int len, int smooth); | |
147 | undef_int i_tt_bbox( TT_Fonthandle *handle, float points,char *txt,int len,int cords[6]); | |
148 | ||
149 | ||
150 | #endif /* End of freetype headers */ | |
151 | ||
152 | ||
153 | ||
154 | ||
155 | ||
156 | ||
157 | ||
158 | /* functions for reading and writing formats */ | |
159 | ||
160 | /* general reader callback | |
161 | userdata - data the user passed into the reader | |
162 | buffer - the buffer to fill with data | |
163 | need - the amount of data needed | |
164 | want - the amount of space we have to store data | |
165 | fill buffer and return the number of bytes read, 0 for eof, -1 for error | |
166 | */ | |
167 | ||
168 | typedef int (*i_read_callback_t)(char *userdata, char *buffer, int need, | |
169 | int want); | |
170 | ||
171 | /* i_gen_reader() translates the low-level requests from whatever library | |
172 | into buffered requests. | |
173 | but the called function can always bypass buffering by only ever | |
174 | reading I<need> bytes. | |
175 | */ | |
176 | #define CBBUFSIZ 4096 | |
177 | ||
178 | typedef struct { | |
179 | i_read_callback_t cb; | |
180 | char *userdata; | |
181 | char buffer[CBBUFSIZ]; | |
182 | int length; | |
183 | int cpos; | |
184 | } i_gen_read_data; | |
185 | ||
186 | extern int i_gen_reader(i_gen_read_data *info, char *buffer, int need); | |
187 | extern i_gen_read_data *i_gen_read_data_new(i_read_callback_t cb, char *userdata); | |
188 | extern void free_gen_read_data(i_gen_read_data *); | |
189 | ||
190 | /* general writer callback | |
191 | userdata - the data the user passed into the writer | |
192 | data - the data to write | |
193 | data_size - the number of bytes to write | |
194 | write the data, return non-zero on success, zero on failure. | |
195 | */ | |
196 | typedef int (*i_write_callback_t)(char *userdata, char const *data, int size); | |
197 | ||
198 | typedef struct { | |
199 | i_write_callback_t cb; | |
200 | char *userdata; | |
201 | char buffer[CBBUFSIZ]; | |
202 | int maxlength; | |
203 | int filledto; | |
204 | } i_gen_write_data; | |
205 | ||
206 | extern int i_gen_writer(i_gen_write_data *info, char const *data, int size); | |
207 | extern i_gen_write_data *i_gen_write_data_new(i_write_callback_t cb, char *userdata, int maxlength); | |
208 | extern int free_gen_write_data(i_gen_write_data *, int flush); | |
209 | ||
210 | /* transparency handling for quantized output */ | |
211 | typedef enum i_transp_tag { | |
212 | tr_none, /* ignore any alpha channel */ | |
213 | tr_threshold, /* threshold the transparency - uses tr_threshold */ | |
214 | tr_errdiff, /* error diffusion */ | |
215 | tr_ordered /* an ordered dither */ | |
216 | } i_transp; | |
217 | ||
218 | /* controls how we build the colour map */ | |
219 | typedef enum i_make_colors_tag { | |
220 | mc_none, /* user supplied colour map only */ | |
221 | mc_web_map, /* Use the 216 colour web colour map */ | |
222 | mc_addi, /* Addi's algorithm */ | |
223 | mc_mask = 0xFF /* (mask for generator) */ | |
224 | } i_make_colors; | |
225 | ||
226 | /* controls how we translate the colours */ | |
227 | typedef enum i_translate_tag { | |
228 | pt_giflib, /* get gif lib to do it (ignores make_colours) */ | |
229 | pt_closest, /* just use the closest match within the hashbox */ | |
230 | pt_perturb, /* randomly perturb the data - uses perturb_size*/ | |
231 | pt_errdiff /* error diffusion dither - uses errdiff */ | |
232 | } i_translate; | |
233 | ||
234 | /* Which error diffusion map to use */ | |
235 | typedef enum i_errdiff_tag { | |
236 | ed_floyd, /* floyd-steinberg */ | |
237 | ed_jarvis, /* Jarvis, Judice and Ninke */ | |
238 | ed_stucki, /* Stucki */ | |
239 | ed_custom, /* the map found in ed_map|width|height|orig */ | |
240 | ed_mask = 0xFF, /* mask to get the map */ | |
241 | ed_bidir = 0x100 /* change direction for each row */ | |
242 | } i_errdiff; | |
243 | ||
244 | /* which ordered dither map to use | |
245 | currently only available for transparency | |
246 | I don't know of a way to do ordered dither of an image against some | |
247 | general palette | |
248 | */ | |
249 | typedef enum i_ord_dith_tag | |
250 | { | |
251 | od_random, /* sort of random */ | |
252 | od_dot8, /* large dot */ | |
253 | od_dot4, | |
254 | od_hline, | |
255 | od_vline, | |
256 | od_slashline, /* / line dither */ | |
257 | od_backline, /* \ line dither */ | |
34ba4c5b | 258 | od_tiny, /* small checkerbox */ |
02d1d628 AMH |
259 | od_custom /* custom 8x8 map */ |
260 | } i_ord_dith; | |
261 | ||
262 | typedef struct i_gif_pos_tag { | |
263 | int x, y; | |
264 | } i_gif_pos; | |
265 | ||
266 | /* passed into i_writegif_gen() to control quantization */ | |
267 | typedef struct i_quantize_tag { | |
268 | /* how to handle transparency */ | |
269 | i_transp transp; | |
270 | /* the threshold at which to make pixels opaque */ | |
271 | int tr_threshold; | |
272 | i_errdiff tr_errdiff; | |
273 | i_ord_dith tr_orddith; | |
274 | unsigned char tr_custom[64]; | |
275 | ||
276 | /* how to make the colour map */ | |
277 | i_make_colors make_colors; | |
278 | ||
279 | /* any existing colours | |
280 | mc_existing is an existing colour table | |
281 | mc_count is the number of existing colours | |
282 | mc_size is the total size of the array that mc_existing points | |
283 | at - this must be at least 256 | |
284 | */ | |
285 | i_color *mc_colors; | |
286 | int mc_size; | |
287 | int mc_count; | |
288 | ||
289 | /* how we translate the colours */ | |
290 | i_translate translate; | |
291 | ||
292 | /* the error diffusion map to use if translate is mc_errdiff */ | |
293 | i_errdiff errdiff; | |
294 | /* the following define the error diffusion values to use if | |
295 | errdiff is ed_custom. ed_orig is the column on the top row that | |
296 | represents the current | |
297 | */ | |
298 | int *ed_map; | |
299 | int ed_width, ed_height, ed_orig; | |
300 | ||
301 | /* the amount of perturbation to use for translate is mc_perturb */ | |
302 | int perturb; | |
303 | } i_quantize; | |
304 | ||
305 | typedef struct i_gif_opts { | |
306 | /* each image has a local color map */ | |
307 | int each_palette; | |
308 | ||
309 | /* images are interlaced */ | |
310 | int interlace; | |
311 | ||
312 | /* time for which image is displayed | |
313 | (in 1/100 seconds) | |
314 | default: 0 | |
315 | */ | |
316 | int delay_count; | |
317 | int *delays; | |
318 | ||
319 | /* user input flags | |
320 | default: 0 | |
321 | */ | |
322 | int user_input_count; | |
323 | char *user_input_flags; | |
324 | ||
325 | /* disposal | |
326 | default: 0 */ | |
327 | int disposal_count; | |
328 | char *disposal; | |
329 | ||
330 | /* this is added to the color table when we make an image transparent */ | |
331 | i_color tran_color; | |
332 | ||
333 | /* image positions */ | |
334 | int position_count; | |
335 | i_gif_pos *positions; | |
336 | ||
337 | /* Netscape loop extension - number of loops */ | |
338 | int loop_count; | |
339 | } i_gif_opts; | |
340 | ||
341 | extern void quant_makemap(i_quantize *quant, i_img **imgs, int count); | |
342 | extern i_palidx *quant_translate(i_quantize *quant, i_img *img); | |
343 | extern void quant_transparent(i_quantize *quant, i_palidx *indices, i_img *img, i_palidx trans_index); | |
344 | ||
345 | #ifdef HAVE_LIBJPEG | |
346 | i_img* i_readjpeg(int fd,char** iptc_itext,int *tlength); | |
347 | i_img* i_readjpeg_scalar(char *data, int length,char** iptc_itext,int *itlength); | |
348 | i_img* i_readjpeg_wiol(io_glue *ig, int length, char** iptc_itext, int *itlength); | |
349 | ||
350 | i_img* i_readjpeg_extra2(int fd,char** iptc_itext); | |
351 | undef_int i_writejpeg(i_img *im,int fd,int qfactor); | |
352 | #endif /* HAVE_LIBJPEG */ | |
353 | ||
354 | #ifdef HAVE_LIBTIFF | |
355 | i_img* i_readtiff_wiol(io_glue *ig, int length); | |
356 | undef_int i_writetiff_wiol(i_img *im, io_glue *ig); | |
357 | ||
358 | #endif /* HAVE_LIBTIFF */ | |
359 | ||
360 | #ifdef HAVE_LIBPNG | |
361 | i_img *i_readpng(int fd); | |
362 | i_img *i_readpng_scalar(char *data, int length); | |
363 | undef_int i_writepng(i_img *im,int fd); | |
364 | #endif /* HAVE_LIBPNG */ | |
365 | ||
366 | #ifdef HAVE_LIBGIF | |
367 | i_img *i_readgif(int fd, int **colour_table, int *colours); | |
368 | i_img *i_readgif_scalar(char *data, int length, int **colour_table, int *colours); | |
369 | i_img *i_readgif_callback(i_read_callback_t callback, char *userdata, int **colour_table, int *colours); | |
370 | undef_int i_writegif(i_img *im,int fd,int colors,int pixdev,int fixedlen,i_color fixed[]); | |
371 | undef_int i_writegifmc(i_img *im,int fd,int colors); | |
372 | undef_int i_writegifex(i_img *im,int fd); | |
373 | undef_int i_writegif_gen(i_quantize *quant, int fd, i_img **imgs, int count, i_gif_opts *opts); | |
374 | undef_int i_writegif_callback(i_quantize *quant, i_write_callback_t cb, char *userdata, int maxbuffer, i_img **imgs, int count, i_gif_opts *opts); | |
375 | ||
376 | void i_qdist(i_img *im); | |
377 | ||
378 | #endif /* HAVE_LIBGIF */ | |
379 | ||
380 | i_img *i_readraw(int fd,int x,int y,int datachannels,int storechannels,int intrl); | |
381 | undef_int i_writeraw(i_img* im,int fd); | |
382 | ||
383 | i_img *i_readpnm_wiol(io_glue *ig, int length); | |
384 | undef_int i_writeppm(i_img *im,int fd); | |
385 | ||
386 | ||
387 | i_img* i_scaleaxis(i_img *im, float Value, int Axis); | |
388 | i_img* i_scale_nn(i_img *im, float scx, float scy); | |
389 | i_img* i_haar(i_img *im); | |
390 | int i_count_colors(i_img *im,int maxc); | |
391 | ||
392 | i_img* i_transform(i_img *im, int *opx,int opxl,int *opy,int opyl,double parm[],int parmlen); | |
393 | ||
394 | struct rm_op; | |
395 | i_img* i_transform2(int width, int height, int channels, | |
396 | struct rm_op *ops, int ops_count, | |
397 | double *n_regs, int n_regs_count, | |
398 | i_color *c_regs, int c_regs_count, | |
399 | i_img **in_imgs, int in_imgs_count); | |
400 | /* filters */ | |
401 | ||
402 | void i_contrast(i_img *im, float intensity); | |
403 | void i_hardinvert(i_img *im); | |
404 | void i_noise(i_img *im, float amount, unsigned char type); | |
405 | void i_bumpmap(i_img *im,i_img *bump,int channel,int light_x,int light_y,int strength); | |
406 | void i_postlevels(i_img *im,int levels); | |
407 | void i_mosaic(i_img *im,int size); | |
408 | void i_watermark(i_img *im,i_img *wmark,int tx,int ty,int pixdiff); | |
409 | void i_autolevels(i_img *im,float lsat,float usat,float skew); | |
410 | void i_radnoise(i_img *im,int xo,int yo,float rscale,float ascale); | |
411 | void i_turbnoise(i_img *im,float xo,float yo,float scale); | |
412 | void i_gradgen(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure); | |
413 | void i_nearest_color(i_img *im, int num, int *xo, int *yo, i_color *ival, int dmeasure); | |
414 | ||
415 | /* Debug only functions */ | |
416 | ||
417 | void malloc_state( void ); | |
418 | ||
419 | /* this is sort of obsolete now */ | |
420 | ||
421 | typedef struct { | |
422 | undef_int (*i_has_format)(char *frmt); | |
423 | i_color*(*ICL_set)(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a); | |
424 | void (*ICL_info)(i_color *cl); | |
425 | ||
426 | i_img*(*i_img_new)( void ); | |
427 | i_img*(*i_img_empty)(i_img *im,int x,int y); | |
428 | i_img*(*i_img_empty_ch)(i_img *im,int x,int y,int ch); | |
429 | void(*i_img_exorcise)(i_img *im); | |
430 | ||
431 | void(*i_img_info)(i_img *im,int *info); | |
432 | ||
433 | void(*i_img_setmask)(i_img *im,int ch_mask); | |
434 | int (*i_img_getmask)(i_img *im); | |
435 | ||
436 | int (*i_ppix)(i_img *im,int x,int y,i_color *val); | |
437 | int (*i_gpix)(i_img *im,int x,int y,i_color *val); | |
438 | ||
439 | void(*i_box)(i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
440 | void(*i_draw)(i_img *im,int x1,int y1,int x2,int y2,i_color *val); | |
441 | void(*i_arc)(i_img *im,int x,int y,float rad,float d1,float d2,i_color *val); | |
442 | void(*i_copyto)(i_img *im,i_img *src,int x1,int y1,int x2,int y2,int tx,int ty); | |
443 | 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); | |
444 | void(*i_rubthru)(i_img *im,i_img *src,int tx,int ty); | |
445 | ||
446 | } symbol_table_t; | |
447 | ||
848ba81a TC |
448 | /* error handling |
449 | see error.c for documentation | |
450 | the error information is currently global | |
451 | */ | |
452 | typedef struct { | |
453 | char *msg; | |
454 | int code; | |
455 | } i_errmsg; | |
456 | typedef void (*i_error_cb)(int code, char const *msg); | |
457 | typedef void (*i_failed_cb)(i_errmsg *msgs); | |
458 | extern i_error_cb i_set_error_cb(i_error_cb); | |
459 | extern i_failed_cb i_set_failed_cb(i_failed_cb); | |
460 | extern void i_set_argv0(char const *); | |
461 | extern int i_set_errors_fatal(int new_fatal); | |
462 | extern i_errmsg *i_errors(); | |
463 | ||
464 | extern void i_push_error(int code, char const *msg); | |
465 | extern void i_push_errorf(int code, char const *fmt, ...); | |
466 | extern void i_push_errorvf(int code, char const *fmt, va_list); | |
467 | extern void i_clear_error(); | |
468 | extern int i_failed(int code, char const *msg); | |
02d1d628 AMH |
469 | |
470 | ||
471 | #endif |