5 #define ABS(x) (((x) < 0) ? -(x) : (x))
8 #define SGN(x) (((x) < 0) ? -1 : 1)
11 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
14 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
16 #define SWAP32(x) (x) = \
17 ((((x) & 0x000000ff ) << 24) | \
18 (((x) & 0x0000ff00 ) << 8) | \
19 (((x) & 0x00ff0000 ) >> 8) | \
20 (((x) & 0xff000000 ) >> 24))
22 #define SWAP16(x) (x) = \
23 ((((x) & 0x00ff ) << 8) | \
24 (((x) & 0xff00 ) >> 8))
27 #define SPANS_COMMON(x1, w1, x2, w2) \
28 (!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
30 #define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
31 ((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
33 #define RECTS_CLIP_TO_RECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \
35 if (RECTS_INTERSECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch)) \
43 if ((_x + _w) > ((_cx) + (_cw))) \
44 _w = (_cx) + (_cw) - _x; \
51 if ((_y + _h) > ((_cy) + (_ch))) \
52 _h = (_cy) + (_ch) - _y; \
61 #define INTERP_VAL(out, in1, in2, in3, in4, interp_x, interp_y) \
65 _v = (256 - (interp_x)) * (in1); \
66 if ((interp_x) > 0) _v += (interp_x) * (in2); \
67 _v *= (256 - (interp_y)); \
70 _vv = (256 - (interp_x)) * (in3); \
71 if ((interp_x) > 0) _vv += (interp_x) * (in4); \
73 (out) = ((_v + _vv) >> 16); \
75 else (out) = (_v >> 16); \
78 #define INTERP_2(in1, in2, interp, interp_inv) \
79 ((in1 * interp_inv) + (in2 * interp)) >> 8
82 #define CONVERT_LOOP_START_ROT_0() \
84 for (y = 0; y < h; y++) \
86 for (x = 0; x < w; x++) \
89 #define CONVERT_LOOP_END_ROT_0() \
93 src_ptr += src_jump; \
94 dst_ptr += dst_jump; \
97 #define CONVERT_LOOP_START_ROT_180() \
98 src_ptr = src + (w - 1) + ((h - 1) * (w + src_jump)); \
99 for (y = 0; y < h; y++) \
101 for (x = 0; x < w; x++) \
104 #define CONVERT_LOOP_END_ROT_180() \
108 src_ptr = src + (w - 1) + ((h - y - 2) * (w + src_jump)); \
109 dst_ptr += dst_jump; \
112 #define CONVERT_LOOP_START_ROT_270() \
113 src_ptr = src + ((w - 1) * (h + src_jump)); \
114 for (y = 0; y < h; y++) \
116 for (x = 0; x < w; x++) \
119 #define CONVERT_LOOP_END_ROT_270() \
121 src_ptr -= (h + src_jump); \
123 src_ptr = src + ((w - 1) * (h + src_jump)) + (y + 1); \
124 dst_ptr += dst_jump; \
127 #define CONVERT_LOOP_START_ROT_90() \
128 src_ptr = src + (h - 1); \
129 for (y = 0; y < h; y++) \
131 for (x = 0; x < w; x++) \
134 #define CONVERT_LOOP_END_ROT_90() \
136 src_ptr += (h + src_jump); \
138 src_ptr = src + (h - 1) - y - 1; \
139 dst_ptr += dst_jump; \
142 #define CONVERT_LOOP2_START_ROT_0() \
144 for (y = 0; y < h; y++) \
146 for (x = 0; x < w; x++) \
149 #define CONVERT_LOOP2_INC_ROT_0() \
153 #define CONVERT_LOOP2_END_ROT_0() \
157 src_ptr += src_jump; \
158 dst_ptr += dst_jump; \
161 #define CONVERT_LOOP2_START_ROT_180() \
162 src_ptr = src + (w - 1) + ((h - 1) * (w + src_jump)); \
163 for (y = 0; y < h; y++) \
165 for (x = 0; x < w; x++) \
168 #define CONVERT_LOOP2_INC_ROT_180() \
172 #define CONVERT_LOOP2_END_ROT_180() \
176 src_ptr = src + (w - 1) + ((h - y - 2) * (w + src_jump)); \
177 dst_ptr += dst_jump; \
180 #define CONVERT_LOOP2_START_ROT_270() \
181 src_ptr = src + ((w - 1) * (h + src_jump)); \
182 for (y = 0; y < h; y++) \
184 for (x = 0; x < w; x++) \
187 #define CONVERT_LOOP2_INC_ROT_270() \
188 src_ptr -= (h + src_jump); \
191 #define CONVERT_LOOP2_END_ROT_270() \
193 src_ptr -= (h + src_jump); \
195 src_ptr = src + ((w - 1) * (h + src_jump)) + (y + 1); \
196 dst_ptr += dst_jump; \
199 #define CONVERT_LOOP2_START_ROT_90() \
200 src_ptr = src + (h - 1); \
201 for (y = 0; y < h; y++) \
203 for (x = 0; x < w; x++) \
206 #define CONVERT_LOOP2_INC_ROT_90() \
207 src_ptr += (h + src_jump); \
210 #define CONVERT_LOOP2_END_ROT_90() \
212 src_ptr += (h + src_jump); \
214 src_ptr = src + (h - 1) - y - 1; \
215 dst_ptr += dst_jump; \