Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
fhmtgenlow.1.c
1/*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
37#include "allheaders.h"
38
39static void fhmt_1_0(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
40static void fhmt_1_1(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
41static void fhmt_1_2(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
42static void fhmt_1_3(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
43static void fhmt_1_4(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
44static void fhmt_1_5(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
45static void fhmt_1_6(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
46static void fhmt_1_7(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
47static void fhmt_1_8(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
48static void fhmt_1_9(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
49
50
51/*---------------------------------------------------------------------*
52 * Fast hmt dispatcher *
53 *---------------------------------------------------------------------*/
59l_int32
60fhmtgen_low_1(l_uint32 *datad,
61 l_int32 w,
62 l_int32 h,
63 l_int32 wpld,
64 l_uint32 *datas,
65 l_int32 wpls,
66 l_int32 index)
67{
68
69 switch (index)
70 {
71 case 0:
72 fhmt_1_0(datad, w, h, wpld, datas, wpls);
73 break;
74 case 1:
75 fhmt_1_1(datad, w, h, wpld, datas, wpls);
76 break;
77 case 2:
78 fhmt_1_2(datad, w, h, wpld, datas, wpls);
79 break;
80 case 3:
81 fhmt_1_3(datad, w, h, wpld, datas, wpls);
82 break;
83 case 4:
84 fhmt_1_4(datad, w, h, wpld, datas, wpls);
85 break;
86 case 5:
87 fhmt_1_5(datad, w, h, wpld, datas, wpls);
88 break;
89 case 6:
90 fhmt_1_6(datad, w, h, wpld, datas, wpls);
91 break;
92 case 7:
93 fhmt_1_7(datad, w, h, wpld, datas, wpls);
94 break;
95 case 8:
96 fhmt_1_8(datad, w, h, wpld, datas, wpls);
97 break;
98 case 9:
99 fhmt_1_9(datad, w, h, wpld, datas, wpls);
100 break;
101 }
102
103 return 0;
104}
105
106
107/*--------------------------------------------------------------------------*
108 * Low-level auto-generated static routines *
109 *--------------------------------------------------------------------------*/
110/*
111 * N.B. In all the low-level routines, the part of the image
112 * that is accessed has been clipped by 32 pixels on
113 * all four sides. This is done in the higher level
114 * code by redefining w and h smaller and by moving the
115 * start-of-image pointers up to the beginning of this
116 * interior rectangle.
117 */
118static void
119fhmt_1_0(l_uint32 *datad,
120 l_int32 w,
121 l_int32 h,
122 l_int32 wpld,
123 l_uint32 *datas,
124 l_int32 wpls)
125{
126l_int32 i;
127l_int32 j, pwpls;
128l_uint32 *sptr, *dptr;
129
130 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
131
132 for (i = 0; i < h; i++) {
133 sptr = datas + i * wpls;
134 dptr = datad + i * wpld;
135 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
136 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
137 (~*(sptr - wpls)) &
138 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
139 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
140 (*sptr) &
141 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
142 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
143 (~*(sptr + wpls)) &
144 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31));
145 }
146 }
147}
148
149static void
150fhmt_1_1(l_uint32 *datad,
151 l_int32 w,
152 l_int32 h,
153 l_int32 wpld,
154 l_uint32 *datas,
155 l_int32 wpls)
156{
157l_int32 i;
158l_int32 j, pwpls;
159l_uint32 *sptr, *dptr;
160
161 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
162
163 for (i = 0; i < h; i++) {
164 sptr = datas + i * wpls;
165 dptr = datad + i * wpld;
166 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
167 *dptr = ((*(sptr) >> 1) | (*(sptr - 1) << 31)) &
168 (*sptr) &
169 ((*(sptr) << 1) | (*(sptr + 1) >> 31)) &
170 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
171 (~*(sptr + wpls)) &
172 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31));
173 }
174 }
175}
176
177static void
178fhmt_1_2(l_uint32 *datad,
179 l_int32 w,
180 l_int32 h,
181 l_int32 wpld,
182 l_uint32 *datas,
183 l_int32 wpls)
184{
185l_int32 i;
186l_int32 j, pwpls;
187l_uint32 *sptr, *dptr;
188
189 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
190
191 for (i = 0; i < h; i++) {
192 sptr = datas + i * wpls;
193 dptr = datad + i * wpld;
194 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
195 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
196 (~*(sptr - wpls)) &
197 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
198 ((*(sptr) >> 1) | (*(sptr - 1) << 31)) &
199 (*sptr) &
200 ((*(sptr) << 1) | (*(sptr + 1) >> 31));
201 }
202 }
203}
204
205static void
206fhmt_1_3(l_uint32 *datad,
207 l_int32 w,
208 l_int32 h,
209 l_int32 wpld,
210 l_uint32 *datas,
211 l_int32 wpls)
212{
213l_int32 i;
214l_int32 j, pwpls;
215l_uint32 *sptr, *dptr;
216
217 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
218
219 for (i = 0; i < h; i++) {
220 sptr = datas + i * wpls;
221 dptr = datad + i * wpld;
222 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
223 *dptr = (*(sptr - wpls)) &
224 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
225 (*sptr) &
226 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
227 (*(sptr + wpls)) &
228 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31));
229 }
230 }
231}
232
233static void
234fhmt_1_4(l_uint32 *datad,
235 l_int32 w,
236 l_int32 h,
237 l_int32 wpld,
238 l_uint32 *datas,
239 l_int32 wpls)
240{
241l_int32 i;
242l_int32 j, pwpls;
243l_uint32 *sptr, *dptr;
244
245 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
246
247 for (i = 0; i < h; i++) {
248 sptr = datas + i * wpls;
249 dptr = datad + i * wpld;
250 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
251 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
252 (*(sptr - wpls)) &
253 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
254 (*sptr) &
255 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
256 (*(sptr + wpls));
257 }
258 }
259}
260
261static void
262fhmt_1_5(l_uint32 *datad,
263 l_int32 w,
264 l_int32 h,
265 l_int32 wpld,
266 l_uint32 *datas,
267 l_int32 wpls)
268{
269l_int32 i;
270l_int32 j, pwpls;
271l_uint32 *sptr, *dptr;
272l_int32 wpls2, wpls3, wpls4;
273l_int32 wpls5, wpls6;
274
275 wpls2 = 2 * wpls;
276 wpls3 = 3 * wpls;
277 wpls4 = 4 * wpls;
278 wpls5 = 5 * wpls;
279 wpls6 = 6 * wpls;
280 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
281
282 for (i = 0; i < h; i++) {
283 sptr = datas + i * wpls;
284 dptr = datad + i * wpld;
285 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
286 *dptr = ((~*(sptr - wpls6) << 1) | (~*(sptr - wpls6 + 1) >> 31)) &
287 ((*(sptr - wpls6) << 3) | (*(sptr - wpls6 + 1) >> 29)) &
288 (~*(sptr - wpls2)) &
289 ((*(sptr - wpls2) << 2) | (*(sptr - wpls2 + 1) >> 30)) &
290 ((~*(sptr + wpls2) >> 1) | (~*(sptr + wpls2 - 1) << 31)) &
291 ((*(sptr + wpls2) << 1) | (*(sptr + wpls2 + 1) >> 31)) &
292 ((~*(sptr + wpls6) >> 2) | (~*(sptr + wpls6 - 1) << 30)) &
293 (*(sptr + wpls6));
294 }
295 }
296}
297
298static void
299fhmt_1_6(l_uint32 *datad,
300 l_int32 w,
301 l_int32 h,
302 l_int32 wpld,
303 l_uint32 *datas,
304 l_int32 wpls)
305{
306l_int32 i;
307l_int32 j, pwpls;
308l_uint32 *sptr, *dptr;
309l_int32 wpls2;
310
311 wpls2 = 2 * wpls;
312 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
313
314 for (i = 0; i < h; i++) {
315 sptr = datas + i * wpls;
316 dptr = datad + i * wpld;
317 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
318 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
319 (~*(sptr - wpls)) &
320 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
321 ((~*(sptr - wpls) << 2) | (~*(sptr - wpls + 1) >> 30)) &
322 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
323 ((*(sptr) << 2) | (*(sptr + 1) >> 30)) &
324 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
325 ((*(sptr + wpls) << 1) | (*(sptr + wpls + 1) >> 31)) &
326 ((*(sptr + wpls) << 2) | (*(sptr + wpls + 1) >> 30)) &
327 ((~*(sptr + wpls2) >> 1) | (~*(sptr + wpls2 - 1) << 31)) &
328 (*(sptr + wpls2)) &
329 ((*(sptr + wpls2) << 1) | (*(sptr + wpls2 + 1) >> 31)) &
330 ((*(sptr + wpls2) << 2) | (*(sptr + wpls2 + 1) >> 30));
331 }
332 }
333}
334
335static void
336fhmt_1_7(l_uint32 *datad,
337 l_int32 w,
338 l_int32 h,
339 l_int32 wpld,
340 l_uint32 *datas,
341 l_int32 wpls)
342{
343l_int32 i;
344l_int32 j, pwpls;
345l_uint32 *sptr, *dptr;
346l_int32 wpls2;
347
348 wpls2 = 2 * wpls;
349 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
350
351 for (i = 0; i < h; i++) {
352 sptr = datas + i * wpls;
353 dptr = datad + i * wpld;
354 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
355 *dptr = ((~*(sptr - wpls) >> 2) | (~*(sptr - wpls - 1) << 30)) &
356 ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
357 (~*(sptr - wpls)) &
358 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
359 ((*(sptr) >> 2) | (*(sptr - 1) << 30)) &
360 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
361 ((*(sptr + wpls) >> 2) | (*(sptr + wpls - 1) << 30)) &
362 ((*(sptr + wpls) >> 1) | (*(sptr + wpls - 1) << 31)) &
363 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31)) &
364 ((*(sptr + wpls2) >> 2) | (*(sptr + wpls2 - 1) << 30)) &
365 ((*(sptr + wpls2) >> 1) | (*(sptr + wpls2 - 1) << 31)) &
366 (*(sptr + wpls2)) &
367 ((~*(sptr + wpls2) << 1) | (~*(sptr + wpls2 + 1) >> 31));
368 }
369 }
370}
371
372static void
373fhmt_1_8(l_uint32 *datad,
374 l_int32 w,
375 l_int32 h,
376 l_int32 wpld,
377 l_uint32 *datas,
378 l_int32 wpls)
379{
380l_int32 i;
381l_int32 j, pwpls;
382l_uint32 *sptr, *dptr;
383l_int32 wpls2;
384
385 wpls2 = 2 * wpls;
386 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
387
388 for (i = 0; i < h; i++) {
389 sptr = datas + i * wpls;
390 dptr = datad + i * wpld;
391 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
392 *dptr = ((~*(sptr - wpls2) >> 1) | (~*(sptr - wpls2 - 1) << 31)) &
393 (*(sptr - wpls2)) &
394 ((*(sptr - wpls2) << 1) | (*(sptr - wpls2 + 1) >> 31)) &
395 ((*(sptr - wpls2) << 2) | (*(sptr - wpls2 + 1) >> 30)) &
396 ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
397 ((*(sptr - wpls) << 1) | (*(sptr - wpls + 1) >> 31)) &
398 ((*(sptr - wpls) << 2) | (*(sptr - wpls + 1) >> 30)) &
399 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
400 ((*(sptr) << 2) | (*(sptr + 1) >> 30)) &
401 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
402 (~*(sptr + wpls)) &
403 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31)) &
404 ((~*(sptr + wpls) << 2) | (~*(sptr + wpls + 1) >> 30));
405 }
406 }
407}
408
409static void
410fhmt_1_9(l_uint32 *datad,
411 l_int32 w,
412 l_int32 h,
413 l_int32 wpld,
414 l_uint32 *datas,
415 l_int32 wpls)
416{
417l_int32 i;
418l_int32 j, pwpls;
419l_uint32 *sptr, *dptr;
420l_int32 wpls2;
421
422 wpls2 = 2 * wpls;
423 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
424
425 for (i = 0; i < h; i++) {
426 sptr = datas + i * wpls;
427 dptr = datad + i * wpld;
428 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
429 *dptr = ((*(sptr - wpls2) >> 2) | (*(sptr - wpls2 - 1) << 30)) &
430 ((*(sptr - wpls2) >> 1) | (*(sptr - wpls2 - 1) << 31)) &
431 (*(sptr - wpls2)) &
432 ((~*(sptr - wpls2) << 1) | (~*(sptr - wpls2 + 1) >> 31)) &
433 ((*(sptr - wpls) >> 2) | (*(sptr - wpls - 1) << 30)) &
434 ((*(sptr - wpls) >> 1) | (*(sptr - wpls - 1) << 31)) &
435 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
436 ((*(sptr) >> 2) | (*(sptr - 1) << 30)) &
437 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
438 ((~*(sptr + wpls) >> 2) | (~*(sptr + wpls - 1) << 30)) &
439 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
440 (~*(sptr + wpls)) &
441 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31));
442 }
443 }
444}
445