]> mj.ucw.cz Git - libucw.git/blob - images/image-walk.h
Released as 6.5.17.
[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
87 #ifdef IMAGE_WALK_FUNC_NAME
88 IMAGE_WALK_FUNC_NAME
89 #else
90 P(walk)
91 #endif
92     (struct image *P(img)
93 #   ifdef IMAGE_WALK_DOUBLE
94     , struct image *P(sec_img)
95 #   endif
96 #   ifdef IMAGE_WALK_EXTRA_ARGS
97     , IMAGE_WALK_EXTRA_ARGS
98 #   endif
99     )
100 #endif
101 {
102   uint P(cols) = IMAGE_WALK_COLS;
103   uint P(rows) = IMAGE_WALK_ROWS;
104 # if IMAGE_WALK_UNROLL > 1
105   uint P(cols_unroll_block_count) = P(cols) / IMAGE_WALK_UNROLL;
106   uint P(cols_unroll_end_count) = P(cols) % IMAGE_WALK_UNROLL;
107 # endif
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;
115 # endif
116   IMAGE_WALK_DO_START;
117   while (P(rows)--)
118     {
119       IMAGE_WALK_DO_ROW_START;
120 #     if IMAGE_WALK_UNROLL == 1
121       for (uint P(_i) = P(cols); P(_i)--; )
122 #     else
123       for (uint P(_i) = P(cols_unroll_block_count); P(_i)--; )
124 #     endif
125         {
126 #         if IMAGE_WALK_UNROLL >= 4
127           IMAGE_WALK__STEP;
128           IMAGE_WALK__STEP;
129 #         endif
130 #         if IMAGE_WALK_UNROLL >= 2
131           IMAGE_WALK__STEP;
132 #         endif
133           IMAGE_WALK__STEP;
134         }
135 #     if IMAGE_WALK_UNROLL > 1
136       for (uint P(_i) = P(cols_unroll_end_count); P(_i)--; )
137         {
138           IMAGE_WALK__STEP;
139         }
140 #     endif
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));
145 #     endif
146     }
147   IMAGE_WALK_DO_END;
148 }
149
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
174 #undef P