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