44 #include <config_auto.h> 48 #include "allheaders.h" 80 l_int32 i, id, j, ws, hs, wpls, wpld, wplsi;
82 l_uint32 *datas, *datad, *lines, *lined;
85 PROCNAME(
"pixReduceBinary2");
88 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
92 return (
PIX *)ERROR_PTR(
"hs must be at least 2", procName, NULL);
93 wpls = pixGetWpl(
pixs);
97 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
98 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
99 pixCopyResolution(pixd,
pixs);
100 pixScaleResolution(pixd, 0.5, 0.5);
101 wpld = pixGetWpl(pixd);
107 return (
PIX *)ERROR_PTR(
"tab not made", procName, NULL);
111 wplsi = L_MIN(wpls, 2 * wpld);
113 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
114 lines = datas + i * wpls;
115 lined = datad +
id * wpld;
116 for (j = 0; j < wplsi; j++) {
118 word = word & 0xaaaaaaaa;
119 word = word | (word << 7);
121 byte1 = (word >> 8) & 0xff;
122 shortd = (tab[byte0] << 8) | tab[byte1];
127 if (!intab) LEPT_FREE(tab);
158 PIX *pix1, *pix2, *pix3, *pix4;
161 PROCNAME(
"pixReduceRankBinaryCascade");
164 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
165 if (pixGetDepth(
pixs) != 1)
166 return (
PIX *)ERROR_PTR(
"pixs must be binary", procName, NULL);
167 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
168 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", procName, NULL);
171 L_WARNING(
"no reduction because level1 not > 0\n", procName);
176 return (
PIX *)ERROR_PTR(
"tab not made", procName, NULL);
231 l_uint8 byte0, byte1;
234 l_int32 i, id, j, ws, hs, wpls, wpld, wplsi;
235 l_uint32 word1, word2, word3, word4;
236 l_uint32 *datas, *datad, *lines, *lined;
239 PROCNAME(
"pixReduceRankBinary2");
242 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
244 if (pixGetDepth(
pixs) != 1)
245 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
246 if (level < 1 || level > 4)
247 return (
PIX *)ERROR_PTR(
"level must be in set {1,2,3,4}",
252 return (
PIX *)ERROR_PTR(
"hs must be at least 2", procName, NULL);
253 wpls = pixGetWpl(
pixs);
257 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
258 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
259 pixCopyResolution(pixd,
pixs);
260 pixScaleResolution(pixd, 0.5, 0.5);
261 wpld = pixGetWpl(pixd);
267 return (
PIX *)ERROR_PTR(
"tab not made", procName, NULL);
271 wplsi = L_MIN(wpls, 2 * wpld);
277 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
278 lines = datas + i * wpls;
279 lined = datad +
id * wpld;
280 for (j = 0; j < wplsi; j++) {
281 word1 = *(lines + j);
282 word2 = *(lines + wpls + j);
285 word2 = word1 | word2;
286 word2 = word2 | (word2 << 1);
288 word2 = word2 & 0xaaaaaaaa;
289 word1 = word2 | (word2 << 7);
291 byte1 = (word1 >> 8) & 0xff;
292 shortd = (tab[byte0] << 8) | tab[byte1];
299 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
300 lines = datas + i * wpls;
301 lined = datad +
id * wpld;
302 for (j = 0; j < wplsi; j++) {
303 word1 = *(lines + j);
304 word2 = *(lines + wpls + j);
307 word3 = word1 & word2;
308 word3 = word3 | (word3 << 1);
309 word4 = word1 | word2;
310 word4 = word4 & (word4 << 1);
311 word2 = word3 | word4;
313 word2 = word2 & 0xaaaaaaaa;
314 word1 = word2 | (word2 << 7);
316 byte1 = (word1 >> 8) & 0xff;
317 shortd = (tab[byte0] << 8) | tab[byte1];
324 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
325 lines = datas + i * wpls;
326 lined = datad +
id * wpld;
327 for (j = 0; j < wplsi; j++) {
328 word1 = *(lines + j);
329 word2 = *(lines + wpls + j);
332 word3 = word1 & word2;
333 word3 = word3 | (word3 << 1);
334 word4 = word1 | word2;
335 word4 = word4 & (word4 << 1);
336 word2 = word3 & word4;
338 word2 = word2 & 0xaaaaaaaa;
339 word1 = word2 | (word2 << 7);
341 byte1 = (word1 >> 8) & 0xff;
342 shortd = (tab[byte0] << 8) | tab[byte1];
349 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
350 lines = datas + i * wpls;
351 lined = datad +
id * wpld;
352 for (j = 0; j < wplsi; j++) {
353 word1 = *(lines + j);
354 word2 = *(lines + wpls + j);
357 word2 = word1 & word2;
358 word2 = word2 & (word2 << 1);
360 word2 = word2 & 0xaaaaaaaa;
361 word1 = word2 | (word2 << 7);
363 byte1 = (word1 >> 8) & 0xff;
364 shortd = (tab[byte0] << 8) | tab[byte1];
371 if (!intab) LEPT_FREE(tab);
396 PROCNAME(
"makeSubsampleTab2x");
398 tab = (l_uint8 *) LEPT_CALLOC(256,
sizeof(l_uint8));
399 for (i = 0; i < 256; i++) {
400 tab[i] = ((i & 0x01) ) |
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixReduceRankBinary2(PIX *pixs, l_int32 level, l_uint8 *intab)
pixReduceRankBinary2()
PIX * pixReduceBinary2(PIX *pixs, l_uint8 *intab)
pixReduceBinary2()
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
#define SET_DATA_TWO_BYTES(pdata, n, val)
l_uint8 * makeSubsampleTab2x(void)
makeSubsampleTab2x()