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