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