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