]> git.imager.perl.org - imager.git/blame_incremental - imager.h
remove a pointless NULL check from i_img_destroy()
[imager.git] / imager.h
... / ...
CommitLineData
1#ifndef _IMAGE_H_
2#define _IMAGE_H_
3
4#include "imconfig.h"
5#include "immacros.h"
6#include "imio.h"
7#include "iolayer.h"
8#include "stackmach.h"
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#include "imdatatypes.h"
27
28undef_int i_has_format(char *frmt);
29
30/* constructors and destructors */
31
32i_color *ICL_new_internal( unsigned char r,unsigned char g,unsigned char b,unsigned char a);
33i_color *ICL_set_internal(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a);
34void ICL_info (const i_color *cl);
35void ICL_DESTROY (i_color *cl);
36void ICL_add (i_color *dst, i_color *src, int ch);
37
38extern i_fcolor *i_fcolor_new(double r, double g, double b, double a);
39extern void i_fcolor_destroy(i_fcolor *cl);
40
41extern void i_rgb_to_hsvf(i_fcolor *color);
42extern void i_hsv_to_rgbf(i_fcolor *color);
43extern void i_rgb_to_hsv(i_color *color);
44extern void i_hsv_to_rgb(i_color *color);
45
46i_img *im_img_8_new(pIMCTX, i_img_dim x,i_img_dim y,int ch);
47#define i_img_empty(im, x, y) i_img_empty_ch((im), (x), (y), 3)
48i_img *im_img_empty_ch(pIMCTX, i_img *im,i_img_dim x,i_img_dim y,int ch);
49#define i_img_empty_ch(im, x, y, ch) im_img_empty_ch(aIMCTX, (im), (x), (y), (ch))
50void i_img_exorcise(i_img *im);
51void i_img_destroy(i_img *im);
52i_img *im_img_alloc(pIMCTX);
53void im_img_init(pIMCTX, i_img *im);
54
55void i_img_info(i_img *im,i_img_dim *info);
56
57extern i_img *i_sametype(i_img *im, i_img_dim xsize, i_img_dim ysize);
58extern i_img *i_sametype_chans(i_img *im, i_img_dim xsize, i_img_dim ysize, int channels);
59
60/* Image feature settings */
61
62void i_img_setmask (i_img *im,int ch_mask);
63int i_img_getmask (i_img *im);
64int i_img_getchannels(i_img *im);
65i_img_dim i_img_get_width(i_img *im);
66i_img_dim i_img_get_height(i_img *im);
67i_color_model_t i_img_color_model(i_img *im);
68int i_img_alpha_channel(i_img *im, int *channel);
69int i_img_color_channels(i_img *im);
70
71/* Base functions */
72
73extern int (i_ppix)(i_img *im,i_img_dim x,i_img_dim y, const i_color *val);
74extern int (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
75extern int (i_ppixf)(i_img *im,i_img_dim x,i_img_dim y, const i_fcolor *val);
76extern int (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val);
77
78extern i_img_dim (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
79 const i_color *vals);
80extern i_img_dim (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
81 i_color *vals);
82extern i_img_dim (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
83 const i_fcolor *vals);
84extern i_img_dim (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
85 i_fcolor *vals);
86extern i_img_dim (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
87 i_sample_t *samp, const int *chans, int chan_count);
88extern i_img_dim
89(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
90 const int *chans, int chan_count);
91extern i_img_dim
92(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
93extern i_img_dim
94(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
95extern int (i_addcolors)(i_img *im, const i_color *colors, int count);
96extern int (i_getcolors)(i_img *im, int i, i_color *, int count);
97extern int (i_colorcount)(i_img *im);
98extern int (i_maxcolors)(i_img *im);
99extern int (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry);
100extern int (i_setcolors)(i_img *im, int index, const i_color *colors,
101 int count);
102
103
104extern i_fill_t *i_new_fill_solidf(const i_fcolor *c, int combine);
105extern i_fill_t *i_new_fill_solid(const i_color *c, int combine);
106extern i_fill_t *
107i_new_fill_hatch(const i_color *fg, const i_color *bg, int combine, int hatch,
108 const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy);
109extern i_fill_t *
110i_new_fill_hatchf(const i_fcolor *fg, const i_fcolor *bg, int combine, int hatch,
111 const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy);
112extern i_fill_t *
113i_new_fill_image(i_img *im, const double *matrix, i_img_dim xoff, i_img_dim yoff, int combine);
114extern i_fill_t *i_new_fill_opacity(i_fill_t *, double alpha_mult);
115extern void i_fill_destroy(i_fill_t *fill);
116
117float i_gpix_pch(i_img *im,i_img_dim x,i_img_dim y,int ch);
118
119/* functions for drawing primitives */
120
121void 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);
122void 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);
123int 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);
124void 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);
125void 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);
126void 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);
127void i_arc (i_img *im,i_img_dim x,i_img_dim y,double rad,double d1,double d2,const i_color *val);
128int 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);
129int 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);
130void i_arc_aa (i_img *im, double x, double y, double rad, double d1, double d2, const i_color *val);
131void i_arc_cfill(i_img *im,i_img_dim x,i_img_dim y,double rad,double d1,double d2,i_fill_t *fill);
132void i_arc_aa_cfill(i_img *im,double x,double y,double rad,double d1,double d2,i_fill_t *fill);
133void i_circle_aa (i_img *im,double x, double y,double rad,const i_color *val);
134void i_circle_aa_fill(i_img *im,double x, double y,double rad,i_fill_t *fill);
135int i_circle_out (i_img *im,i_img_dim x, i_img_dim y, i_img_dim rad,const i_color *val);
136int i_circle_out_aa (i_img *im,i_img_dim x, i_img_dim y, i_img_dim rad,const i_color *val);
137void 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);
138void 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);
139i_img* i_copy (i_img *src);
140int 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);
141extern int
142i_compose_mask(i_img *out, i_img *src, i_img *mask,
143 i_img_dim out_left, i_img_dim out_top, i_img_dim src_left, i_img_dim src_top,
144 i_img_dim mask_left, i_img_dim mask_top, i_img_dim width, i_img_dim height,
145 int combine, double opacity);
146extern int
147i_compose(i_img *out, i_img *src,
148 i_img_dim out_left, i_img_dim out_top, i_img_dim src_left, i_img_dim src_top,
149 i_img_dim width, i_img_dim height, int combine, double opacity);
150
151extern i_img *
152i_combine(i_img **src, const int *channels, int in_count);
153
154undef_int i_flipxy (i_img *im, int direction);
155extern i_img *i_rotate90(i_img *im, int degrees);
156extern i_img *i_rotate_exact(i_img *im, double amount);
157extern i_img *i_rotate_exact_bg(i_img *im, double amount, const i_color *backp, const i_fcolor *fbackp);
158extern i_img *i_matrix_transform(i_img *im, i_img_dim xsize, i_img_dim ysize, const double *matrix);
159extern 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);
160
161void i_bezier_multi(i_img *im,int l,const double *x,const double *y,const i_color *val);
162int i_poly_aa (i_img *im,int l,const double *x,const double *y,const i_color *val);
163int i_poly_aa_cfill(i_img *im,int l,const double *x,const double *y,i_fill_t *fill);
164int i_poly_aa_m (i_img *im,int l,const double *x,const double *y, i_poly_fill_mode_t mode, const i_color *val);
165int i_poly_aa_cfill_m(i_img *im,int l,const double *x,const double *y, i_poly_fill_mode_t mode, i_fill_t *fill);
166extern int
167i_poly_poly_aa(i_img *im, int count, const i_polygon_t *polys,
168 i_poly_fill_mode_t mode, const i_color *val);
169extern int
170i_poly_poly_aa_cfill(i_img *im, int count, const i_polygon_t *polys,
171 i_poly_fill_mode_t mode, i_fill_t *fill);
172
173undef_int i_flood_fill (i_img *im,i_img_dim seedx,i_img_dim seedy, const i_color *dcol);
174undef_int i_flood_cfill(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill);
175undef_int i_flood_fill_border (i_img *im,i_img_dim seedx,i_img_dim seedy, const i_color *dcol, const i_color *border);
176undef_int i_flood_cfill_border(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill, const i_color *border);
177
178
179/* image processing functions */
180
181int i_gaussian (i_img *im, double stdev);
182int i_conv (i_img *im,const double *coeff,int len);
183void i_unsharp_mask(i_img *im, double stddev, double scale);
184
185/* colour manipulation */
186extern i_img *i_convert(i_img *src, const double *coeff, int outchan, int inchan);
187extern void i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask);
188
189float i_img_diff (i_img *im1,i_img *im2);
190double i_img_diffd(i_img *im1,i_img *im2);
191int i_img_samef(i_img *im1,i_img *im2, double epsilon, const char *what);
192
193/* font routines */
194
195#ifdef HAVE_LIBTT
196
197extern void i_tt_start(void);
198
199TT_Fonthandle* i_tt_new(const char *fontname);
200void i_tt_destroy( TT_Fonthandle *handle );
201undef_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);
202undef_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);
203undef_int i_tt_bbox( TT_Fonthandle *handle, double points,const char *txt,size_t len,i_img_dim cords[6], int utf8);
204size_t i_tt_has_chars(TT_Fonthandle *handle, char const *text, size_t len, int utf8, char *out);
205void i_tt_dump_names(TT_Fonthandle *handle);
206size_t i_tt_face_name(TT_Fonthandle *handle, char *name_buf,
207 size_t name_buf_size);
208size_t i_tt_glyph_name(TT_Fonthandle *handle, unsigned long ch, char *name_buf,
209 size_t name_buf_size);
210
211#endif /* End of freetype headers */
212
213extern void i_quant_makemap(i_quantize *quant, i_img **imgs, int count);
214extern i_palidx *i_quant_translate(i_quantize *quant, i_img *img);
215extern void i_quant_transparent(i_quantize *quant, i_palidx *indices, i_img *img, i_palidx trans_index);
216
217i_img *im_img_pal_new(pIMCTX, i_img_dim x, i_img_dim y, int ch, int maxpal);
218
219extern i_img *i_img_to_pal(i_img *src, i_quantize *quant);
220extern i_img *i_img_to_rgb(i_img *src);
221extern i_img *i_img_masked_new(i_img *targ, i_img *mask, i_img_dim x, i_img_dim y,
222 i_img_dim w, i_img_dim h);
223extern i_img *im_img_16_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
224extern i_img *i_img_to_rgb16(i_img *im);
225extern i_img *im_img_double_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
226extern i_img *i_img_to_drgb(i_img *im);
227
228extern int i_img_is_monochrome(i_img *im, int *zero_is_white);
229extern int i_get_file_background(i_img *im, i_color *bg);
230extern int i_get_file_backgroundf(i_img *im, i_fcolor *bg);
231
232const char * i_test_format_probe(io_glue *data, int length);
233
234
235i_img * i_readraw_wiol(io_glue *ig, i_img_dim x, i_img_dim y, int datachannels, int storechannels, int intrl);
236undef_int i_writeraw_wiol(i_img* im, io_glue *ig);
237
238i_img * i_readpnm_wiol(io_glue *ig, int allow_incomplete);
239i_img ** i_readpnm_multi_wiol(io_glue *ig, int *count, int allow_incomplete);
240undef_int i_writeppm_wiol(i_img *im, io_glue *ig);
241
242extern int i_writebmp_wiol(i_img *im, io_glue *ig);
243extern i_img *i_readbmp_wiol(io_glue *ig, int allow_incomplete);
244
245int tga_header_verify(unsigned char headbuf[18]);
246
247i_img * i_readtga_wiol(io_glue *ig, int length);
248undef_int i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen);
249
250i_img * i_readrgb_wiol(io_glue *ig, int length);
251undef_int i_writergb_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idstring, size_t idlen);
252
253i_img * i_scaleaxis(i_img *im, double Value, int Axis);
254i_img * i_scale_nn(i_img *im, double scx, double scy);
255i_img * i_scale_mixing(i_img *src, i_img_dim width, i_img_dim height);
256i_img * i_haar(i_img *im);
257int i_count_colors(i_img *im,int maxc);
258int i_get_anonymous_color_histo(i_img *im, unsigned int **col_usage, int maxc);
259
260i_img * i_transform(i_img *im, int *opx, int opxl, int *opy,int opyl,double parm[],int parmlen);
261
262struct rm_op;
263i_img * i_transform2(i_img_dim width, i_img_dim height, int channels,
264 struct rm_op *ops, int ops_count,
265 double *n_regs, int n_regs_count,
266 i_color *c_regs, int c_regs_count,
267 i_img **in_imgs, int in_imgs_count);
268
269/* filters */
270
271void i_contrast(i_img *im, float intensity);
272void i_hardinvert(i_img *im);
273void i_hardinvertall(i_img *im);
274void i_noise(i_img *im, float amount, unsigned char type);
275void i_bumpmap(i_img *im,i_img *bump,int channel,i_img_dim light_x,i_img_dim light_y,i_img_dim strength);
276void i_bumpmap_complex(i_img *im, i_img *bump, int channel, i_img_dim tx, i_img_dim ty, double Lx, double Ly,
277 double Lz, float cd, float cs, float n, i_color *Ia, i_color *Il, i_color *Is);
278void i_postlevels(i_img *im,int levels);
279void i_mosaic(i_img *im,i_img_dim size);
280void i_watermark(i_img *im,i_img *wmark,i_img_dim tx,i_img_dim ty,int pixdiff);
281void i_autolevels(i_img *im,float lsat,float usat,float skew);
282void i_autolevels_mono(i_img *im,float lsat,float usat);
283void i_radnoise(i_img *im,i_img_dim xo,i_img_dim yo,double rscale,double ascale);
284void i_turbnoise(i_img *im,double xo,double yo,double scale);
285void i_gradgen(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *ival, int dmeasure);
286int i_nearest_color(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *ival, int dmeasure);
287i_img *i_diff_image(i_img *im, i_img *im2, double mindist);
288int
289i_fountain(i_img *im, double xa, double ya, double xb, double yb,
290 i_fountain_type type, i_fountain_repeat repeat,
291 int combine, int super_sample, double ssample_param,
292 int count, i_fountain_seg *segs);
293extern i_fill_t *
294i_new_fill_fount(double xa, double ya, double xb, double yb,
295 i_fountain_type type, i_fountain_repeat repeat,
296 int combine, int super_sample, double ssample_param,
297 int count, i_fountain_seg *segs);
298
299/* Debug only functions */
300
301void malloc_state( void );
302
303#include "imerror.h"
304
305/* image tag processing */
306extern void i_tags_new(i_img_tags *tags);
307extern int i_tags_addn(i_img_tags *tags, char const *name, int code,
308 int idata);
309extern int i_tags_add(i_img_tags *tags, char const *name, int code,
310 char const *data, int size, int idata);
311extern int i_tags_set(i_img_tags *tags, char const *name,
312 char const *data, int size);
313extern int i_tags_setn(i_img_tags *tags, char const *name, int idata);
314
315extern void i_tags_destroy(i_img_tags *tags);
316extern int i_tags_find(i_img_tags *tags, char const *name, int start,
317 int *entry);
318extern int i_tags_findn(i_img_tags *tags, int code, int start, int *entry);
319extern int i_tags_delete(i_img_tags *tags, int entry);
320extern int i_tags_delbyname(i_img_tags *tags, char const *name);
321extern int i_tags_delbycode(i_img_tags *tags, int code);
322extern int i_tags_get_float(i_img_tags *tags, char const *name, int code,
323 double *value);
324extern int i_tags_set_float(i_img_tags *tags, char const *name, int code,
325 double value);
326extern int i_tags_set_float2(i_img_tags *tags, char const *name, int code,
327 double value, int places);
328extern int i_tags_get_int(i_img_tags *tags, char const *name, int code,
329 int *value);
330extern int i_tags_get_string(i_img_tags *tags, char const *name, int code,
331 char *value, size_t value_size);
332extern int i_tags_get_color(i_img_tags *tags, char const *name, int code,
333 i_color *value);
334extern int i_tags_set_color(i_img_tags *tags, char const *name, int code,
335 i_color const *value);
336extern void i_tags_print(i_img_tags *tags);
337
338/* image file limits */
339extern int
340im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes);
341extern int
342im_get_image_file_limits(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes);
343extern int
344im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size);
345
346/* memory allocation */
347void* mymalloc(size_t size);
348void myfree(void *p);
349void* myrealloc(void *p, size_t newsize);
350void* mymalloc_file_line (size_t size, char* file, int line);
351void myfree_file_line (void *p, char*file, int line);
352void* myrealloc_file_line(void *p, size_t newsize, char* file,int line);
353
354#ifdef IMAGER_DEBUG_MALLOC
355
356#define mymalloc(x) (mymalloc_file_line((x), __FILE__, __LINE__))
357#define myrealloc(x,y) (myrealloc_file_line((x),(y), __FILE__, __LINE__))
358#define myfree(x) (myfree_file_line((x), __FILE__, __LINE__))
359
360void malloc_state (void);
361void bndcheck_all (void);
362
363#else
364
365void malloc_state(void);
366
367#endif /* IMAGER_MALLOC_DEBUG */
368
369#include "imrender.h"
370
371extern void
372i_adapt_colors(int dest_channels, int src_channels, i_color *colors,
373 size_t count);
374extern void
375i_adapt_fcolors(int dest_channels, int src_channels, i_fcolor *colors,
376 size_t count);
377
378extern void
379i_adapt_colors_bg(int dest_channels, int src_channels, i_color *colors,
380 size_t count, i_color const *bg);
381extern void
382i_adapt_fcolors_bg(int dest_channels, int src_channels, i_fcolor *colors,
383 size_t count, i_fcolor const *bg);
384
385extern int
386i_gsamp_bg(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samples,
387 int out_channels, i_color const *bg);
388
389extern int
390i_gsampf_bg(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samples,
391 int out_channels, i_fcolor const *bg);
392
393/* context object management */
394extern im_context_t im_context_new(void);
395extern void im_context_refinc(im_context_t ctx, const char *where);
396extern void im_context_refdec(im_context_t ctx, const char *where);
397extern im_context_t im_context_clone(im_context_t ctx, const char *where);
398extern im_slot_t im_context_slot_new(im_slot_destroy_t);
399extern void *im_context_slot_get(im_context_t ctx, im_slot_t slot);
400extern int im_context_slot_set(im_context_t ctx, im_slot_t slot, void *);
401
402extern im_context_t (*im_get_context)(void);
403
404/* mutex API */
405extern i_mutex_t i_mutex_new(void);
406extern void i_mutex_destroy(i_mutex_t m);
407extern void i_mutex_lock(i_mutex_t m);
408extern void i_mutex_unlock(i_mutex_t m);
409
410#include "imio.h"
411
412#endif