]> mj.ucw.cz Git - libucw.git/blob - images/image-walk.h
sources backup... changed:
[libucw.git] / images / image-walk.h
1 /*
2  *      Image Library -- Pixels iteration
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef IMAGE_WALK_PREFIX
11 #  error Undefined IMAGE_WALK_PREFIX
12 #endif
13
14 #define P(x) IMAGE_WALK_PREFIX(x)
15
16 #if !defined(IMAGE_WALK_UNROLL)
17 #  define IMAGE_WALK_UNROLL 1
18 #elif IMAGE_WALK_UNROLL != 1 && IMAGE_WALK_UNROLL != 2 && IMAGE_WALK_UNROLL != 4
19 #  error IMAGE_WALK_UNROLL must be 1, 2 or 4
20 #endif
21
22 #ifndef IMAGE_WALK_IMAGE
23 #  define IMAGE_WALK_IMAGE P(img)
24 #endif
25 #ifndef IMAGE_WALK_PIXELS
26 #  define IMAGE_WALK_PIXELS (IMAGE_WALK_IMAGE->pixels)
27 #endif
28 #ifndef IMAGE_WALK_COLS
29 #  define IMAGE_WALK_COLS (IMAGE_WALK_IMAGE->cols)
30 #endif
31 #ifndef IMAGE_WALK_ROWS
32 #  define IMAGE_WALK_ROWS (IMAGE_WALK_IMAGE->rows)
33 #endif
34 #ifndef IMAGE_WALK_COL_STEP
35 #  define IMAGE_WALK_COL_STEP (IMAGE_WALK_IMAGE->pixel_size)
36 #endif
37 #ifndef IMAGE_WALK_ROW_STEP
38 #  define IMAGE_WALK_ROW_STEP (IMAGE_WALK_IMAGE->row_size)
39 #endif
40
41 #ifdef IMAGE_WALK_DOUBLE
42 #  ifndef IMAGE_WALK_SEC_IMAGE
43 #    define IMAGE_WALK_SEC_IMAGE P(sec_img)
44 #  endif
45 #  ifndef IMAGE_WALK_SEC_PIXELS
46 #    define IMAGE_WALK_SEC_PIXELS (IMAGE_WALK_SEC_IMAGE->pixels)
47 #  endif
48 #  ifndef IMAGE_WALK_SEC_COLS
49 #    define IMAGE_WALK_SEC_COLS (IMAGE_WALK_SEC_IMAGE->cols)
50 #  endif
51 #  ifndef IMAGE_WALK_SEC_ROWS
52 #    define IMAGE_WALK_SEC_ROWS (IMAGE_WALK_SEC_IMAGE->rows)
53 #  endif
54 #  ifndef IMAGE_WALK_SEC_COL_STEP
55 #    define IMAGE_WALK_SEC_COL_STEP (IMAGE_WALK_SEC_IMAGE->pixel_size)
56 #  endif
57 #  ifndef IMAGE_WALK_SEC_ROW_STEP
58 #    define IMAGE_WALK_SEC_ROW_STEP (IMAGE_WALK_SEC_IMAGE->row_size)
59 #  endif
60 #  define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step); P(sec_pos) += P(sec_col_step)
61 #else
62 #  define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step)
63 #endif
64
65 #ifndef IMAGE_WALK_DO_START
66 #  define IMAGE_WALK_DO_START
67 #endif
68
69 #ifndef IMAGE_WALK_DO_END
70 #  define IMAGE_WALK_DO_END
71 #endif
72
73 #ifndef IMAGE_WALK_DO_ROW_START
74 #  define IMAGE_WALK_DO_ROW_START
75 #endif
76
77 #ifndef IMAGE_WALK_DO_ROW_END
78 #  define IMAGE_WALK_DO_ROW_END
79 #endif
80
81 #ifndef IMAGE_WALK_DO_STEP
82 #  define IMAGE_WALK_DO_STEP
83 #endif
84
85 #ifndef IMAGE_WALK_INLINE
86 static void P(walk)
87     (struct image *P(img)
88 #   ifdef IMAGE_WALK_DOUBLE
89     , struct image *P(sec_img)
90 #   endif
91 #   ifdef IMAGE_WALK_EXTRA_ARGS
92     , IMAGE_WALK_EXTRA_ARGS
93 #   endif
94     )
95 #endif
96 {
97   uns P(cols) = IMAGE_WALK_COLS;
98   uns P(rows) = IMAGE_WALK_ROWS;
99 # if IMAGE_WALK_UNROLL > 1
100   uns P(cols_unroll_block_count) = P(cols) / IMAGE_WALK_UNROLL;
101   uns P(cols_unroll_end_count) = P(cols) % IMAGE_WALK_UNROLL;
102 # endif
103   byte *P(pos) = IMAGE_WALK_PIXELS, *P(row_start) = P(pos);
104   int P(col_step) = IMAGE_WALK_COL_STEP;
105   int P(row_step) = IMAGE_WALK_ROW_STEP;
106 # ifdef IMAGE_WALK_DOUBLE
107   byte *P(sec_pos) = IMAGE_WALK_SEC_PIXELS, *P(sec_row_start) = P(sec_pos);
108   int P(sec_col_step) = IMAGE_WALK_SEC_COL_STEP;
109   int P(sec_row_step) = IMAGE_WALK_SEC_ROW_STEP;
110 # endif
111   IMAGE_WALK_DO_START;
112   while (P(rows)--)
113     {
114       IMAGE_WALK_DO_ROW_START;
115 #     if IMAGE_WALK_UNROLL == 1
116       for (uns P(_i) = P(cols); P(_i)--; )
117 #     else
118       for (uns P(_i) = P(cols_unroll_block_count); P(_i)--; )
119 #     endif
120         {
121 #         if IMAGE_WALK_UNROLL >= 4
122           IMAGE_WALK__STEP;
123           IMAGE_WALK__STEP;
124 #         endif
125 #         if IMAGE_WALK_UNROLL >= 2
126           IMAGE_WALK__STEP;
127 #         endif
128           IMAGE_WALK__STEP;
129         }
130 #     if IMAGE_WALK_UNROLL > 1
131       for (uns P(_i) = P(cols_unroll_end_count); P(_i)--; )
132         {
133           IMAGE_WALK__STEP;
134         }
135 #     endif
136       IMAGE_WALK_DO_ROW_END;
137       P(pos) = (P(row_start) += P(row_step));
138 #     ifdef IMAGE_WALK_DOUBLE
139       P(sec_pos) = (P(sec_row_start) += P(sec_row_step));
140 #     endif
141     }
142   IMAGE_WALK_DO_END;
143 }
144
145 #undef IMAGE_WALK_PREFIX
146 #undef IMAGE_WALK_INLINE
147 #undef IMAGE_WALK_UNROLL
148 #undef IMAGE_WALK_DOUBLE
149 #undef IMAGE_WALK_EXTRA_ARGS
150 #undef IMAGE_WALK_IMAGE
151 #undef IMAGE_WALK_PIXELS
152 #undef IMAGE_WALK_COLS
153 #undef IMAGE_WALK_ROWS
154 #undef IMAGE_WALK_COL_STEP
155 #undef IMAGE_WALK_ROW_STEP
156 #undef IMAGE_WALK_SEC_IMAGE
157 #undef IMAGE_WALK_SEC_PIXELS
158 #undef IMAGE_WALK_SEC_COLS
159 #undef IMAGE_WALK_SEC_ROWS
160 #undef IMAGE_WALK_SEC_COL_STEP
161 #undef IMAGE_WALK_SEC_ROW_STEP
162 #undef IMAGE_WALK_DO_START
163 #undef IMAGE_WALK_DO_END
164 #undef IMAGE_WALK_DO_ROW_START
165 #undef IMAGE_WALK_DO_ROW_END
166 #undef IMAGE_WALK_DO_STEP
167 #undef IMAGE_WALK__STEP
168 #undef P