2 * Image Library -- Pixels iteration
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef IMAGE_WALK_PREFIX
11 # error Undefined IMAGE_WALK_PREFIX
14 #define P(x) IMAGE_WALK_PREFIX(x)
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
22 #ifndef IMAGE_WALK_IMAGE
23 # define IMAGE_WALK_IMAGE P(img)
25 #ifndef IMAGE_WALK_PIXELS
26 # define IMAGE_WALK_PIXELS (IMAGE_WALK_IMAGE->pixels)
28 #ifndef IMAGE_WALK_COLS
29 # define IMAGE_WALK_COLS (IMAGE_WALK_IMAGE->cols)
31 #ifndef IMAGE_WALK_ROWS
32 # define IMAGE_WALK_ROWS (IMAGE_WALK_IMAGE->rows)
34 #ifndef IMAGE_WALK_COL_STEP
35 # define IMAGE_WALK_COL_STEP (IMAGE_WALK_IMAGE->pixel_size)
37 #ifndef IMAGE_WALK_ROW_STEP
38 # define IMAGE_WALK_ROW_STEP (IMAGE_WALK_IMAGE->row_size)
41 #ifdef IMAGE_WALK_DOUBLE
42 # ifndef IMAGE_WALK_SEC_IMAGE
43 # define IMAGE_WALK_SEC_IMAGE P(sec_img)
45 # ifndef IMAGE_WALK_SEC_PIXELS
46 # define IMAGE_WALK_SEC_PIXELS (IMAGE_WALK_SEC_IMAGE->pixels)
48 # ifndef IMAGE_WALK_SEC_COLS
49 # define IMAGE_WALK_SEC_COLS (IMAGE_WALK_SEC_IMAGE->cols)
51 # ifndef IMAGE_WALK_SEC_ROWS
52 # define IMAGE_WALK_SEC_ROWS (IMAGE_WALK_SEC_IMAGE->rows)
54 # ifndef IMAGE_WALK_SEC_COL_STEP
55 # define IMAGE_WALK_SEC_COL_STEP (IMAGE_WALK_SEC_IMAGE->pixel_size)
57 # ifndef IMAGE_WALK_SEC_ROW_STEP
58 # define IMAGE_WALK_SEC_ROW_STEP (IMAGE_WALK_SEC_IMAGE->row_size)
60 # define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step); P(sec_pos) += P(sec_col_step)
62 # define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step)
65 #ifndef IMAGE_WALK_DO_START
66 # define IMAGE_WALK_DO_START
69 #ifndef IMAGE_WALK_DO_END
70 # define IMAGE_WALK_DO_END
73 #ifndef IMAGE_WALK_DO_ROW_START
74 # define IMAGE_WALK_DO_ROW_START
77 #ifndef IMAGE_WALK_DO_ROW_END
78 # define IMAGE_WALK_DO_ROW_END
81 #ifndef IMAGE_WALK_DO_STEP
82 # define IMAGE_WALK_DO_STEP
85 #ifndef IMAGE_WALK_INLINE
87 #ifdef IMAGE_WALK_FUNC_NAME
93 # ifdef IMAGE_WALK_DOUBLE
94 , struct image *P(sec_img)
96 # ifdef IMAGE_WALK_EXTRA_ARGS
97 , IMAGE_WALK_EXTRA_ARGS
102 uns P(cols) = IMAGE_WALK_COLS;
103 uns P(rows) = IMAGE_WALK_ROWS;
104 # if IMAGE_WALK_UNROLL > 1
105 uns P(cols_unroll_block_count) = P(cols) / IMAGE_WALK_UNROLL;
106 uns P(cols_unroll_end_count) = P(cols) % IMAGE_WALK_UNROLL;
108 byte *P(pos) = IMAGE_WALK_PIXELS, *P(row_start) = P(pos);
109 int P(col_step) = IMAGE_WALK_COL_STEP;
110 int P(row_step) = IMAGE_WALK_ROW_STEP;
111 # ifdef IMAGE_WALK_DOUBLE
112 byte *P(sec_pos) = IMAGE_WALK_SEC_PIXELS, *P(sec_row_start) = P(sec_pos);
113 int P(sec_col_step) = IMAGE_WALK_SEC_COL_STEP;
114 int P(sec_row_step) = IMAGE_WALK_SEC_ROW_STEP;
119 IMAGE_WALK_DO_ROW_START;
120 # if IMAGE_WALK_UNROLL == 1
121 for (uns P(_i) = P(cols); P(_i)--; )
123 for (uns P(_i) = P(cols_unroll_block_count); P(_i)--; )
126 # if IMAGE_WALK_UNROLL >= 4
130 # if IMAGE_WALK_UNROLL >= 2
135 # if IMAGE_WALK_UNROLL > 1
136 for (uns P(_i) = P(cols_unroll_end_count); P(_i)--; )
141 IMAGE_WALK_DO_ROW_END;
142 P(pos) = (P(row_start) += P(row_step));
143 # ifdef IMAGE_WALK_DOUBLE
144 P(sec_pos) = (P(sec_row_start) += P(sec_row_step));
150 #undef IMAGE_WALK_PREFIX
151 #undef IMAGE_WALK_FUNC_NAME
152 #undef IMAGE_WALK_INLINE
153 #undef IMAGE_WALK_UNROLL
154 #undef IMAGE_WALK_DOUBLE
155 #undef IMAGE_WALK_EXTRA_ARGS
156 #undef IMAGE_WALK_IMAGE
157 #undef IMAGE_WALK_PIXELS
158 #undef IMAGE_WALK_COLS
159 #undef IMAGE_WALK_ROWS
160 #undef IMAGE_WALK_COL_STEP
161 #undef IMAGE_WALK_ROW_STEP
162 #undef IMAGE_WALK_SEC_IMAGE
163 #undef IMAGE_WALK_SEC_PIXELS
164 #undef IMAGE_WALK_SEC_COLS
165 #undef IMAGE_WALK_SEC_ROWS
166 #undef IMAGE_WALK_SEC_COL_STEP
167 #undef IMAGE_WALK_SEC_ROW_STEP
168 #undef IMAGE_WALK_DO_START
169 #undef IMAGE_WALK_DO_END
170 #undef IMAGE_WALK_DO_ROW_START
171 #undef IMAGE_WALK_DO_ROW_END
172 #undef IMAGE_WALK_DO_STEP
173 #undef IMAGE_WALK__STEP