]> git.imager.perl.org - imager.git/blob - imageri.h
0.78 release
[imager.git] / imageri.h
1 /* Declares utility functions useful across various files which
2    aren't meant to be available externally
3 */
4
5 #ifndef IMAGEI_H_
6 #define IMAGEI_H_
7
8 #include "imager.h"
9
10 /* wrapper functions that implement the floating point sample version of a 
11    function in terms of the 8-bit sample version
12 */
13 extern int i_ppixf_fp(i_img *im, int x, int y, const i_fcolor *pix);
14 extern int i_gpixf_fp(i_img *im, int x, int y, i_fcolor *pix);
15 extern int i_plinf_fp(i_img *im, int l, int r, int y, const i_fcolor *pix);
16 extern int i_glinf_fp(i_img *im, int l, int r, int y, i_fcolor *pix);
17 extern int i_gsampf_fp(i_img *im, int l, int r, int y, i_fsample_t *samp,
18                        int const *chans, int chan_count);
19
20 /* wrapper functions that forward palette calls to the underlying image,
21    assuming the underlying image is the first pointer in whatever
22    ext_data points at
23 */
24 extern int i_addcolors_forward(i_img *im, const i_color *, int count);
25 extern int i_getcolors_forward(i_img *im, int i, i_color *, int count);
26 extern int i_colorcount_forward(i_img *im);
27 extern int i_maxcolors_forward(i_img *im);
28 extern int i_findcolor_forward(i_img *im, const i_color *color, 
29                                i_palidx *entry);
30 extern int i_setcolors_forward(i_img *im, int index, const i_color *colors, 
31                                int count);
32
33 /* fallback handler for gsamp_bits */
34 extern int i_gsamp_bits_fb(i_img *im, int x, int r, int y, unsigned *samp, 
35                            const int *chans, int chan_count, int bits);
36
37 #define SampleFTo16(num) ((int)((num) * 65535.0 + 0.01))
38 /* we add that little bit to avoid rounding issues */
39 #define Sample16ToF(num) ((num) / 65535.0)
40
41 #define SampleFTo8(num) ((int)((num) * 255.0 + 0.01))
42 #define Sample8ToF(num) ((num) / 255.0)
43
44 #define Sample16To8(num) ((num) / 257)
45 #define Sample8To16(num) ((num) * 257)
46
47 extern void i_get_combine(int combine, i_fill_combine_f *, i_fill_combinef_f *);
48
49 #define im_min(a, b) ((a) < (b) ? (a) : (b))
50 #define im_max(a, b) ((a) > (b) ? (a) : (b))
51
52 #include "ext.h"
53
54 extern UTIL_table_t i_UTIL_table;
55
56 /* Ideally this will move into imconfig.h if we ever probe */
57 #if defined(_GNU_SOURCE) || __STDC_VERSION__ >= 199901L
58 /* snprintf() is part of C99 and provided by Glibc */
59 #define HAVE_SNPRINTF
60 #endif
61
62 /* test if all channels are writable */
63 #define I_ALL_CHANNELS_WRITABLE(im) (((im)->ch_mask & 0xF) == 0xf)
64
65 typedef struct i_int_hline_seg_tag {
66   int minx, x_limit;
67 } i_int_hline_seg;
68
69 typedef struct i_int_hline_entry_tag {
70   int count;
71   int alloc;
72   i_int_hline_seg segs[1];
73 } i_int_hline_entry;
74
75 /* represents a set of horizontal line segments to be filled in later */
76 typedef struct i_int_hlines_tag {
77   int start_y, limit_y;
78   int start_x, limit_x;
79   i_int_hline_entry **entries;
80 } i_int_hlines;
81
82 extern void 
83 i_int_init_hlines(
84                   i_int_hlines *hlines, 
85                   int start_y,
86                   int count_y, 
87                   int start_x, 
88                   int width_x
89                   );
90 extern void i_int_init_hlines_img(i_int_hlines *hlines, i_img *img);
91 extern void i_int_hlines_add(i_int_hlines *hlines, int y, int minx, int width);
92 extern void i_int_hlines_destroy(i_int_hlines *hlines);
93
94 extern void i_int_hlines_fill_color(i_img *im, i_int_hlines *hlines, const i_color *val);
95 extern void i_int_hlines_fill_fill(i_img *im, i_int_hlines *hlines, i_fill_t *fill);
96
97 #define I_LIMIT_8(x) ((x) < 0 ? 0 : (x) > 255 ? 255 : (x))
98 #define I_LIMIT_DOUBLE(x) ((x) < 0.0 ? 0.0 : (x) > 1.0 ? 1.0 : (x))
99
100 #define IM_STRING(x) #x
101
102 /* I considered using assert.h here, but perl does it's own thing with 
103    assert() and the NDEBUG test is opposite to the direction I prefer */
104 #ifdef IM_ASSERT
105 extern void im_assert_fail(char const *, int, char const *);
106 #define im_assert(x) ((x) ? (void)(0) : im_assert_fail(__FILE__, __LINE__, IM_STRING(x)))
107 #else
108 #define im_assert(x) (void)(0)
109 #endif 
110
111 i_img_dim i_minx(i_img_dim a, i_img_dim b);
112 i_img_dim i_maxx(i_img_dim x, i_img_dim y);
113
114 #define i_min(a, b) i_minx((a), (b))
115 #define i_max(a, b) i_maxx((a), (b))
116
117 #endif