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