move around - flatter.
[profile/ivi/evas.git] / src / lib / include / evas_macros.h
1 #ifndef EVAS_MACROS_H
2 #define EVAS_MACROS_H
3
4 #undef ABS
5 #define ABS(x) (((x) < 0) ? -(x) : (x))
6
7 #undef SGN
8 #define SGN(x) (((x) < 0) ? -1 : 1)
9
10 #undef MIN
11 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
12
13 #undef MAX
14 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
15
16 #define SWAP32(x) (x) = \
17    ((((x) & 0x000000ff ) << 24) | \
18     (((x) & 0x0000ff00 ) << 8)  | \
19     (((x) & 0x00ff0000 ) >> 8)  | \
20     (((x) & 0xff000000 ) >> 24))
21
22 #define SWAP16(x) (x) = \
23    ((((x) & 0x00ff ) << 8) | \
24     (((x) & 0xff00 ) >> 8))
25
26
27 #define SPANS_COMMON(x1, w1, x2, w2) \
28 (!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
29
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))))
32
33 #define RECTS_CLIP_TO_RECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch) \
34 { \
35    if (RECTS_INTERSECT(_x, _y, _w, _h, _cx, _cy, _cw, _ch)) \
36      { \
37         if (_x < (_cx)) \
38           { \
39              _w += _x - (_cx); \
40              _x = (_cx); \
41              if (_w < 0) _w = 0; \
42           } \
43         if ((_x + _w) > ((_cx) + (_cw))) \
44           _w = (_cx) + (_cw) - _x; \
45         if (_y < (_cy)) \
46           { \
47              _h += _y - (_cy); \
48              _y = (_cy); \
49              if (_h < 0) _h = 0; \
50           } \
51         if ((_y + _h) > ((_cy) + (_ch))) \
52           _h = (_cy) + (_ch) - _y; \
53      } \
54    else \
55      { \
56         _w = 0; _h = 0; \
57      } \
58 }
59
60
61 #define INTERP_VAL(out, in1, in2, in3, in4, interp_x, interp_y)    \
62    {                                                               \
63       int _v, _vv;                                                 \
64                                                                    \
65       _v = (256 - (interp_x)) * (in1);                             \
66       if ((interp_x) > 0) _v += (interp_x) * (in2);                \
67       _v *= (256 - (interp_y));                                    \
68       if ((interp_y) > 0)                                          \
69         {                                                          \
70            _vv = (256 - (interp_x)) * (in3);                       \
71            if ((interp_x) > 0) _vv += (interp_x) * (in4);          \
72            _vv *= (interp_y);                                      \
73            (out) = ((_v + _vv) >> 16);                             \
74         }                                                          \
75       else (out) = (_v >> 16);                                     \
76    }
77
78 #define INTERP_2(in1, in2, interp, interp_inv) \
79    ((in1 * interp_inv) + (in2 * interp)) >> 8
80
81
82 #define CONVERT_LOOP_START_ROT_0() \
83    src_ptr = src; \
84    for (y = 0; y < h; y++) \
85      { \
86         for (x = 0; x < w; x++) \
87           {
88
89 #define CONVERT_LOOP_END_ROT_0() \
90              dst_ptr++; \
91              src_ptr++; \
92           } \
93         src_ptr += src_jump; \
94         dst_ptr += dst_jump; \
95      }
96
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++) \
100      { \
101         for (x = 0; x < w; x++) \
102           {
103
104 #define CONVERT_LOOP_END_ROT_180() \
105              dst_ptr++; \
106              src_ptr--; \
107           } \
108         src_ptr = src + (w - 1) + ((h - y - 2) * (w + src_jump)); \
109         dst_ptr += dst_jump; \
110      }
111
112 #define CONVERT_LOOP_START_ROT_270() \
113    src_ptr = src + ((w - 1) * (h + src_jump)); \
114    for (y = 0; y < h; y++) \
115      { \
116         for (x = 0; x < w; x++) \
117           {
118
119 #define CONVERT_LOOP_END_ROT_270() \
120              dst_ptr++; \
121              src_ptr -= (h + src_jump); \
122           } \
123         src_ptr = src + ((w - 1) * (h + src_jump)) + (y + 1); \
124         dst_ptr += dst_jump; \
125      }
126
127 #define CONVERT_LOOP_START_ROT_90() \
128    src_ptr = src + (h - 1); \
129    for (y = 0; y < h; y++) \
130      { \
131         for (x = 0; x < w; x++) \
132           {
133
134 #define CONVERT_LOOP_END_ROT_90() \
135              dst_ptr++; \
136              src_ptr += (h + src_jump); \
137           } \
138         src_ptr = src + (h - 1) - y - 1; \
139         dst_ptr += dst_jump; \
140      }
141
142 #define CONVERT_LOOP2_START_ROT_0() \
143    src_ptr = src; \
144    for (y = 0; y < h; y++) \
145      { \
146         for (x = 0; x < w; x++) \
147           {
148
149 #define CONVERT_LOOP2_INC_ROT_0() \
150 src_ptr++; \
151 x++;
152
153 #define CONVERT_LOOP2_END_ROT_0() \
154              dst_ptr+=2; \
155              src_ptr++; \
156           } \
157         src_ptr += src_jump; \
158         dst_ptr += dst_jump; \
159      }
160
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++) \
164      { \
165         for (x = 0; x < w; x++) \
166           {
167
168 #define CONVERT_LOOP2_INC_ROT_180() \
169 src_ptr--; \
170 x++;
171
172 #define CONVERT_LOOP2_END_ROT_180() \
173              dst_ptr+=2; \
174              src_ptr--; \
175           } \
176         src_ptr = src + (w - 1) + ((h - y - 2) * (w + src_jump)); \
177         dst_ptr += dst_jump; \
178      }
179
180 #define CONVERT_LOOP2_START_ROT_270() \
181    src_ptr = src + ((w - 1) * (h + src_jump)); \
182    for (y = 0; y < h; y++) \
183      { \
184         for (x = 0; x < w; x++) \
185           {
186
187 #define CONVERT_LOOP2_INC_ROT_270() \
188 src_ptr -= (h + src_jump); \
189 x++;
190
191 #define CONVERT_LOOP2_END_ROT_270() \
192              dst_ptr+=2; \
193              src_ptr -= (h + src_jump); \
194           } \
195         src_ptr = src + ((w - 1) * (h + src_jump)) + (y + 1); \
196         dst_ptr += dst_jump; \
197      }
198
199 #define CONVERT_LOOP2_START_ROT_90() \
200    src_ptr = src + (h - 1); \
201    for (y = 0; y < h; y++) \
202      { \
203         for (x = 0; x < w; x++) \
204           {
205
206 #define CONVERT_LOOP2_INC_ROT_90() \
207 src_ptr += (h + src_jump); \
208 x++;
209
210 #define CONVERT_LOOP2_END_ROT_90() \
211              dst_ptr+=2; \
212              src_ptr += (h + src_jump); \
213           } \
214         src_ptr = src + (h - 1) - y - 1; \
215         dst_ptr += dst_jump; \
216      }
217
218 #endif