comparison mupdf-source/thirdparty/leptonica/src/fliphmtgen.c.notused @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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
27 /*
28 * fliphmtgen.c.notused
29 *
30 * NOTE
31 * ================================================================
32 * This code has been retired from the library, along with the code
33 * in flipdetectdwa.c which uses it. It is no longer compiled.
34 * ================================================================
35 *
36 * DWA implementation of hit-miss transforms with auto-generated sels
37 * for pixOrientDetectDwa() and pixUpDownDetectDwa() in
38 * flipdetectdwa.c
39 *
40 * PIX *pixFlipFHMTGen()
41 * static l_int32 flipfhmtgen_low() -- dispatcher
42 * static void fhmt_1_0()
43 * static void fhmt_1_1()
44 * static void fhmt_1_2()
45 * static void fhmt_1_3()
46 *
47 * The code (slightly rearranged) was generated by prog/flipselgen.c
48 */
49
50 #ifdef HAVE_CONFIG_H
51 #include <config_auto.h>
52 #endif /* HAVE_CONFIG_H */
53
54 #include <string.h>
55 #include "allheaders.h"
56
57 static l_int32 NUM_SELS_GENERATED = 4;
58 static char SEL_NAMES[][10] = {"flipsel1",
59 "flipsel2",
60 "flipsel3",
61 "flipsel4"};
62
63 static l_int32 flipfhmtgen_low(l_uint32 *, l_int32, l_int32, l_int32,
64 l_uint32 *, l_int32, l_int32);
65
66 static void fhmt_1_0(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *,
67 l_int32);
68 static void fhmt_1_1(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *,
69 l_int32);
70 static void fhmt_1_2(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *,
71 l_int32);
72 static void fhmt_1_3(l_uint32 *, l_int32, l_int32, l_int32, l_uint32 *,
73 l_int32);
74
75 /*---------------------------------------------------------------------*
76 * Top-level hmt functions *
77 *---------------------------------------------------------------------*/
78 /*
79 * pixFlipFHMTGen()
80 *
81 * Input: pixd (usual 3 choices: null, == pixs, != pixs)
82 * pixs
83 * sel name (one of four defined in SEL_NAMES[])
84 * Return: pixd
85 *
86 * Notes:
87 * Action: hit-miss transform on pixs by the sel
88 * N.B.: the sel must have at least one hit, and it
89 * can have any number of misses.
90 */
91 PIX *
92 pixFlipFHMTGen(PIX *pixd,
93 PIX *pixs,
94 const char *selname)
95 {
96 l_int32 i, index, found, w, h, wpls, wpld;
97 l_uint32 *datad, *datas, *datat;
98 PIX *pixt;
99
100 PROCNAME("pixFlipFHMTGen");
101
102 if (!pixs)
103 return (PIX *)ERROR_PTR("pixs not defined", procName, pixd);
104 if (pixGetDepth(pixs) != 1)
105 return (PIX *)ERROR_PTR("pixs must be 1 bpp", procName, pixd);
106
107 found = FALSE;
108 for (i = 0; i < NUM_SELS_GENERATED; i++) {
109 if (strcmp(selname, SEL_NAMES[i]) == 0) {
110 found = TRUE;
111 index = i;
112 break;
113 }
114 }
115 if (found == FALSE)
116 return (PIX *)ERROR_PTR("sel index not found", procName, pixd);
117
118 if (pixd) {
119 if (!pixSizesEqual(pixs, pixd))
120 return (PIX *)ERROR_PTR("sizes not equal", procName, pixd);
121 } else {
122 if ((pixd = pixCreateTemplate(pixs)) == NULL)
123 return (PIX *)ERROR_PTR("pixd not made", procName, NULL);
124 }
125
126 wpls = pixGetWpl(pixs);
127 wpld = pixGetWpl(pixd);
128
129 /* The images must be surrounded with ADDED_BORDER white pixels,
130 * that we'll read from. We fabricate a "proper"
131 * image as the subimage within the border, having the
132 * following parameters: */
133 w = pixGetWidth(pixs) - 2 * ADDED_BORDER;
134 h = pixGetHeight(pixs) - 2 * ADDED_BORDER;
135 datas = pixGetData(pixs) + ADDED_BORDER * wpls + ADDED_BORDER / 32;
136 datad = pixGetData(pixd) + ADDED_BORDER * wpld + ADDED_BORDER / 32;
137
138 if (pixd == pixs) { /* need temp image if in-place */
139 if ((pixt = pixCopy(NULL, pixs)) == NULL)
140 return (PIX *)ERROR_PTR("pixt not made", procName, pixd);
141 datat = pixGetData(pixt) + ADDED_BORDER * wpls + ADDED_BORDER / 32;
142 flipfhmtgen_low(datad, w, h, wpld, datat, wpls, index);
143 pixDestroy(&pixt);
144 } else { /* simple and not in-place */
145 flipfhmtgen_low(datad, w, h, wpld, datas, wpls, index);
146 }
147
148 return pixd;
149 }
150
151
152 /*---------------------------------------------------------------------*
153 * Fast hmt dispatcher *
154 *---------------------------------------------------------------------*/
155 /*
156 * flipfhmtgen_low()
157 *
158 * A dispatcher to appropriate low-level code for flip hmt ops
159 */
160 static l_int32
161 flipfhmtgen_low(l_uint32 *datad,
162 l_int32 w,
163 l_int32 h,
164 l_int32 wpld,
165 l_uint32 *datas,
166 l_int32 wpls,
167 l_int32 index)
168 {
169
170 switch (index)
171 {
172 case 0:
173 fhmt_1_0(datad, w, h, wpld, datas, wpls);
174 break;
175 case 1:
176 fhmt_1_1(datad, w, h, wpld, datas, wpls);
177 break;
178 case 2:
179 fhmt_1_2(datad, w, h, wpld, datas, wpls);
180 break;
181 case 3:
182 fhmt_1_3(datad, w, h, wpld, datas, wpls);
183 break;
184 }
185
186 return 0;
187 }
188
189
190 /*--------------------------------------------------------------------------*
191 * Low-level auto-generated hmt routines *
192 *--------------------------------------------------------------------------*/
193 /*
194 * N.B. in all the low-level routines, the part of the image
195 * that is accessed has been clipped by ADDED_BORDER pixels
196 * on all four sides. This is done in the higher level
197 * code by redefining w and h smaller and by moving the
198 * start-of-image pointers up to the beginning of this
199 * interior rectangle.
200 */
201
202 static void
203 fhmt_1_0(l_uint32 *datad,
204 l_int32 w,
205 l_int32 h,
206 l_int32 wpld,
207 l_uint32 *datas,
208 l_int32 wpls)
209 {
210 l_int32 i;
211 l_int32 j, pwpls;
212 l_uint32 *sptr, *dptr;
213 l_int32 wpls2, wpls3;
214
215 wpls2 = 2 * wpls;
216 wpls3 = 3 * wpls;
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) >> 3) | (*(sptr - wpls - 1) << 29)) &
224 (~*(sptr - wpls)) &
225 ((~*(sptr - wpls) << 1) | (~*(sptr - wpls + 1) >> 31)) &
226 ((*(sptr) >> 3) | (*(sptr - 1) << 29)) &
227 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
228 (~*sptr) &
229 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
230 ((*(sptr + wpls) >> 3) | (*(sptr + wpls - 1) << 29)) &
231 (~*(sptr + wpls)) &
232 ((*(sptr + wpls2) >> 3) | (*(sptr + wpls2 - 1) << 29)) &
233 ((*(sptr + wpls3) >> 3) | (*(sptr + wpls3 - 1) << 29)) &
234 ((*(sptr + wpls3) >> 2) | (*(sptr + wpls3 - 1) << 30)) &
235 ((*(sptr + wpls3) >> 1) | (*(sptr + wpls3 - 1) << 31)) &
236 (*(sptr + wpls3)) &
237 ((*(sptr + wpls3) << 1) | (*(sptr + wpls3 + 1) >> 31)) &
238 ((*(sptr + wpls3) << 2) | (*(sptr + wpls3 + 1) >> 30));
239 }
240 }
241 }
242
243
244 static void
245 fhmt_1_1(l_uint32 *datad,
246 l_int32 w,
247 l_int32 h,
248 l_int32 wpld,
249 l_uint32 *datas,
250 l_int32 wpls)
251 {
252 l_int32 i;
253 l_int32 j, pwpls;
254 l_uint32 *sptr, *dptr;
255 l_int32 wpls2, wpls3;
256
257 wpls2 = 2 * wpls;
258 wpls3 = 3 * wpls;
259 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
260
261 for (i = 0; i < h; i++) {
262 sptr = datas + i * wpls;
263 dptr = datad + i * wpld;
264 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
265 *dptr = ((~*(sptr - wpls) >> 1) | (~*(sptr - wpls - 1) << 31)) &
266 (~*(sptr - wpls)) &
267 ((*(sptr - wpls) << 3) | (*(sptr - wpls + 1) >> 29)) &
268 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
269 (~*sptr) &
270 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
271 ((*(sptr) << 3) | (*(sptr + 1) >> 29)) &
272 (~*(sptr + wpls)) &
273 ((*(sptr + wpls) << 3) | (*(sptr + wpls + 1) >> 29)) &
274 ((*(sptr + wpls2) << 3) | (*(sptr + wpls2 + 1) >> 29)) &
275 ((*(sptr + wpls3) >> 2) | (*(sptr + wpls3 - 1) << 30)) &
276 ((*(sptr + wpls3) >> 1) | (*(sptr + wpls3 - 1) << 31)) &
277 (*(sptr + wpls3)) &
278 ((*(sptr + wpls3) << 1) | (*(sptr + wpls3 + 1) >> 31)) &
279 ((*(sptr + wpls3) << 2) | (*(sptr + wpls3 + 1) >> 30)) &
280 ((*(sptr + wpls3) << 3) | (*(sptr + wpls3 + 1) >> 29));
281 }
282 }
283 }
284
285
286 static void
287 fhmt_1_2(l_uint32 *datad,
288 l_int32 w,
289 l_int32 h,
290 l_int32 wpld,
291 l_uint32 *datas,
292 l_int32 wpls)
293 {
294 l_int32 i;
295 l_int32 j, pwpls;
296 l_uint32 *sptr, *dptr;
297 l_int32 wpls2, wpls3;
298
299 wpls2 = 2 * wpls;
300 wpls3 = 3 * wpls;
301 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
302
303 for (i = 0; i < h; i++) {
304 sptr = datas + i * wpls;
305 dptr = datad + i * wpld;
306 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
307 *dptr = ((*(sptr - wpls3) >> 3) | (*(sptr - wpls3 - 1) << 29)) &
308 ((*(sptr - wpls3) >> 2) | (*(sptr - wpls3 - 1) << 30)) &
309 ((*(sptr - wpls3) >> 1) | (*(sptr - wpls3 - 1) << 31)) &
310 (*(sptr - wpls3)) &
311 ((*(sptr - wpls3) << 1) | (*(sptr - wpls3 + 1) >> 31)) &
312 ((*(sptr - wpls3) << 2) | (*(sptr - wpls3 + 1) >> 30)) &
313 ((*(sptr - wpls2) >> 3) | (*(sptr - wpls2 - 1) << 29)) &
314 ((*(sptr - wpls) >> 3) | (*(sptr - wpls - 1) << 29)) &
315 (~*(sptr - wpls)) &
316 ((*(sptr) >> 3) | (*(sptr - 1) << 29)) &
317 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
318 (~*sptr) &
319 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
320 ((*(sptr + wpls) >> 3) | (*(sptr + wpls - 1) << 29)) &
321 (~*(sptr + wpls)) &
322 ((~*(sptr + wpls) << 1) | (~*(sptr + wpls + 1) >> 31));
323 }
324 }
325 }
326
327
328 static void
329 fhmt_1_3(l_uint32 *datad,
330 l_int32 w,
331 l_int32 h,
332 l_int32 wpld,
333 l_uint32 *datas,
334 l_int32 wpls)
335 {
336 l_int32 i;
337 l_int32 j, pwpls;
338 l_uint32 *sptr, *dptr;
339 l_int32 wpls2, wpls3;
340
341 wpls2 = 2 * wpls;
342 wpls3 = 3 * wpls;
343 pwpls = (l_uint32)(w + 31) / 32; /* proper wpl of src */
344
345 for (i = 0; i < h; i++) {
346 sptr = datas + i * wpls;
347 dptr = datad + i * wpld;
348 for (j = 0; j < pwpls; j++, sptr++, dptr++) {
349 *dptr = ((*(sptr - wpls3) >> 2) | (*(sptr - wpls3 - 1) << 30)) &
350 ((*(sptr - wpls3) >> 1) | (*(sptr - wpls3 - 1) << 31)) &
351 (*(sptr - wpls3)) &
352 ((*(sptr - wpls3) << 1) | (*(sptr - wpls3 + 1) >> 31)) &
353 ((*(sptr - wpls3) << 2) | (*(sptr - wpls3 + 1) >> 30)) &
354 ((*(sptr - wpls3) << 3) | (*(sptr - wpls3 + 1) >> 29)) &
355 ((*(sptr - wpls2) << 3) | (*(sptr - wpls2 + 1) >> 29)) &
356 (~*(sptr - wpls)) &
357 ((*(sptr - wpls) << 3) | (*(sptr - wpls + 1) >> 29)) &
358 ((~*(sptr) >> 1) | (~*(sptr - 1) << 31)) &
359 (~*sptr) &
360 ((~*(sptr) << 1) | (~*(sptr + 1) >> 31)) &
361 ((*(sptr) << 3) | (*(sptr + 1) >> 29)) &
362 ((~*(sptr + wpls) >> 1) | (~*(sptr + wpls - 1) << 31)) &
363 (~*(sptr + wpls)) &
364 ((*(sptr + wpls) << 3) | (*(sptr + wpls + 1) >> 29));
365 }
366 }
367 }