101#include <config_auto.h>
106#include "allheaders.h"
109 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
110 l_uint32 *bufs1, l_uint32 *bufs2,
111 l_int32 lowerclip, l_int32 upperclip);
113 l_int32 wpld, l_uint32 *datas, l_int32 d,
114 l_int32 wpls, l_int32 thresh);
115static void ditherTo2bppLow(l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld,
116 l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1,
117 l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38,
120 l_uint32 *bufs2, l_int32 *tabval,
121 l_int32 *tab38, l_int32 *tab14,
122 l_int32 lastlineflag);
124 l_int32 **ptab14, l_int32 cliptoblack,
125 l_int32 cliptowhite);
127 l_uint32 *datas, l_int32 wpls, l_int32 *tab);
129 l_uint32 *datas, l_int32 wpls, l_int32 *tab);
132 l_int32 outdepth,
PIXCMAP **pcmap);
134 l_float32 minfract, l_int32 maxsize,
138#define DEBUG_UNROLLING 0
178 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
179 if (pixGetDepth(pixs) != 8)
180 return (
PIX *)ERROR_PTR(
"must be 8 bpp for dithering", __func__, NULL);
209l_int32 w, h, d, wplt, wpld;
210l_uint32 *datat, *datad;
211l_uint32 *bufs1, *bufs2;
215 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
216 pixGetDimensions(pixs, &w, &h, &d);
218 return (
PIX *)ERROR_PTR(
"must be 8 bpp for dithering", __func__, NULL);
219 if (lowerclip < 0 || lowerclip > 255)
220 return (
PIX *)ERROR_PTR(
"invalid value for lowerclip", __func__, NULL);
221 if (upperclip < 0 || upperclip > 255)
222 return (
PIX *)ERROR_PTR(
"invalid value for upperclip", __func__, NULL);
224 if ((pixd = pixCreate(w, h, 1)) == NULL)
225 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
226 pixCopyResolution(pixd, pixs);
227 pixCopyInputFormat(pixd, pixs);
228 datad = pixGetData(pixd);
229 wpld = pixGetWpl(pixd);
234 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
236 datat = pixGetData(pixt);
237 wplt = pixGetWpl(pixt);
240 bufs1 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
241 bufs2 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
242 if (!bufs1 || !bufs2) {
247 return (
PIX *)ERROR_PTR(
"bufs1, bufs2 not both made", __func__, NULL);
251 lowerclip, upperclip);
281 memcpy(bufs2, datas, 4 * wpls);
282 for (i = 0; i < h - 1; i++) {
283 memcpy(bufs1, bufs2, 4 * wpls);
284 memcpy(bufs2, datas + (i + 1) * wpls, 4 * wpls);
285 lined = datad + i * wpld;
290 memcpy(bufs1, bufs2, 4 * wpls);
291 lined = datad + (h - 1) * wpld;
328 l_int32 lastlineflag)
332l_uint8 fval1, fval2, rval, bval, dval;
334 if (lastlineflag == 0) {
335 for (j = 0; j < w - 1; j++) {
338 if ((eval = 255 - oval) > upperclip) {
340 fval1 = (3 * eval) / 8;
343 rval = L_MAX(0, rval - fval1);
346 bval = L_MAX(0, bval - fval1);
349 dval = L_MAX(0, dval - fval2);
354 if (oval > lowerclip) {
356 fval1 = (3 * oval) / 8;
359 rval = L_MIN(255, rval + fval1);
362 bval = L_MIN(255, bval + fval1);
365 dval = L_MIN(255, dval + fval2);
374 if ((eval = 255 - oval) > upperclip) {
376 fval1 = (3 * eval) / 8;
378 bval = L_MAX(0, bval - fval1);
383 if (oval > lowerclip) {
385 fval1 = (3 * oval) / 8;
387 bval = L_MIN(255, bval + fval1);
392 for (j = 0; j < w - 1; j++) {
395 if ((eval = 255 - oval) > upperclip) {
397 fval1 = (3 * eval) / 8;
399 rval = L_MAX(0, rval - fval1);
404 if (oval > lowerclip) {
406 fval1 = (3 * oval) / 8;
408 rval = L_MIN(255, rval + fval1);
446l_int32 d, w, h, wplt, wpld;
447l_uint32 *datat, *datad;
451 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
452 pixGetDimensions(pixs, &w, &h, &d);
453 if (d != 4 && d != 8)
454 return (
PIX *)ERROR_PTR(
"pixs must be 4 or 8 bpp", __func__, NULL);
456 return (
PIX *)ERROR_PTR(
"thresh must be non-negative", __func__, NULL);
457 if (d == 4 && thresh > 16)
458 return (
PIX *)ERROR_PTR(
"4 bpp thresh not in {0-16}", __func__, NULL);
459 if (d == 8 && thresh > 256)
460 return (
PIX *)ERROR_PTR(
"8 bpp thresh not in {0-256}", __func__, NULL);
462 if ((pixd = pixCreate(w, h, 1)) == NULL)
463 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
464 pixCopyResolution(pixd, pixs);
465 pixCopyInputFormat(pixd, pixs);
466 datad = pixGetData(pixd);
467 wpld = pixGetWpl(pixd);
472 datat = pixGetData(pixt);
473 wplt = pixGetWpl(pixt);
474 if (pixGetColormap(pixs) && d == 4) {
502l_uint32 *lines, *lined;
504 for (i = 0; i < h; i++) {
505 lines = datas + i * wpls;
506 lined = datad + i * wpld;
507 thresholdToBinaryLineLow(lined, w, lines, d, thresh);
517thresholdToBinaryLineLow(l_uint32 *lined,
523l_int32 j, k, gval, scount, dcount;
524l_uint32 sword, dword;
530 for (j = 0, scount = 0, dcount = 0; j + 31 < w; j += 32) {
532 for (k = 0; k < 4; k++) {
533 sword = lines[scount++];
535 gval = (sword >> 28) & 0xf;
542 dword |= ((gval - thresh) >> 24) & 128;
543 gval = (sword >> 24) & 0xf;
544 dword |= ((gval - thresh) >> 25) & 64;
545 gval = (sword >> 20) & 0xf;
546 dword |= ((gval - thresh) >> 26) & 32;
547 gval = (sword >> 16) & 0xf;
548 dword |= ((gval - thresh) >> 27) & 16;
549 gval = (sword >> 12) & 0xf;
550 dword |= ((gval - thresh) >> 28) & 8;
551 gval = (sword >> 8) & 0xf;
552 dword |= ((gval - thresh) >> 29) & 4;
553 gval = (sword >> 4) & 0xf;
554 dword |= ((gval - thresh) >> 30) & 2;
556 dword |= ((gval - thresh) >> 31) & 1;
558 lined[dcount++] = dword;
565 sword = lines[scount++];
567 gval = (sword >> 28) & 0xf;
569 dword |= (((gval - thresh) >> 31) & 1) << (31 - (j & 31));
571 lined[dcount] = dword;
574#define CHECK_BIT(a, b, c) if (GET_DATA_BIT(a, b) != c) { \
575 lept_stderr("Error: mismatch at %d/%d(%d), %d vs %d\n", \
576 j, w, d, GET_DATA_BIT(a, b), c); }
577 for (j = 0; j < w; j++) {
579 CHECK_BIT(lined, j, gval < thresh ? 1 : 0);
585 for (j = 0, scount = 0, dcount = 0; j + 31 < w; j += 32) {
587 for (k = 0; k < 8; k++) {
588 sword = lines[scount++];
590 gval = (sword >> 24) & 0xff;
591 dword |= ((gval - thresh) >> 28) & 8;
592 gval = (sword >> 16) & 0xff;
593 dword |= ((gval - thresh) >> 29) & 4;
594 gval = (sword >> 8) & 0xff;
595 dword |= ((gval - thresh) >> 30) & 2;
597 dword |= ((gval - thresh) >> 31) & 1;
599 lined[dcount++] = dword;
606 sword = lines[scount++];
608 gval = (sword >> 24) & 0xff;
610 dword |= (l_uint64)(((gval - thresh) >> 31) & 1)
613 lined[dcount] = dword;
616 for (j = 0; j < w; j++) {
618 CHECK_BIT(lined, j, gval < thresh ? 1 : 0);
624 L_ERROR(
"src depth not 4 or 8 bpp\n", __func__);
650l_int32 i, j, vals, valg, w, h, d, wpls, wplg, wpld;
651l_uint32 *datas, *datag, *datad, *lines, *lineg, *lined;
655 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
657 return (
PIX *)ERROR_PTR(
"pixg not defined", __func__, NULL);
658 if (!pixSizesEqual(pixs, pixg))
659 return (
PIX *)ERROR_PTR(
"pix sizes not equal", __func__, NULL);
660 pixGetDimensions(pixs, &w, &h, &d);
662 return (
PIX *)ERROR_PTR(
"pixs must be 8 bpp", __func__, NULL);
664 pixd = pixCreate(w, h, 1);
665 pixCopyResolution(pixd, pixs);
666 pixCopyInputFormat(pixd, pixs);
667 datad = pixGetData(pixd);
668 wpld = pixGetWpl(pixd);
669 datas = pixGetData(pixs);
670 wpls = pixGetWpl(pixs);
671 datag = pixGetData(pixg);
672 wplg = pixGetWpl(pixg);
673 for (i = 0; i < h; i++) {
674 lines = datas + i * wpls;
675 lineg = datag + i * wplg;
676 lined = datad + i * wpld;
677 for (j = 0; j < w; j++) {
726 if (!pixs || pixGetDepth(pixs) != 8)
727 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
769 if (!pixs || pixGetDepth(pixs) != 8)
770 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
773 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
774 pixGammaTRC(pix1, pix1, gamma, blackval, whiteval);
808l_int32 i, j, w, h, d, wplg, wpld;
809l_uint32 *datag, *datad, *lineg, *lined;
813 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
814 d = pixGetDepth(pixs);
815 if (d != 2 && d != 4 && d != 8)
816 return (
PIX *)ERROR_PTR(
"not 2, 4 or 8 bpp", __func__, NULL);
818 if (!usecmap && pixGetColormap(pixs))
821 pixg = pixClone(pixs);
822 pixGetDimensions(pixg, &w, &h, &d);
823 if (d == 8 && (val < 0 || val > 255)) {
825 return (
PIX *)ERROR_PTR(
"val out of 8 bpp range", __func__, NULL);
827 if (d == 4 && (val < 0 || val > 15)) {
829 return (
PIX *)ERROR_PTR(
"val out of 4 bpp range", __func__, NULL);
831 if (d == 2 && (val < 0 || val > 3)) {
833 return (
PIX *)ERROR_PTR(
"val out of 2 bpp range", __func__, NULL);
836 pixd = pixCreate(w, h, 1);
837 pixCopyResolution(pixd, pixg);
838 pixCopyInputFormat(pixd, pixs);
839 datag = pixGetData(pixg);
840 wplg = pixGetWpl(pixg);
841 datad = pixGetData(pixd);
842 wpld = pixGetWpl(pixd);
843 for (i = 0; i < h; i++) {
844 lineg = datag + i * wplg;
845 lined = datad + i * wpld;
846 for (j = 0; j < w; j++) {
899l_int32 i, j, w, h, d, wplg, wpld, val;
900l_uint32 *datag, *datad, *lineg, *lined;
904 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
905 d = pixGetDepth(pixs);
906 if (d != 2 && d != 4 && d != 8)
907 return (
PIX *)ERROR_PTR(
"not 2, 4 or 8 bpp", __func__, NULL);
908 if (lower < 0 || lower > upper)
909 return (
PIX *)ERROR_PTR(
"lower < 0 or lower > upper!", __func__, NULL);
911 if (!usecmap && pixGetColormap(pixs))
914 pixg = pixClone(pixs);
915 pixGetDimensions(pixg, &w, &h, &d);
916 if (d == 8 && upper > 255) {
918 return (
PIX *)ERROR_PTR(
"d == 8 and upper > 255", __func__, NULL);
920 if (d == 4 && upper > 15) {
922 return (
PIX *)ERROR_PTR(
"d == 4 and upper > 15", __func__, NULL);
924 if (d == 2 && upper > 3) {
926 return (
PIX *)ERROR_PTR(
"d == 2 and upper > 3", __func__, NULL);
929 pixd = pixCreate(w, h, 1);
930 pixCopyResolution(pixd, pixg);
931 pixCopyInputFormat(pixd, pixs);
932 datag = pixGetData(pixg);
933 wplg = pixGetWpl(pixg);
934 datad = pixGetData(pixd);
935 wpld = pixGetWpl(pixd);
936 for (i = 0; i < h; i++) {
937 lineg = datag + i * wplg;
938 lined = datad + i * wpld;
939 for (j = 0; j < w; j++) {
947 if (val >= lower && val <= upper)
950 if (val < lower || val > upper)
1008 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1009 if (pixGetDepth(pixs) != 8)
1010 return (
PIX *)ERROR_PTR(
"must be 8 bpp for dithering", __func__, NULL);
1041l_int32 w, h, d, wplt, wpld;
1042l_int32 *tabval, *tab38, *tab14;
1043l_uint32 *datat, *datad;
1044l_uint32 *bufs1, *bufs2;
1049 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1050 pixGetDimensions(pixs, &w, &h, &d);
1052 return (
PIX *)ERROR_PTR(
"must be 8 bpp for dithering", __func__, NULL);
1053 if (lowerclip < 0 || lowerclip > 255)
1054 return (
PIX *)ERROR_PTR(
"invalid value for lowerclip", __func__, NULL);
1055 if (upperclip < 0 || upperclip > 255)
1056 return (
PIX *)ERROR_PTR(
"invalid value for upperclip", __func__, NULL);
1058 if ((pixd = pixCreate(w, h, 2)) == NULL)
1059 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1060 pixCopyResolution(pixd, pixs);
1061 pixCopyInputFormat(pixd, pixs);
1062 datad = pixGetData(pixd);
1063 wpld = pixGetWpl(pixd);
1067 datat = pixGetData(pixt);
1068 wplt = pixGetWpl(pixt);
1071 bufs1 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
1072 bufs2 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
1073 if (!bufs1 || !bufs2) {
1078 return (
PIX *)ERROR_PTR(
"bufs1, bufs2 not both made", __func__, NULL);
1085 tabval, tab38, tab14);
1088 cmap = pixcmapCreateLinear(2, 4);
1089 pixSetColormap(pixd, cmap);
1133 memcpy(bufs2, datas, 4 * wpls);
1134 for (i = 0; i < h - 1; i++) {
1135 memcpy(bufs1, bufs2, 4 * wpls);
1136 memcpy(bufs2, datas + (i + 1) * wpls, 4 * wpls);
1137 lined = datad + i * wpld;
1142 memcpy(bufs1, bufs2, 4 * wpls);
1143 lined = datad + (h - 1) * wpld;
1182 l_int32 lastlineflag)
1185l_int32 oval, tab38val, tab14val;
1186l_uint8 rval, bval, dval;
1188 if (lastlineflag == 0) {
1189 for (j = 0; j < w - 1; j++) {
1195 tab38val = tab38[oval];
1196 tab14val = tab14[oval];
1198 rval = L_MAX(0, rval + tab38val);
1199 bval = L_MAX(0, bval + tab38val);
1200 dval = L_MAX(0, dval + tab14val);
1202 rval = L_MIN(255, rval + tab38val);
1203 bval = L_MIN(255, bval + tab38val);
1204 dval = L_MIN(255, dval + tab14val);
1215 tab38val = tab38[oval];
1217 bval = L_MAX(0, bval + tab38val);
1219 bval = L_MIN(255, bval + tab38val);
1222 for (j = 0; j < w - 1; j++) {
1226 tab38val = tab38[oval];
1228 rval = L_MAX(0, rval + tab38val);
1230 rval = L_MIN(255, rval + tab38val);
1256 l_int32 cliptoblack,
1257 l_int32 cliptowhite)
1260l_int32 *tabval, *tab38, *tab14;
1263 tabval = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1264 tab38 = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1265 tab14 = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1270 for (i = 0; i < 256; i++) {
1271 if (i <= cliptoblack) {
1275 }
else if (i < 43) {
1277 tab38[i] = (3 * i + 4) / 8;
1278 tab14[i] = (i + 2) / 4;
1279 }
else if (i < 85) {
1281 tab38[i] = (3 * (i - 85) - 4) / 8;
1282 tab14[i] = ((i - 85) - 2) / 4;
1283 }
else if (i < 128) {
1285 tab38[i] = (3 * (i - 85) + 4) / 8;
1286 tab14[i] = ((i - 85) + 2) / 4;
1287 }
else if (i < 170) {
1289 tab38[i] = (3 * (i - 170) - 4) / 8;
1290 tab14[i] = ((i - 170) - 2) / 4;
1291 }
else if (i < 213) {
1293 tab38[i] = (3 * (i - 170) + 4) / 8;
1294 tab14[i] = ((i - 170) + 2) / 4;
1295 }
else if (i < 255 - cliptowhite) {
1297 tab38[i] = (3 * (i - 255) - 4) / 8;
1298 tab14[i] = ((i - 255) - 2) / 4;
1363l_int32 w, h, d, wplt, wpld;
1364l_uint32 *datat, *datad;
1369 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1370 pixGetDimensions(pixs, &w, &h, &d);
1372 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
1373 if (nlevels < 2 || nlevels > 4)
1374 return (
PIX *)ERROR_PTR(
"nlevels not in {2, 3, 4}", __func__, NULL);
1376 if ((pixd = pixCreate(w, h, 2)) == NULL)
1377 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1378 pixCopyResolution(pixd, pixs);
1379 pixCopyInputFormat(pixd, pixs);
1380 datad = pixGetData(pixd);
1381 wpld = pixGetWpl(pixd);
1384 cmap = pixcmapCreateLinear(2, nlevels);
1385 pixSetColormap(pixd, cmap);
1390 datat = pixGetData(pixt);
1391 wplt = pixGetWpl(pixt);
1427l_uint8 sval1, sval2, sval3, sval4, dval;
1429l_uint32 *lines, *lined;
1431 for (i = 0; i < h; i++) {
1432 lines = datas + i * wpls;
1433 lined = datad + i * wpld;
1434 for (j = 0; j < wpls; j++) {
1440 dval = (tab[sval1] << 6) | (tab[sval2] << 4) |
1441 (tab[sval3] << 2) | tab[sval4];
1503l_int32 w, h, d, wplt, wpld;
1504l_uint32 *datat, *datad;
1509 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1510 pixGetDimensions(pixs, &w, &h, &d);
1512 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
1513 if (nlevels < 2 || nlevels > 16)
1514 return (
PIX *)ERROR_PTR(
"nlevels not in [2,...,16]", __func__, NULL);
1516 if ((pixd = pixCreate(w, h, 4)) == NULL)
1517 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1518 pixCopyResolution(pixd, pixs);
1519 pixCopyInputFormat(pixd, pixs);
1520 datad = pixGetData(pixd);
1521 wpld = pixGetWpl(pixd);
1524 cmap = pixcmapCreateLinear(4, nlevels);
1525 pixSetColormap(pixd, cmap);
1530 datat = pixGetData(pixt);
1531 wplt = pixGetWpl(pixt);
1567l_uint8 sval1, sval2, sval3, sval4;
1570l_uint32 *lines, *lined;
1572 for (i = 0; i < h; i++) {
1573 lines = datas + i * wpls;
1574 lined = datad + i * wpld;
1575 for (j = 0; j < wpls; j++) {
1581 dval = (tab[sval1] << 12) | (tab[sval2] << 8) |
1582 (tab[sval3] << 4) | tab[sval4];
1618l_int32 i, j, w, h, wpld, val, newval;
1619l_uint32 *datad, *lined;
1624 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1625 if (pixGetDepth(pixs) != 8)
1626 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
1627 if (nlevels < 2 || nlevels > 256)
1628 return (
PIX *)ERROR_PTR(
"nlevels not in [2,...,256]", __func__, NULL);
1631 if (pixGetColormap(pixs))
1634 pixd = pixCopy(NULL, pixs);
1637 cmap = pixcmapCreateLinear(8, nlevels);
1638 pixSetColormap(pixd, cmap);
1646 pixGetDimensions(pixd, &w, &h, NULL);
1647 pixCopyResolution(pixd, pixs);
1648 pixCopyInputFormat(pixd, pixs);
1649 datad = pixGetData(pixd);
1650 wpld = pixGetWpl(pixd);
1651 for (i = 0; i < h; i++) {
1652 lined = datad + i * wpld;
1653 for (j = 0; j < w; j++) {
1713 const char *edgevals,
1715 l_int32 use_average,
1720l_int32 w, h, d, i, j, n, wplt, wpld, val, newval;
1721l_uint32 *datat, *datad, *linet, *lined;
1727 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1728 pixGetDimensions(pixs, &w, &h, &d);
1730 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
1732 return (
PIX *)ERROR_PTR(
"edgevals not defined", __func__, NULL);
1733 if (outdepth != 0 && outdepth != 2 && outdepth != 4 && outdepth != 8)
1734 return (
PIX *)ERROR_PTR(
"invalid outdepth", __func__, NULL);
1737 na = parseStringForNumbers(edgevals,
" \t\n,");
1738 n = numaGetCount(na);
1741 return (
PIX *)ERROR_PTR(
"more than 256 levels", __func__, NULL);
1743 if (outdepth == 0) {
1750 }
else if (n + 1 > (1 << outdepth)) {
1751 L_WARNING(
"outdepth too small; setting to 8 bpp\n", __func__);
1759 pixcmapDestroy(&cmap);
1762 pixcmapSetBlackAndWhite(cmap, setblack, setwhite);
1765 if ((pixd = pixCreate(w, h, outdepth)) == NULL) {
1767 pixcmapDestroy(&cmap);
1768 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1770 pixCopyResolution(pixd, pixs);
1771 pixCopyInputFormat(pixd, pixs);
1772 pixSetColormap(pixd, cmap);
1773 datad = pixGetData(pixd);
1774 wpld = pixGetWpl(pixd);
1778 datat = pixGetData(pixt);
1779 wplt = pixGetWpl(pixt);
1781 if (outdepth == 2) {
1783 }
else if (outdepth == 4) {
1786 for (i = 0; i < h; i++) {
1787 lined = datad + i * wpld;
1788 linet = datat + i * wplt;
1789 for (j = 0; j < w; j++) {
1823l_int32 i, j, thresh;
1825 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1826 for (i = 0; i < 256; i++) {
1827 for (j = 0; j < nlevels; j++) {
1828 thresh = 255 * (2 * j + 1) / (2 * nlevels - 2);
1873l_int32 i, j, thresh, maxval, quantval;
1875 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1876 maxval = (1 << depth) - 1;
1878 nlevels = 1 << depth;
1879 for (i = 0; i < 256; i++) {
1880 for (j = 0; j < nlevels; j++) {
1881 thresh = 255 * (2 * j + 1) / (2 * nlevels - 2);
1883 quantval = maxval * j / (nlevels - 1);
1927l_int32 i, j, n, jstart, ave, val;
1932 return ERROR_INT(
"&tab not defined", __func__, 1);
1935 return ERROR_INT(
"&cmap not defined", __func__, 1);
1938 return ERROR_INT(
"na not defined", __func__, 1);
1939 n = numaGetCount(na);
1940 if (n + 1 > (1 << outdepth))
1941 return ERROR_INT(
"more bins than cmap levels", __func__, 1);
1943 if ((cmap = pixcmapCreate(outdepth)) == NULL)
1944 return ERROR_INT(
"cmap not made", __func__, 1);
1945 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
1951 for (i = 0; i < n; i++) {
1952 numaGetIValue(na, i, &val);
1953 ave = (jstart + val) / 2;
1954 pixcmapAddColor(cmap, ave, ave, ave);
1955 for (j = jstart; j < val; j++)
1961 ave = (jstart + 255) / 2;
1962 pixcmapAddColor(cmap, ave, ave, ave);
1963 for (j = jstart; j < 256; j++)
1997l_int32 i, j, index, w, h, d, nbins, wpl, factor, val;
1998l_int32 *bincount, *binave, *binstart;
1999l_uint32 *line, *data;
2002 return ERROR_INT(
"&cmap not defined", __func__, 1);
2005 return ERROR_INT(
"pixs not defined", __func__, 1);
2006 pixGetDimensions(pixs, &w, &h, &d);
2008 return ERROR_INT(
"pixs not 8 bpp", __func__, 1);
2010 return ERROR_INT(
"tab not defined", __func__, 1);
2011 nbins = tab[255] + 1;
2012 if (nbins > (1 << outdepth))
2013 return ERROR_INT(
"more bins than cmap levels", __func__, 1);
2016 if ((bincount = (l_int32 *)LEPT_CALLOC(nbins,
sizeof(l_int32))) == NULL)
2017 return ERROR_INT(
"calloc fail for bincount", __func__, 1);
2018 if ((binave = (l_int32 *)LEPT_CALLOC(nbins,
sizeof(l_int32))) == NULL) {
2019 LEPT_FREE(bincount);
2020 return ERROR_INT(
"calloc fail for binave", __func__, 1);
2022 factor = (l_int32)(sqrt((l_float64)(w * h) / 30000.) + 0.5);
2023 factor = L_MAX(1, factor);
2024 data = pixGetData(pixs);
2025 wpl = pixGetWpl(pixs);
2026 for (i = 0; i < h; i += factor) {
2027 line = data + i * wpl;
2028 for (j = 0; j < w; j += factor) {
2030 bincount[tab[val]]++;
2031 binave[tab[val]] += val;
2036 binstart = (l_int32 *)LEPT_CALLOC(nbins,
sizeof(l_int32));
2037 for (i = 1, index = 1; i < 256; i++) {
2038 if (tab[i] < index)
continue;
2039 if (tab[i] == index)
2040 binstart[index++] = i;
2045 *pcmap = pixcmapCreate(outdepth);
2046 for (i = 0; i < nbins; i++) {
2048 val = binave[i] / bincount[i];
2051 val = (binstart[i] + binstart[i + 1]) / 2;
2053 val = (binstart[i] + 255) / 2;
2055 pixcmapAddColor(*pcmap, val, val, val);
2058 LEPT_FREE(bincount);
2060 LEPT_FREE(binstart);
2102l_int32 i, j, w, h, d, wpls, wpld;
2103l_int32 rref, gref, bref, rval, gval, bval;
2104l_int32 rmin, gmin, bmin, rmax, gmax, bmax;
2106l_uint32 *datas, *datad, *lines, *lined;
2110 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2111 pixGetDimensions(pixs, &w, &h, &d);
2113 return (
PIX *)ERROR_PTR(
"not 32 bpp", __func__, NULL);
2114 if (delm < 0 || delp < 0)
2115 return (
PIX *)ERROR_PTR(
"delm and delp must be >= 0", __func__, NULL);
2116 if (fractm < 0.0 || fractm > 1.0 || fractp < 0.0 || fractp > 1.0)
2117 return (
PIX *)ERROR_PTR(
"fractm and/or fractp invalid", __func__, NULL);
2119 extractRGBValues(refval, &rref, &gref, &bref);
2120 if (fractm == 0.0 && fractp == 0.0) {
2127 }
else if (delm == 0 && delp == 0) {
2128 rmin = (l_int32)((1.0 - fractm) * rref);
2129 gmin = (l_int32)((1.0 - fractm) * gref);
2130 bmin = (l_int32)((1.0 - fractm) * bref);
2131 rmax = rref + (l_int32)(fractp * (255 - rref));
2132 gmax = gref + (l_int32)(fractp * (255 - gref));
2133 bmax = bref + (l_int32)(fractp * (255 - bref));
2135 L_ERROR(
"bad input: either (delm, delp) or (fractm, fractp) "
2136 "must be 0\n", __func__);
2140 pixd = pixCreate(w, h, 1);
2141 pixCopyResolution(pixd, pixs);
2142 pixCopyInputFormat(pixd, pixs);
2143 datas = pixGetData(pixs);
2144 wpls = pixGetWpl(pixs);
2145 datad = pixGetData(pixd);
2146 wpld = pixGetWpl(pixd);
2147 for (i = 0; i < h; i++) {
2148 lines = datas + i * wpls;
2149 lined = datad + i * wpld;
2150 for (j = 0; j < w; j++) {
2152 rval = (pixel >> L_RED_SHIFT) & 0xff;
2153 if (rval < rmin || rval > rmax)
2155 gval = (pixel >> L_GREEN_SHIFT) & 0xff;
2156 if (gval < gmin || gval > gmax)
2158 bval = (pixel >> L_BLUE_SHIFT) & 0xff;
2159 if (bval < bmin || bval > bmax)
2196l_int32 i, j, w, h, d, wpls, wpld;
2197l_int32 rref1, gref1, bref1, rref2, gref2, bref2, rval, gval, bval;
2198l_uint32 pixel, dist1, dist2;
2199l_uint32 *datas, *datad, *lines, *lined;
2203 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2204 pixGetDimensions(pixs, &w, &h, &d);
2206 return (
PIX *)ERROR_PTR(
"not 32 bpp", __func__, NULL);
2208 return (
PIX *)ERROR_PTR(
"invalid distflag", __func__, NULL);
2210 extractRGBValues(refval1, &rref1, &gref1, &bref1);
2211 extractRGBValues(refval2, &rref2, &gref2, &bref2);
2212 pixd = pixCreate(w, h, 1);
2213 pixCopyResolution(pixd, pixs);
2214 pixCopyInputFormat(pixd, pixs);
2215 datas = pixGetData(pixs);
2216 wpls = pixGetWpl(pixs);
2217 datad = pixGetData(pixd);
2218 wpld = pixGetWpl(pixd);
2219 for (i = 0; i < h; i++) {
2220 lines = datas + i * wpls;
2221 lined = datad + i * wpld;
2222 for (j = 0; j < w; j++) {
2224 extractRGBValues(pixel, &rval, &gval, &bval);
2226 dist1 = L_ABS(rref1 - rval);
2227 dist2 = L_ABS(rref2 - rval);
2228 dist1 += L_ABS(gref1 - gval);
2229 dist2 += L_ABS(gref2 - gval);
2230 dist1 += L_ABS(bref1 - bval);
2231 dist2 += L_ABS(bref2 - bval);
2233 dist1 = (rref1 - rval) * (rref1 - rval);
2234 dist2 = (rref2 - rval) * (rref2 - rval);
2235 dist1 += (gref1 - gval) * (gref1 - gval);
2236 dist2 += (gref2 - gval) * (gref2 - gval);
2237 dist1 += (bref1 - bval) * (bref1 - bval);
2238 dist2 += (bref2 - bval) * (bref2 - bval);
2309l_int32 w, h, wd, hd, wm, hm, wpls, wplm, wpld;
2310l_int32 nc, nestim, i, j, vals, vald;
2312l_uint32 *datas, *datam, *datad, *lines, *linem, *lined;
2317 if (!pixs || pixGetDepth(pixs) != 8)
2318 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
2319 if (minfract < 0.01) {
2320 L_WARNING(
"minfract < 0.01; setting to 0.05\n", __func__);
2324 L_WARNING(
"maxsize < 2; setting to 10\n", __func__);
2327 if ((pixd && !pixm) || (!pixd && pixm))
2328 return (
PIX *)ERROR_PTR(
"(pixd,pixm) not defined together",
2330 pixGetDimensions(pixs, &w, &h, NULL);
2332 if (pixGetDepth(pixm) != 1)
2333 return (
PIX *)ERROR_PTR(
"pixm not 1 bpp", __func__, NULL);
2334 if ((cmap = pixGetColormap(pixd)) == NULL)
2335 return (
PIX *)ERROR_PTR(
"pixd not cmapped", __func__, NULL);
2336 pixGetDimensions(pixd, &wd, &hd, NULL);
2337 if (w != wd || h != hd)
2338 return (
PIX *)ERROR_PTR(
"pixs, pixd sizes differ", __func__, NULL);
2339 nc = pixcmapGetCount(cmap);
2340 nestim = nc + (l_int32)(1.5 * 255 / maxsize);
2341 lept_stderr(
"nestim = %d\n", nestim);
2343 L_ERROR(
"Estimate %d colors!\n", __func__, nestim);
2344 return (
PIX *)ERROR_PTR(
"probably too many colors", __func__, NULL);
2346 pixGetDimensions(pixm, &wm, &hm, NULL);
2347 if (w != wm || h != hm) {
2348 L_WARNING(
"mask and dest sizes not equal\n", __func__);
2349 pixmr = pixCreate(w, h, 1);
2350 pixRasterop(pixmr, 0, 0, wm, hm,
PIX_SRC, pixm, 0, 0);
2351 pixRasterop(pixmr, wm, 0, w - wm, h,
PIX_SET, NULL, 0, 0);
2352 pixRasterop(pixmr, 0, hm, wm, h - hm,
PIX_SET, NULL, 0, 0);
2354 pixmr = pixClone(pixm);
2357 pixd = pixCreateTemplate(pixs);
2358 cmap = pixcmapCreate(8);
2359 pixSetColormap(pixd, cmap);
2361 pixCopyResolution(pixd, pixs);
2362 pixCopyInputFormat(pixd, pixs);
2365 na = pixGetGrayHistogramMasked(pixs, pixm, 0, 0, 1);
2370 L_ERROR(
"ran out of colors in cmap!\n", __func__);
2374 datas = pixGetData(pixs);
2375 datad = pixGetData(pixd);
2376 wpls = pixGetWpl(pixs);
2377 wpld = pixGetWpl(pixd);
2379 for (i = 0; i < h; i++) {
2380 lines = datas + i * wpls;
2381 lined = datad + i * wpld;
2382 for (j = 0; j < w; j++) {
2392 datam = pixGetData(pixmr);
2393 wplm = pixGetWpl(pixmr);
2394 for (i = 0; i < h; i++) {
2395 lines = datas + i * wpls;
2396 linem = datam + i * wplm;
2397 lined = datad + i * wpld;
2398 for (j = 0; j < w; j++) {
2439l_int32 mincount, index, sum, wtsum, span, istart, i, val, ret;
2440l_int32 *iahisto, *lut;
2444 return ERROR_INT(
"&lut not defined", __func__, 1);
2447 return ERROR_INT(
"na not defined", __func__, 1);
2449 return ERROR_INT(
"cmap not defined", __func__, 1);
2451 numaGetSum(na, &total);
2452 mincount = (l_int32)(minfract * total);
2453 iahisto = numaGetIArray(na);
2454 lut = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2456 index = pixcmapGetCount(cmap);
2471 for (i = 0; i < 256; i++) {
2474 wtsum += i * iahisto[i];
2475 span = i - istart + 1;
2476 if (sum < mincount && span < maxsize)
2485 val = (l_int32)((l_float32)wtsum / (l_float32)sum + 0.5);
2486 ret = pixcmapAddColor(cmap, val, val, val);
2492 if (istart < 256 && sum > 0) {
2493 span = 256 - istart;
2494 val = (l_int32)((l_float32)wtsum / (l_float32)sum + 0.5);
2495 ret = pixcmapAddColor(cmap, val, val, val);
2526l_int32 i, j, index, w, h, d, depth, wpls, wpld;
2527l_int32 hascolor, vals, vald;
2529l_uint32 *datas, *datad, *lines, *lined;
2534 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2535 if (pixGetColormap(pixs) != NULL) {
2536 L_WARNING(
"pixs already has a colormap; returning a copy\n", __func__);
2537 return pixCopy(NULL, pixs);
2539 pixGetDimensions(pixs, &w, &h, &d);
2541 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
2543 return (
PIX *)ERROR_PTR(
"cmap not defined", __func__, NULL);
2544 if (mindepth != 2 && mindepth != 4 && mindepth != 8)
2545 return (
PIX *)ERROR_PTR(
"invalid mindepth", __func__, NULL);
2548 pixcmapHasColor(cmap, &hascolor);
2550 L_WARNING(
"Converting colormap colors to gray\n", __func__);
2551 cmapd = pixcmapColorToGray(cmap, 0.3f, 0.5f, 0.2f);
2553 cmapd = pixcmapCopy(cmap);
2557 tab = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2558 for (i = 0; i < 256; i++) {
2559 pixcmapGetNearestGrayIndex(cmapd, i, &index);
2563 pixcmapGetMinDepth(cmap, &depth);
2564 depth = L_MAX(depth, mindepth);
2565 pixd = pixCreate(w, h, depth);
2566 pixSetColormap(pixd, cmapd);
2567 pixCopyResolution(pixd, pixs);
2568 pixCopyInputFormat(pixd, pixs);
2569 datas = pixGetData(pixs);
2570 datad = pixGetData(pixd);
2571 wpls = pixGetWpl(pixs);
2572 wpld = pixGetWpl(pixd);
2573 for (i = 0; i < h; i++) {
2574 lines = datas + i * wpls;
2575 lined = datad + i * wpld;
2576 for (j = 0; j < w; j++) {
2581 else if (depth == 4)
2613pixDitherToBinaryLUT(
PIX *pixs,
2617l_int32 w, h, d, wplt, wpld;
2618l_int32 *tabval, *tab38, *tab14;
2619l_uint32 *datat, *datad;
2620l_uint32 *bufs1, *bufs2;
2624 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2625 pixGetDimensions(pixs, &w, &h, &d);
2627 return (
PIX *)ERROR_PTR(
"must be 8 bpp for dithering", __func__, NULL);
2633 if ((pixd = pixCreate(w, h, 1)) == NULL)
2634 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2635 pixCopyResolution(pixd, pixs);
2636 pixCopyInputFormat(pixd, pixs);
2637 datad = pixGetData(pixd);
2638 wpld = pixGetWpl(pixd);
2642 datat = pixGetData(pixt);
2643 wplt = pixGetWpl(pixt);
2646 bufs1 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
2647 bufs2 = (l_uint32 *)LEPT_CALLOC(wplt,
sizeof(l_uint32));
2648 if (!bufs1 || !bufs2) {
2653 return (
PIX *)ERROR_PTR(
"bufs1, bufs2 not both made", __func__, NULL);
2657 make8To1DitherTables(&tabval, &tab38, &tab14, lowerclip, upperclip);
2659 ditherToBinaryLUTLow(datad, w, h, wpld, datat, wplt, bufs1, bufs2,
2660 tabval, tab38, tab14);
2685ditherToBinaryLUTLow(l_uint32 *datad,
2701 memcpy(bufs2, datas, 4 * wpls);
2702 for (i = 0; i < h - 1; i++) {
2703 memcpy(bufs1, bufs2, 4 * wpls);
2704 memcpy(bufs2, datas + (i + 1) * wpls, 4 * wpls);
2705 lined = datad + i * wpld;
2706 ditherToBinaryLineLUTLow(lined, w, bufs1, bufs2,
2707 tabval, tab38, tab14, 0);
2711 memcpy(bufs1, bufs2, 4 * wpls);
2712 lined = datad + (h - 1) * wpld;
2713 ditherToBinaryLineLUTLow(lined, w, bufs1, bufs2, tabval, tab38, tab14, 1);
2731ditherToBinaryLineLUTLow(l_uint32 *lined,
2738 l_int32 lastlineflag)
2741l_int32 oval, tab38val, tab14val;
2742l_uint8 rval, bval, dval;
2744 if (lastlineflag == 0) {
2745 for (j = 0; j < w - 1; j++) {
2752 tab38val = tab38[oval];
2755 tab14val = tab14[oval];
2757 rval = L_MAX(0, rval + tab38val);
2758 bval = L_MAX(0, bval + tab38val);
2759 dval = L_MAX(0, dval + tab14val);
2761 rval = L_MIN(255, rval + tab38val);
2762 bval = L_MIN(255, bval + tab38val);
2763 dval = L_MIN(255, dval + tab14val);
2775 tab38val = tab38[oval];
2777 bval = L_MAX(0, bval + tab38val);
2779 }
else if (tab38val > 0 ) {
2780 bval = L_MIN(255, bval + tab38val);
2784 for (j = 0; j < w - 1; j++) {
2789 tab38val = tab38[oval];
2793 rval = L_MAX(0, rval + tab38val);
2795 rval = L_MIN(255, rval + tab38val);
2820make8To1DitherTables(l_int32 **ptabval,
2827l_int32 *tabval, *tab38, *tab14;
2829 if (ptabval) *ptabval = NULL;
2830 if (ptab38) *ptab38 = NULL;
2831 if (ptab14) *ptab14 = NULL;
2832 if (!ptabval || !ptab38 || !ptab14)
2833 return ERROR_INT(
"table ptrs not all defined", __func__, 1);
2836 tabval = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2837 tab38 = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2838 tab14 = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
2839 if (!tabval || !tab38 || !tab14)
2840 return ERROR_INT(
"calloc failure to make small table", __func__, 1);
2845 for (i = 0; i < 256; i++) {
2846 if (i <= lowerclip) {
2850 }
else if (i < 128) {
2852 tab38[i] = (3 * i + 4) / 8;
2853 tab14[i] = (i + 2) / 4;
2854 }
else if (i < 255 - upperclip) {
2856 tab38[i] = (3 * (i - 255) + 4) / 8;
2857 tab14[i] = ((i - 255) + 2) / 4;
PIX * pixBackgroundNormSimple(PIX *pixs, PIX *pixim, PIX *pixg)
pixBackgroundNormSimple()
#define GET_DATA_QBIT(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
PIX * pixThresholdGrayArb(PIX *pixs, const char *edgevals, l_int32 outdepth, l_int32 use_average, l_int32 setblack, l_int32 setwhite)
pixThresholdGrayArb()
l_int32 * makeGrayQuantIndexTable(l_int32 nlevels)
makeGrayQuantIndexTable()
static void thresholdToBinaryLow(l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls, l_int32 thresh)
thresholdToBinaryLow()
void ditherToBinaryLineLow(l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 lowerclip, l_int32 upperclip, l_int32 lastlineflag)
ditherToBinaryLineLow()
PIX * pixDitherTo2bppSpec(PIX *pixs, l_int32 lowerclip, l_int32 upperclip, l_int32 cmapflag)
pixDitherTo2bppSpec()
PIX * pixDitherToBinarySpec(PIX *pixs, l_int32 lowerclip, l_int32 upperclip)
pixDitherToBinarySpec()
PIX * pixThresholdTo4bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdTo4bpp()
PIX * pixAdaptThresholdToBinaryGen(PIX *pixs, PIX *pixm, l_float32 gamma, l_int32 blackval, l_int32 whiteval, l_int32 thresh)
pixAdaptThresholdToBinaryGen()
static l_int32 make8To2DitherTables(l_int32 **ptabval, l_int32 **ptab38, l_int32 **ptab14, l_int32 cliptoblack, l_int32 cliptowhite)
make8To2DitherTables()
PIX * pixGenerateMaskByBand32(PIX *pixs, l_uint32 refval, l_int32 delm, l_int32 delp, l_float32 fractm, l_float32 fractp)
pixGenerateMaskByBand32()
static void thresholdTo4bppLow(l_uint32 *datad, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab)
thresholdTo4bppLow()
PIX * pixAdaptThresholdToBinary(PIX *pixs, PIX *pixm, l_float32 gamma)
pixAdaptThresholdToBinary()
static l_int32 makeGrayQuantColormapArb(PIX *pixs, l_int32 *tab, l_int32 outdepth, PIXCMAP **pcmap)
makeGrayQuantColormapArb()
PIX * pixGrayQuantFromHisto(PIX *pixd, PIX *pixs, PIX *pixm, l_float32 minfract, l_int32 maxsize)
pixGrayQuantFromHisto()
static void ditherTo2bppLow(l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14)
ditherTo2bppLow()
PIX * pixVarThresholdToBinary(PIX *pixs, PIX *pixg)
pixVarThresholdToBinary()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
PIX * pixGenerateMaskByDiscr32(PIX *pixs, l_uint32 refval1, l_uint32 refval2, l_int32 distflag)
pixGenerateMaskByDiscr32()
PIX * pixThresholdOn8bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdOn8bpp()
PIX * pixDitherTo2bpp(PIX *pixs, l_int32 cmapflag)
pixDitherTo2bpp()
static void ditherToBinaryLow(l_uint32 *datad, l_int32 w, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 lowerclip, l_int32 upperclip)
ditherToBinaryLow()
static l_int32 * makeGrayQuantTargetTable(l_int32 nlevels, l_int32 depth)
makeGrayQuantTargetTable()
PIX * pixGenerateMaskByBand(PIX *pixs, l_int32 lower, l_int32 upper, l_int32 inband, l_int32 usecmap)
pixGenerateMaskByBand()
PIX * pixDitherToBinary(PIX *pixs)
pixDitherToBinary()
PIX * pixGrayQuantFromCmap(PIX *pixs, PIXCMAP *cmap, l_int32 mindepth)
pixGrayQuantFromCmap()
static l_int32 numaFillCmapFromHisto(NUMA *na, PIXCMAP *cmap, l_float32 minfract, l_int32 maxsize, l_int32 **plut)
numaFillCmapFromHisto()
static void thresholdTo2bppLow(l_uint32 *datad, l_int32 h, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab)
thresholdTo2bppLow()
l_ok makeGrayQuantTableArb(NUMA *na, l_int32 outdepth, l_int32 **ptab, PIXCMAP **pcmap)
makeGrayQuantTableArb()
PIX * pixGenerateMaskByValue(PIX *pixs, l_int32 val, l_int32 usecmap)
pixGenerateMaskByValue()
static void ditherTo2bppLineLow(l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 *tabval, l_int32 *tab38, l_int32 *tab14, l_int32 lastlineflag)
ditherTo2bppLineLow()
PIX * pixThresholdTo2bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdTo2bpp()
@ REMOVE_CMAP_TO_GRAYSCALE