Leptonica  1.82.0
Image processing and image analysis suite
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 
39 static void fhmt_1_0(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
40 static void fhmt_1_1(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
41 static void fhmt_1_2(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
42 static void fhmt_1_3(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
43 static void fhmt_1_4(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
44 static void fhmt_1_5(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
45 static void fhmt_1_6(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
46 static void fhmt_1_7(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
47 static void fhmt_1_8(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
48 static void fhmt_1_9(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *, l_int32);
49 
50 
51 /*---------------------------------------------------------------------*
52  * Fast hmt dispatcher *
53  *---------------------------------------------------------------------*/
59 l_int32
60 fhmtgen_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  */
118 static void
119 fhmt_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 {
126 l_int32 i;
127 l_int32 j, pwpls;
128 l_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 
149 static void
150 fhmt_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 {
157 l_int32 i;
158 l_int32 j, pwpls;
159 l_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 
177 static void
178 fhmt_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 {
185 l_int32 i;
186 l_int32 j, pwpls;
187 l_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 
205 static void
206 fhmt_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 {
213 l_int32 i;
214 l_int32 j, pwpls;
215 l_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 
233 static void
234 fhmt_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 {
241 l_int32 i;
242 l_int32 j, pwpls;
243 l_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 
261 static void
262 fhmt_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 {
269 l_int32 i;
270 l_int32 j, pwpls;
271 l_uint32 *sptr, *dptr;
272 l_int32 wpls2, wpls3, wpls4;
273 l_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 
298 static void
299 fhmt_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 {
306 l_int32 i;
307 l_int32 j, pwpls;
308 l_uint32 *sptr, *dptr;
309 l_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 
335 static void
336 fhmt_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 {
343 l_int32 i;
344 l_int32 j, pwpls;
345 l_uint32 *sptr, *dptr;
346 l_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 
372 static void
373 fhmt_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 {
380 l_int32 i;
381 l_int32 j, pwpls;
382 l_uint32 *sptr, *dptr;
383 l_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 
409 static void
410 fhmt_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 {
417 l_int32 i;
418 l_int32 j, pwpls;
419 l_uint32 *sptr, *dptr;
420 l_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