23 #define PI 3.14159265358979323846
27 #define MAXINT 2147483647
30 #include "imdatatypes.h"
32 undef_int i_has_format(char *frmt);
34 /* constructors and destructors */
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 (const i_color *cl);
39 void ICL_DESTROY (i_color *cl);
40 void ICL_add (i_color *dst, i_color *src, int ch);
42 extern i_fcolor *i_fcolor_new(double r, double g, double b, double a);
43 extern void i_fcolor_destroy(i_fcolor *cl);
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);
50 i_img *im_img_8_new(pIMCTX, i_img_dim x,i_img_dim y,int ch);
51 #define i_img_empty(im, x, y) i_img_empty_ch((im), (x), (y), 3)
52 i_img *im_img_empty_ch(pIMCTX, i_img *im,i_img_dim x,i_img_dim y,int ch);
53 #define i_img_empty_ch(im, x, y, ch) im_img_empty_ch(aIMCTX, (im), (x), (y), (ch))
54 void i_img_exorcise(i_img *im);
55 void i_img_destroy(i_img *im);
56 i_img *im_img_alloc(pIMCTX);
57 void im_img_init(pIMCTX, i_img *im);
59 void i_img_info(i_img *im,i_img_dim *info);
61 extern i_img *i_sametype(i_img *im, i_img_dim xsize, i_img_dim ysize);
62 extern i_img *i_sametype_chans(i_img *im, i_img_dim xsize, i_img_dim ysize, int channels);
64 /* Image feature settings */
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 i_img_dim i_img_get_width(i_img *im);
70 i_img_dim i_img_get_height(i_img *im);
74 extern int i_ppix(i_img *im,i_img_dim x,i_img_dim y, const i_color *val);
75 extern int i_gpix(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
76 extern int i_ppixf(i_img *im,i_img_dim x,i_img_dim y, const i_fcolor *val);
77 extern int i_gpixf(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val);
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)))
84 extern i_img_dim i_plin(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals);
85 extern i_img_dim i_glin(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals);
86 extern i_img_dim i_plinf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals);
87 extern i_img_dim i_glinf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals);
88 extern i_img_dim i_gsamp(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
89 const int *chans, int chan_count);
90 extern i_img_dim i_gsampf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
91 const int *chans, int chan_count);
92 extern i_img_dim i_gpal(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
93 extern i_img_dim i_ppal(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
94 extern int i_addcolors(i_img *im, const i_color *colors, int count);
95 extern int i_getcolors(i_img *im, int i, i_color *, int count);
96 extern int i_colorcount(i_img *im);
97 extern int i_maxcolors(i_img *im);
98 extern int i_findcolor(i_img *im, const i_color *color, i_palidx *entry);
99 extern int i_setcolors(i_img *im, int index, const i_color *colors,
102 #define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
103 #define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
104 #define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
105 #define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
107 #define i_gsamp(im, l, r, y, samps, chans, count) \
108 (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
109 #define i_gsampf(im, l, r, y, samps, chans, count) \
110 (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
112 #define i_gsamp_bits(im, l, r, y, samps, chans, count, bits) \
113 (((im)->i_f_gsamp_bits) ? ((im)->i_f_gsamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
114 #define i_psamp_bits(im, l, r, y, samps, chans, count, bits) \
115 (((im)->i_f_psamp_bits) ? ((im)->i_f_psamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
117 #define i_findcolor(im, color, entry) \
118 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
120 #define i_gpal(im, l, r, y, vals) \
121 (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
122 #define i_ppal(im, l, r, y, vals) \
123 (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
124 #define i_addcolors(im, colors, count) \
125 (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
126 #define i_getcolors(im, index, color, count) \
127 (((im)->i_f_getcolors) ? \
128 ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
129 #define i_setcolors(im, index, color, count) \
130 (((im)->i_f_setcolors) ? \
131 ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
132 #define i_colorcount(im) \
133 (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
134 #define i_maxcolors(im) \
135 (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
136 #define i_findcolor(im, color, entry) \
137 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
139 #define i_img_virtual(im) ((im)->virtual)
140 #define i_img_type(im) ((im)->type)
141 #define i_img_bits(im) ((im)->bits)
143 extern i_fill_t *i_new_fill_solidf(const i_fcolor *c, int combine);
144 extern i_fill_t *i_new_fill_solid(const i_color *c, int combine);
146 i_new_fill_hatch(const i_color *fg, const i_color *bg, int combine, int hatch,
147 const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy);
149 i_new_fill_hatchf(const i_fcolor *fg, const i_fcolor *bg, int combine, int hatch,
150 const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy);
152 i_new_fill_image(i_img *im, const double *matrix, i_img_dim xoff, i_img_dim yoff, int combine);
153 extern i_fill_t *i_new_fill_opacity(i_fill_t *, double alpha_mult);
154 extern void i_fill_destroy(i_fill_t *fill);
156 float i_gpix_pch(i_img *im,i_img_dim x,i_img_dim y,int ch);
158 /* functions for drawing primitives */
160 void i_box (i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val);
161 void i_box_filled (i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val);
162 int i_box_filledf (i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_fcolor *val);
163 void i_box_cfill(i_img *im, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, i_fill_t *fill);
164 void i_line (i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val, int endp);
165 void i_line_aa (i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val, int endp);
166 void i_arc (i_img *im,i_img_dim x,i_img_dim y,double rad,double d1,double d2,const i_color *val);
167 int i_arc_out(i_img *im,i_img_dim x,i_img_dim y,i_img_dim rad,double d1,double d2,const i_color *val);
168 int i_arc_out_aa(i_img *im,i_img_dim x,i_img_dim y,i_img_dim rad,double d1,double d2,const i_color *val);
169 void i_arc_aa (i_img *im, double x, double y, double rad, double d1, double d2, const i_color *val);
170 void i_arc_cfill(i_img *im,i_img_dim x,i_img_dim y,double rad,double d1,double d2,i_fill_t *fill);
171 void i_arc_aa_cfill(i_img *im,double x,double y,double rad,double d1,double d2,i_fill_t *fill);
172 void i_circle_aa (i_img *im,double x, double y,double rad,const i_color *val);
173 int i_circle_out (i_img *im,i_img_dim x, i_img_dim y, i_img_dim rad,const i_color *val);
174 int i_circle_out_aa (i_img *im,i_img_dim x, i_img_dim y, i_img_dim rad,const i_color *val);
175 void i_copyto (i_img *im,i_img *src,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,i_img_dim tx,i_img_dim ty);
176 void i_copyto_trans(i_img *im,i_img *src,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,i_img_dim tx,i_img_dim ty,const i_color *trans);
177 i_img* i_copy (i_img *src);
178 int i_rubthru (i_img *im, i_img *src, i_img_dim tx, i_img_dim ty, i_img_dim src_minx, i_img_dim src_miny, i_img_dim src_maxx, i_img_dim src_maxy);
180 i_compose_mask(i_img *out, i_img *src, i_img *mask,
181 i_img_dim out_left, i_img_dim out_top, i_img_dim src_left, i_img_dim src_top,
182 i_img_dim mask_left, i_img_dim mask_top, i_img_dim width, i_img_dim height,
183 int combine, double opacity);
185 i_compose(i_img *out, i_img *src,
186 i_img_dim out_left, i_img_dim out_top, i_img_dim src_left, i_img_dim src_top,
187 i_img_dim width, i_img_dim height, int combine, double opacity);
190 i_combine(i_img **src, const int *channels, int in_count);
192 undef_int i_flipxy (i_img *im, int direction);
193 extern i_img *i_rotate90(i_img *im, int degrees);
194 extern i_img *i_rotate_exact(i_img *im, double amount);
195 extern i_img *i_rotate_exact_bg(i_img *im, double amount, const i_color *backp, const i_fcolor *fbackp);
196 extern i_img *i_matrix_transform(i_img *im, i_img_dim xsize, i_img_dim ysize, const double *matrix);
197 extern i_img *i_matrix_transform_bg(i_img *im, i_img_dim xsize, i_img_dim ysize, const double *matrix, const i_color *backp, const i_fcolor *fbackp);
199 void i_bezier_multi(i_img *im,int l,const double *x,const double *y,const i_color *val);
200 int i_poly_aa (i_img *im,int l,const double *x,const double *y,const i_color *val);
201 int i_poly_aa_cfill(i_img *im,int l,const double *x,const double *y,i_fill_t *fill);
203 undef_int i_flood_fill (i_img *im,i_img_dim seedx,i_img_dim seedy, const i_color *dcol);
204 undef_int i_flood_cfill(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill);
205 undef_int i_flood_fill_border (i_img *im,i_img_dim seedx,i_img_dim seedy, const i_color *dcol, const i_color *border);
206 undef_int i_flood_cfill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill, const i_color *border);
209 /* image processing functions */
211 int i_gaussian (i_img *im, double stdev);
212 int i_conv (i_img *im,const double *coeff,int len);
213 void i_unsharp_mask(i_img *im, double stddev, double scale);
215 /* colour manipulation */
216 extern i_img *i_convert(i_img *src, const double *coeff, int outchan, int inchan);
217 extern void i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask);
219 float i_img_diff (i_img *im1,i_img *im2);
220 double i_img_diffd(i_img *im1,i_img *im2);
221 int i_img_samef(i_img *im1,i_img *im2, double epsilon, const char *what);
225 undef_int i_init_fonts( int t1log );
229 TT_Fonthandle* i_tt_new(const char *fontname);
230 void i_tt_destroy( TT_Fonthandle *handle );
231 undef_int i_tt_cp( TT_Fonthandle *handle,i_img *im,i_img_dim xb,i_img_dim yb,int channel,double points,char const* txt,size_t len,int smooth, int utf8, int align);
232 undef_int i_tt_text( TT_Fonthandle *handle, i_img *im, i_img_dim xb, i_img_dim yb, const i_color *cl, double points, char const* txt, size_t len, int smooth, int utf8, int align);
233 undef_int i_tt_bbox( TT_Fonthandle *handle, double points,const char *txt,size_t len,i_img_dim cords[6], int utf8);
234 size_t i_tt_has_chars(TT_Fonthandle *handle, char const *text, size_t len, int utf8, char *out);
235 void i_tt_dump_names(TT_Fonthandle *handle);
236 size_t i_tt_face_name(TT_Fonthandle *handle, char *name_buf,
237 size_t name_buf_size);
238 size_t i_tt_glyph_name(TT_Fonthandle *handle, unsigned long ch, char *name_buf,
239 size_t name_buf_size);
241 #endif /* End of freetype headers */
243 extern void i_quant_makemap(i_quantize *quant, i_img **imgs, int count);
244 extern i_palidx *i_quant_translate(i_quantize *quant, i_img *img);
245 extern void i_quant_transparent(i_quantize *quant, i_palidx *indices, i_img *img, i_palidx trans_index);
247 i_img *im_img_pal_new(pIMCTX, i_img_dim x, i_img_dim y, int ch, int maxpal);
249 extern i_img *i_img_to_pal(i_img *src, i_quantize *quant);
250 extern i_img *i_img_to_rgb(i_img *src);
251 extern i_img *i_img_masked_new(i_img *targ, i_img *mask, i_img_dim x, i_img_dim y,
252 i_img_dim w, i_img_dim h);
253 extern i_img *im_img_16_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
254 extern i_img *i_img_to_rgb16(i_img *im);
255 extern i_img *im_img_double_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
256 extern i_img *i_img_to_drgb(i_img *im);
258 extern int i_img_is_monochrome(i_img *im, int *zero_is_white);
259 extern int i_get_file_background(i_img *im, i_color *bg);
260 extern int i_get_file_backgroundf(i_img *im, i_fcolor *bg);
262 const char * i_test_format_probe(io_glue *data, int length);
265 i_img * i_readraw_wiol(io_glue *ig, i_img_dim x, i_img_dim y, int datachannels, int storechannels, int intrl);
266 undef_int i_writeraw_wiol(i_img* im, io_glue *ig);
268 i_img * i_readpnm_wiol(io_glue *ig, int allow_incomplete);
269 i_img ** i_readpnm_multi_wiol(io_glue *ig, int *count, int allow_incomplete);
270 undef_int i_writeppm_wiol(i_img *im, io_glue *ig);
272 extern int i_writebmp_wiol(i_img *im, io_glue *ig);
273 extern i_img *i_readbmp_wiol(io_glue *ig, int allow_incomplete);
275 int tga_header_verify(unsigned char headbuf[18]);
277 i_img * i_readtga_wiol(io_glue *ig, int length);
278 undef_int i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen);
280 i_img * i_readrgb_wiol(io_glue *ig, int length);
281 undef_int i_writergb_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen);
283 i_img * i_scaleaxis(i_img *im, double Value, int Axis);
284 i_img * i_scale_nn(i_img *im, double scx, double scy);
285 i_img * i_scale_mixing(i_img *src, i_img_dim width, i_img_dim height);
286 i_img * i_haar(i_img *im);
287 int i_count_colors(i_img *im,int maxc);
288 int i_get_anonymous_color_histo(i_img *im, unsigned int **col_usage, int maxc);
290 i_img * i_transform(i_img *im, int *opx, int opxl, int *opy,int opyl,double parm[],int parmlen);
293 i_img * i_transform2(i_img_dim width, i_img_dim height, int channels,
294 struct rm_op *ops, int ops_count,
295 double *n_regs, int n_regs_count,
296 i_color *c_regs, int c_regs_count,
297 i_img **in_imgs, int in_imgs_count);
301 void i_contrast(i_img *im, float intensity);
302 void i_hardinvert(i_img *im);
303 void i_hardinvertall(i_img *im);
304 void i_noise(i_img *im, float amount, unsigned char type);
305 void i_bumpmap(i_img *im,i_img *bump,int channel,i_img_dim light_x,i_img_dim light_y,i_img_dim strength);
306 void i_bumpmap_complex(i_img *im, i_img *bump, int channel, i_img_dim tx, i_img_dim ty, double Lx, double Ly,
307 double Lz, float cd, float cs, float n, i_color *Ia, i_color *Il, i_color *Is);
308 void i_postlevels(i_img *im,int levels);
309 void i_mosaic(i_img *im,i_img_dim size);
310 void i_watermark(i_img *im,i_img *wmark,i_img_dim tx,i_img_dim ty,int pixdiff);
311 void i_autolevels(i_img *im,float lsat,float usat,float skew);
312 void i_radnoise(i_img *im,i_img_dim xo,i_img_dim yo,double rscale,double ascale);
313 void i_turbnoise(i_img *im,double xo,double yo,double scale);
314 void i_gradgen(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *ival, int dmeasure);
315 int i_nearest_color(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *ival, int dmeasure);
316 i_img *i_diff_image(i_img *im, i_img *im2, double mindist);
318 i_fountain(i_img *im, double xa, double ya, double xb, double yb,
319 i_fountain_type type, i_fountain_repeat repeat,
320 int combine, int super_sample, double ssample_param,
321 int count, i_fountain_seg *segs);
323 i_new_fill_fount(double xa, double ya, double xb, double yb,
324 i_fountain_type type, i_fountain_repeat repeat,
325 int combine, int super_sample, double ssample_param,
326 int count, i_fountain_seg *segs);
328 /* Debug only functions */
330 void malloc_state( void );
334 /* image tag processing */
335 extern void i_tags_new(i_img_tags *tags);
336 extern int i_tags_addn(i_img_tags *tags, char const *name, int code,
338 extern int i_tags_add(i_img_tags *tags, char const *name, int code,
339 char const *data, int size, int idata);
340 extern int i_tags_set(i_img_tags *tags, char const *name,
341 char const *data, int size);
342 extern int i_tags_setn(i_img_tags *tags, char const *name, int idata);
344 extern void i_tags_destroy(i_img_tags *tags);
345 extern int i_tags_find(i_img_tags *tags, char const *name, int start,
347 extern int i_tags_findn(i_img_tags *tags, int code, int start, int *entry);
348 extern int i_tags_delete(i_img_tags *tags, int entry);
349 extern int i_tags_delbyname(i_img_tags *tags, char const *name);
350 extern int i_tags_delbycode(i_img_tags *tags, int code);
351 extern int i_tags_get_float(i_img_tags *tags, char const *name, int code,
353 extern int i_tags_set_float(i_img_tags *tags, char const *name, int code,
355 extern int i_tags_set_float2(i_img_tags *tags, char const *name, int code,
356 double value, int places);
357 extern int i_tags_get_int(i_img_tags *tags, char const *name, int code,
359 extern int i_tags_get_string(i_img_tags *tags, char const *name, int code,
360 char *value, size_t value_size);
361 extern int i_tags_get_color(i_img_tags *tags, char const *name, int code,
363 extern int i_tags_set_color(i_img_tags *tags, char const *name, int code,
364 i_color const *value);
365 extern void i_tags_print(i_img_tags *tags);
367 /* image file limits */
369 im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes);
371 im_get_image_file_limits(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes);
373 im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size);
375 /* memory allocation */
376 void* mymalloc(size_t size);
377 void myfree(void *p);
378 void* myrealloc(void *p, size_t newsize);
379 void* mymalloc_file_line (size_t size, char* file, int line);
380 void myfree_file_line (void *p, char*file, int line);
381 void* myrealloc_file_line(void *p, size_t newsize, char* file,int line);
383 #ifdef IMAGER_DEBUG_MALLOC
385 #define mymalloc(x) (mymalloc_file_line((x), __FILE__, __LINE__))
386 #define myrealloc(x,y) (myrealloc_file_line((x),(y), __FILE__, __LINE__))
387 #define myfree(x) (myfree_file_line((x), __FILE__, __LINE__))
389 void malloc_state (void);
390 void bndcheck_all (void);
394 void malloc_state(void);
396 #endif /* IMAGER_MALLOC_DEBUG */
398 #include "imrender.h"
401 i_adapt_colors(int dest_channels, int src_channels, i_color *colors,
404 i_adapt_fcolors(int dest_channels, int src_channels, i_fcolor *colors,
408 i_adapt_colors_bg(int dest_channels, int src_channels, i_color *colors,
409 size_t count, i_color const *bg);
411 i_adapt_fcolors_bg(int dest_channels, int src_channels, i_fcolor *colors,
412 size_t count, i_fcolor const *bg);
415 i_gsamp_bg(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samples,
416 int out_channels, i_color const *bg);
419 i_gsampf_bg(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samples,
420 int out_channels, i_fcolor const *bg);
422 extern im_context_t (*im_get_context)(void);