1 /* Declares utility functions useful across various files which
2 aren't meant to be available externally
11 /* wrapper functions that implement the floating point sample version of a
12 function in terms of the 8-bit sample version
14 extern int i_ppixf_fp(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
15 extern int i_gpixf_fp(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
16 extern i_img_dim i_plinf_fp(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *pix);
17 extern i_img_dim i_glinf_fp(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *pix);
18 extern i_img_dim i_gsampf_fp(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
19 int const *chans, int chan_count);
21 /* wrapper functions that forward palette calls to the underlying image,
22 assuming the underlying image is the first pointer in whatever
25 extern int i_addcolors_forward(i_img *im, const i_color *, int count);
26 extern int i_getcolors_forward(i_img *im, int i, i_color *, int count);
27 extern int i_colorcount_forward(i_img *im);
28 extern int i_maxcolors_forward(i_img *im);
29 extern int i_findcolor_forward(i_img *im, const i_color *color,
31 extern int i_setcolors_forward(i_img *im, int index, const i_color *colors,
34 /* fallback handler for gsamp_bits */
35 extern i_img_dim i_gsamp_bits_fb(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, unsigned *samp,
36 const int *chans, int chan_count, int bits);
38 #define SampleFTo16(num) ((int)((num) * 65535.0 + 0.5))
39 /* we add that little bit to avoid rounding issues */
40 #define Sample16ToF(num) ((num) / 65535.0)
42 #define SampleFTo8(num) ((int)((num) * 255.0 + 0.5))
43 #define Sample8ToF(num) ((num) / 255.0)
45 #define Sample16To8(num) (((num)+128) / 257)
46 #define Sample8To16(num) ((num) * 257)
48 extern void i_get_combine(int combine, i_fill_combine_f *, i_fill_combinef_f *);
50 #define im_min(a, b) ((a) < (b) ? (a) : (b))
51 #define im_max(a, b) ((a) > (b) ? (a) : (b))
55 extern UTIL_table_t i_UTIL_table;
57 /* test if all channels are writable */
58 #define I_ALL_CHANNELS_WRITABLE(im) (((im)->ch_mask & 0xF) == 0xf)
60 typedef struct i_int_hline_seg_tag {
61 i_img_dim minx, x_limit;
64 typedef struct i_int_hline_entry_tag {
67 i_int_hline_seg segs[1];
70 /* represents a set of horizontal line segments to be filled in later */
71 typedef struct i_int_hlines_tag {
72 i_img_dim start_y, limit_y;
73 i_img_dim start_x, limit_x;
74 i_int_hline_entry **entries;
85 extern void i_int_init_hlines_img(i_int_hlines *hlines, i_img *img);
86 extern void i_int_hlines_add(i_int_hlines *hlines, i_img_dim y, i_img_dim minx, i_img_dim width);
87 extern void i_int_hlines_destroy(i_int_hlines *hlines);
89 extern void i_int_hlines_fill_color(i_img *im, i_int_hlines *hlines, const i_color *val);
90 extern void i_int_hlines_fill_fill(i_img *im, i_int_hlines *hlines, i_fill_t *fill);
92 #define I_LIMIT_8(x) ((x) < 0 ? 0 : (x) > 255 ? 255 : (x))
93 #define I_LIMIT_DOUBLE(x) ((x) < 0.0 ? 0.0 : (x) > 1.0 ? 1.0 : (x))
95 #define IM_STRING(x) #x
97 /* I considered using assert.h here, but perl does it's own thing with
98 assert() and the NDEBUG test is opposite to the direction I prefer */
100 extern void im_assert_fail(char const *, int, char const *);
101 #define im_assert(x) ((x) ? (void)(0) : im_assert_fail(__FILE__, __LINE__, IM_STRING(x)))
103 #define im_assert(x) (void)(0)
106 i_img_dim i_minx(i_img_dim a, i_img_dim b);
107 i_img_dim i_maxx(i_img_dim x, i_img_dim y);
108 i_img_dim i_abs(i_img_dim x);
110 #define i_min(a, b) i_minx((a), (b))
111 #define i_max(a, b) i_maxx((a), (b))
113 #define color_to_grey(col) ((col)->rgb.r * 0.222 + (col)->rgb.g * 0.707 + (col)->rgb.b * 0.071)
115 #define IM_ERROR_COUNT 20
116 typedef struct im_context_tag {
118 size_t error_alloc[IM_ERROR_COUNT];
119 i_errmsg error_stack[IM_ERROR_COUNT];
123 const char *filename;
127 /* file size limits */
128 i_img_dim max_width, max_height;
131 /* per context storage */
138 #define DEF_BYTES_LIMIT 0x40000000