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 if (!pixs || pixGetDepth(pixs) != 1)
86 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
90 return (
PIX *)ERROR_PTR(
"hs must be at least 2", __func__, NULL);
91 wpls = pixGetWpl(pixs);
95 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
96 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
97 pixCopyResolution(pixd, pixs);
98 pixScaleResolution(pixd, 0.5, 0.5);
99 wpld = pixGetWpl(pixd);
105 return (
PIX *)ERROR_PTR(
"tab not made", __func__, NULL);
109 wplsi = L_MIN(wpls, 2 * wpld);
111 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
112 lines = datas + i * wpls;
113 lined = datad +
id * wpld;
114 for (j = 0; j < wplsi; j++) {
116 word = word & 0xaaaaaaaa;
117 word = word | (word << 7);
119 byte1 = (word >> 8) & 0xff;
120 shortd = (tab[byte0] << 8) | tab[byte1];
125 if (!intab) LEPT_FREE(tab);
156 PIX *pix1, *pix2, *pix3, *pix4;
160 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
161 if (pixGetDepth(pixs) != 1)
162 return (
PIX *)ERROR_PTR(
"pixs must be binary", __func__, NULL);
163 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
164 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", __func__, NULL);
167 L_WARNING(
"no reduction because level1 not > 0\n", __func__);
172 return (
PIX *)ERROR_PTR(
"tab not made", __func__, NULL);
227 l_uint8 byte0, byte1;
230 l_int32 i, id, j, ws, hs, wpls, wpld, wplsi;
231 l_uint32 word1, word2, word3, word4;
232 l_uint32 *datas, *datad, *lines, *lined;
236 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
238 if (pixGetDepth(pixs) != 1)
239 return (
PIX *)ERROR_PTR(
"pixs not binary", __func__, NULL);
240 if (level < 1 || level > 4)
241 return (
PIX *)ERROR_PTR(
"level must be in set {1,2,3,4}",
246 return (
PIX *)ERROR_PTR(
"hs must be at least 2", __func__, NULL);
247 wpls = pixGetWpl(pixs);
251 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
252 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
253 pixCopyResolution(pixd, pixs);
254 pixScaleResolution(pixd, 0.5, 0.5);
255 wpld = pixGetWpl(pixd);
261 return (
PIX *)ERROR_PTR(
"tab not made", __func__, NULL);
265 wplsi = L_MIN(wpls, 2 * wpld);
271 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
272 lines = datas + i * wpls;
273 lined = datad +
id * wpld;
274 for (j = 0; j < wplsi; j++) {
275 word1 = *(lines + j);
276 word2 = *(lines + wpls + j);
279 word2 = word1 | word2;
280 word2 = word2 | (word2 << 1);
282 word2 = word2 & 0xaaaaaaaa;
283 word1 = word2 | (word2 << 7);
285 byte1 = (word1 >> 8) & 0xff;
286 shortd = (tab[byte0] << 8) | tab[byte1];
293 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
294 lines = datas + i * wpls;
295 lined = datad +
id * wpld;
296 for (j = 0; j < wplsi; j++) {
297 word1 = *(lines + j);
298 word2 = *(lines + wpls + j);
301 word3 = word1 & word2;
302 word3 = word3 | (word3 << 1);
303 word4 = word1 | word2;
304 word4 = word4 & (word4 << 1);
305 word2 = word3 | word4;
307 word2 = word2 & 0xaaaaaaaa;
308 word1 = word2 | (word2 << 7);
310 byte1 = (word1 >> 8) & 0xff;
311 shortd = (tab[byte0] << 8) | tab[byte1];
318 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
319 lines = datas + i * wpls;
320 lined = datad +
id * wpld;
321 for (j = 0; j < wplsi; j++) {
322 word1 = *(lines + j);
323 word2 = *(lines + wpls + j);
326 word3 = word1 & word2;
327 word3 = word3 | (word3 << 1);
328 word4 = word1 | word2;
329 word4 = word4 & (word4 << 1);
330 word2 = word3 & word4;
332 word2 = word2 & 0xaaaaaaaa;
333 word1 = word2 | (word2 << 7);
335 byte1 = (word1 >> 8) & 0xff;
336 shortd = (tab[byte0] << 8) | tab[byte1];
343 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
344 lines = datas + i * wpls;
345 lined = datad +
id * wpld;
346 for (j = 0; j < wplsi; j++) {
347 word1 = *(lines + j);
348 word2 = *(lines + wpls + j);
351 word2 = word1 & word2;
352 word2 = word2 & (word2 << 1);
354 word2 = word2 & 0xaaaaaaaa;
355 word1 = word2 | (word2 << 7);
357 byte1 = (word1 >> 8) & 0xff;
358 shortd = (tab[byte0] << 8) | tab[byte1];
365 if (!intab) LEPT_FREE(tab);
390 tab = (l_uint8 *) LEPT_CALLOC(256,
sizeof(l_uint8));
391 for (i = 0; i < 256; i++) {
392 tab[i] = ((i & 0x01) ) |
#define SET_DATA_TWO_BYTES(pdata, n, val)
PIX * pixReduceRankBinaryCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixReduceRankBinaryCascade()
l_uint8 * makeSubsampleTab2x(void)
makeSubsampleTab2x()
PIX * pixReduceBinary2(PIX *pixs, l_uint8 *intab)
pixReduceBinary2()
PIX * pixReduceRankBinary2(PIX *pixs, l_int32 level, l_uint8 *intab)
pixReduceRankBinary2()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()