44 #include "allheaders.h" 77 l_int32 i, id, j, ws, hs, wpls, wpld, wplsi;
79 l_uint32 *datas, *datad, *lines, *lined;
82 PROCNAME(
"pixReduceBinary2");
85 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", procName, NULL);
89 return (
PIX *)ERROR_PTR(
"hs must be at least 2", procName, NULL);
90 wpls = pixGetWpl(
pixs);
93 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
94 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
95 pixCopyResolution(pixd,
pixs);
96 pixScaleResolution(pixd, 0.5, 0.5);
97 wpld = pixGetWpl(pixd);
103 return (
PIX *)ERROR_PTR(
"tab not made", procName, NULL);
107 wplsi = L_MIN(wpls, 2 * wpld);
109 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
110 lines = datas + i * wpls;
111 lined = datad +
id * wpld;
112 for (j = 0; j < wplsi; j++) {
114 word = word & 0xaaaaaaaa;
115 word = word | (word << 7);
117 byte1 = (word >> 8) & 0xff;
118 shortd = (tab[byte0] << 8) | tab[byte1];
123 if (!intab) LEPT_FREE(tab);
154 PIX *pix1, *pix2, *pix3, *pix4;
157 PROCNAME(
"pixReduceRankBinaryCascade");
160 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
161 if (pixGetDepth(
pixs) != 1)
162 return (
PIX *)ERROR_PTR(
"pixs must be binary", procName, NULL);
163 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
164 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", procName, NULL);
167 L_WARNING(
"no reduction because level1 not > 0\n", procName);
172 return (
PIX *)ERROR_PTR(
"tab not made", procName, 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;
235 PROCNAME(
"pixReduceRankBinary2");
238 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
240 if (pixGetDepth(
pixs) != 1)
241 return (
PIX *)ERROR_PTR(
"pixs not binary", procName, NULL);
242 if (level < 1 || level > 4)
243 return (
PIX *)ERROR_PTR(
"level must be in set {1,2,3,4}",
248 return (
PIX *)ERROR_PTR(
"hs must be at least 2", procName, NULL);
249 wpls = pixGetWpl(
pixs);
252 if ((pixd =
pixCreate(ws / 2, hs / 2, 1)) == NULL)
253 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
254 pixCopyResolution(pixd,
pixs);
255 pixScaleResolution(pixd, 0.5, 0.5);
256 wpld = pixGetWpl(pixd);
262 return (
PIX *)ERROR_PTR(
"tab not made", procName, NULL);
266 wplsi = L_MIN(wpls, 2 * wpld);
272 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
273 lines = datas + i * wpls;
274 lined = datad +
id * wpld;
275 for (j = 0; j < wplsi; j++) {
276 word1 = *(lines + j);
277 word2 = *(lines + wpls + j);
280 word2 = word1 | word2;
281 word2 = word2 | (word2 << 1);
283 word2 = word2 & 0xaaaaaaaa;
284 word1 = word2 | (word2 << 7);
286 byte1 = (word1 >> 8) & 0xff;
287 shortd = (tab[byte0] << 8) | tab[byte1];
294 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
295 lines = datas + i * wpls;
296 lined = datad +
id * wpld;
297 for (j = 0; j < wplsi; j++) {
298 word1 = *(lines + j);
299 word2 = *(lines + wpls + j);
302 word3 = word1 & word2;
303 word3 = word3 | (word3 << 1);
304 word4 = word1 | word2;
305 word4 = word4 & (word4 << 1);
306 word2 = word3 | word4;
308 word2 = word2 & 0xaaaaaaaa;
309 word1 = word2 | (word2 << 7);
311 byte1 = (word1 >> 8) & 0xff;
312 shortd = (tab[byte0] << 8) | tab[byte1];
319 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
320 lines = datas + i * wpls;
321 lined = datad +
id * wpld;
322 for (j = 0; j < wplsi; j++) {
323 word1 = *(lines + j);
324 word2 = *(lines + wpls + j);
327 word3 = word1 & word2;
328 word3 = word3 | (word3 << 1);
329 word4 = word1 | word2;
330 word4 = word4 & (word4 << 1);
331 word2 = word3 & word4;
333 word2 = word2 & 0xaaaaaaaa;
334 word1 = word2 | (word2 << 7);
336 byte1 = (word1 >> 8) & 0xff;
337 shortd = (tab[byte0] << 8) | tab[byte1];
344 for (i = 0,
id = 0; i < hs - 1; i += 2,
id++) {
345 lines = datas + i * wpls;
346 lined = datad +
id * wpld;
347 for (j = 0; j < wplsi; j++) {
348 word1 = *(lines + j);
349 word2 = *(lines + wpls + j);
352 word2 = word1 & word2;
353 word2 = word2 & (word2 << 1);
355 word2 = word2 & 0xaaaaaaaa;
356 word1 = word2 | (word2 << 7);
358 byte1 = (word1 >> 8) & 0xff;
359 shortd = (tab[byte0] << 8) | tab[byte1];
366 if (!intab) LEPT_FREE(tab);
389 PROCNAME(
"makeSubsampleTab2x");
391 if ((tab = (l_uint8 *) LEPT_CALLOC(256,
sizeof(l_uint8))) == NULL)
392 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
394 for (i = 0; i < 256; i++)
395 tab[i] = ((i & 0x01) ) |
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
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 * pixReduceRankBinary2(PIX *pixs, l_int32 level, l_uint8 *intab)
pixReduceRankBinary2()
PIX * pixReduceBinary2(PIX *pixs, l_uint8 *intab)
pixReduceBinary2()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
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)
Permutation table for 2x rank binary reduction.