158 #include <config_auto.h>
163 #include "allheaders.h"
167 static l_int32 var_NEUTRAL_BOOST_VAL = 180;
170 #ifndef NO_CONSOLE_IO
171 #define DEBUG_CONVERT_TO_COLORMAP 0
172 #define DEBUG_UNROLLING 0
219 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
220 if (pixGetDepth(pixs) != 8)
221 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
222 if (cmapflag && nlevels < 2)
223 return (
PIX *)ERROR_PTR(
"nlevels must be at least 2", __func__, NULL);
243 return (
PIX *)ERROR_PTR(
"d must be in {1,2,4,8}", __func__, NULL);
247 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
248 pixCopyInputFormat(pixd, pixs);
281 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
283 return (
PIX *)ERROR_PTR(
"invalid value for ifnocmap", __func__, NULL);
285 if (pixGetColormap(pixs))
327 l_int32 sval, rval, gval, bval, val0, val1;
328 l_int32 i, j, k, w, h, d, wpls, wpld, ncolors, nalloc, count;
329 l_int32 opaque, colorfound, blackwhite;
330 l_int32 *rmap, *gmap, *bmap, *amap;
331 l_uint32 *datas, *lines, *datad, *lined, *lut, *graymap;
332 l_uint32 sword, dword;
337 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
338 if ((cmap = pixGetColormap(pixs)) == NULL)
345 L_WARNING(
"Invalid type; converting based on src\n", __func__);
349 if (d != 1 && d != 2 && d != 4 && d != 8)
350 return (
PIX *)ERROR_PTR(
"pixs must be {1,2,4,8} bpp", __func__, NULL);
354 if (ncolors > nalloc)
355 return (
PIX *)ERROR_PTR(
"too many colors for pixel depth",
359 return (
PIX *)ERROR_PTR(
"colormap arrays not made", __func__, NULL);
362 L_WARNING(
"not 1 bpp; can't remove cmap to binary\n", __func__);
373 }
else if (colorfound) {
376 if (d == 1 && blackwhite)
384 wpls = pixGetWpl(pixs);
386 if ((pixd =
pixCopy(NULL, pixs)) == NULL) {
387 L_ERROR(
"pixd not made\n", __func__);
391 val0 = rval + gval + bval;
393 val1 = rval + gval + bval;
398 if ((pixd =
pixCreate(w, h, 8)) == NULL) {
399 L_ERROR(
"pixd not made\n", __func__);
402 pixCopyResolution(pixd, pixs);
403 pixCopyInputFormat(pixd, pixs);
405 wpld = pixGetWpl(pixd);
406 graymap = (l_uint32 *)LEPT_CALLOC(nalloc,
sizeof(l_uint32));
407 for (i = 0; i < ncolors; i++) {
412 for (i = 0; i < h; i++) {
413 lines = datas + i * wpls;
414 lined = datad + i * wpld;
419 for (j = 0, count = 0; j + 3 < w; j += 4, count++) {
420 sword = lines[count];
421 dword = (graymap[(sword >> 24) & 0xff] << 24) |
422 (graymap[(sword >> 16) & 0xff] << 16) |
423 (graymap[(sword >> 8) & 0xff] << 8) |
424 graymap[sword & 0xff];
425 lined[count] = dword;
430 gval = graymap[sval];
434 #define CHECK_VALUE(a, b, c) if (GET_DATA_BYTE(a, b) != c) { \
435 lept_stderr("Error: mismatch at %d, %d vs %d\n", \
436 j, GET_DATA_BYTE(a, b), c); }
437 for (j = 0; j < w; j++) {
439 gval = graymap[sval];
440 CHECK_VALUE(lined, j, gval);
446 for (j = 0, count = 0; j + 7 < w; j += 8, count++) {
447 sword = lines[count];
448 dword = (graymap[(sword >> 28) & 0xf] << 24) |
449 (graymap[(sword >> 24) & 0xf] << 16) |
450 (graymap[(sword >> 20) & 0xf] << 8) |
451 graymap[(sword >> 16) & 0xf];
452 lined[2 * count] = dword;
453 dword = (graymap[(sword >> 12) & 0xf] << 24) |
454 (graymap[(sword >> 8) & 0xf] << 16) |
455 (graymap[(sword >> 4) & 0xf] << 8) |
456 graymap[sword & 0xf];
457 lined[2 * count + 1] = dword;
462 gval = graymap[sval];
466 for (j = 0; j < w; j++) {
468 gval = graymap[sval];
469 CHECK_VALUE(lined, j, gval);
475 for (j = 0, count = 0; j + 15 < w; j += 16, count++) {
476 sword = lines[count];
477 dword = (graymap[(sword >> 30) & 0x3] << 24) |
478 (graymap[(sword >> 28) & 0x3] << 16) |
479 (graymap[(sword >> 26) & 0x3] << 8) |
480 graymap[(sword >> 24) & 0x3];
481 lined[4 * count] = dword;
482 dword = (graymap[(sword >> 22) & 0x3] << 24) |
483 (graymap[(sword >> 20) & 0x3] << 16) |
484 (graymap[(sword >> 18) & 0x3] << 8) |
485 graymap[(sword >> 16) & 0x3];
486 lined[4 * count + 1] = dword;
487 dword = (graymap[(sword >> 14) & 0x3] << 24) |
488 (graymap[(sword >> 12) & 0x3] << 16) |
489 (graymap[(sword >> 10) & 0x3] << 8) |
490 graymap[(sword >> 8) & 0x3];
491 lined[4 * count + 2] = dword;
492 dword = (graymap[(sword >> 6) & 0x3] << 24) |
493 (graymap[(sword >> 4) & 0x3] << 16) |
494 (graymap[(sword >> 2) & 0x3] << 8) |
495 graymap[sword & 0x3];
496 lined[4 * count + 3] = dword;
501 gval = graymap[sval];
505 for (j = 0; j < w; j++) {
507 gval = graymap[sval];
508 CHECK_VALUE(lined, j, gval);
514 for (j = 0, count = 0; j + 31 < w; j += 32, count++) {
515 sword = lines[count];
516 for (k = 0; k < 4; k++) {
518 dword = (graymap[(sword >> 31) & 0x1] << 24) |
519 (graymap[(sword >> 30) & 0x1] << 16) |
520 (graymap[(sword >> 29) & 0x1] << 8) |
521 graymap[(sword >> 28) & 0x1];
522 lined[8 * count + 2 * k] = dword;
523 dword = (graymap[(sword >> 27) & 0x1] << 24) |
524 (graymap[(sword >> 26) & 0x1] << 16) |
525 (graymap[(sword >> 25) & 0x1] << 8) |
526 graymap[(sword >> 24) & 0x1];
527 lined[8 * count + 2 * k + 1] = dword;
534 gval = graymap[sval];
538 for (j = 0; j < w; j++) {
540 gval = graymap[sval];
541 CHECK_VALUE(lined, j, gval);
553 if ((pixd =
pixCreate(w, h, 32)) == NULL) {
554 L_ERROR(
"pixd not made\n", __func__);
557 pixCopyInputFormat(pixd, pixs);
558 pixCopyResolution(pixd, pixs);
562 wpld = pixGetWpl(pixd);
563 lut = (l_uint32 *)LEPT_CALLOC(nalloc,
sizeof(l_uint32));
564 for (i = 0; i < ncolors; i++) {
571 for (i = 0; i < h; i++) {
572 lines = datas + i * wpls;
573 lined = datad + i * wpld;
574 for (j = 0; j < w; j++) {
584 L_WARNING(
"pixel value out of bounds\n", __func__);
586 lined[j] = lut[sval];
620 if (!pixs || pixGetDepth(pixs) != 8)
621 return ERROR_INT(
"pixs not defined or not 8 bpp", __func__, 1);
622 if (pixGetColormap(pixs))
647 l_int32 ncolors, w, h, i, j, wpl1, wpld, index, val;
648 l_int32 *inta, *revmap;
649 l_uint32 *data1, *datad, *line1, *lined;
653 if (!pixs || pixGetDepth(pixs) != 8)
654 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
658 cmap = pixGetColormap(pixs);
665 if (ncolors == 256) {
676 wpl1 = pixGetWpl(pix1);
677 inta = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
678 for (i = 0; i < h; i++) {
679 line1 = data1 + i * wpl1;
680 for (j = 0; j < w; j++) {
686 revmap = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
687 for (i = 0, index = 0; i < 256; i++) {
697 pixCopyInputFormat(pixd, pixs);
698 pixCopyResolution(pixd, pixs);
700 wpld = pixGetWpl(pixd);
701 for (i = 0; i < h; i++) {
702 line1 = data1 + i * wpl1;
703 lined = datad + i * wpld;
704 for (j = 0; j < w; j++) {
764 if (!pixs || pixGetDepth(pixs) != 32)
765 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
771 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
790 if (rwt < 0.0 || gwt < 0.0 || bwt < 0.0)
791 return (
PIX *)ERROR_PTR(
"weights not all >= 0.0", __func__, NULL);
792 if (rwt + gwt + bwt != 1.0)
793 return (
PIX *)ERROR_PTR(
"weights don't sum to 1.0", __func__, NULL);
820 l_int32 i, j, w, h, wpls, wpld, val;
822 l_uint32 *datas, *lines, *datad, *lined;
827 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
828 if (pixGetDepth(pixs) != 32)
829 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
830 if (rwt < 0.0 || gwt < 0.0 || bwt < 0.0)
831 return (
PIX *)ERROR_PTR(
"weights not all >= 0.0", __func__, NULL);
835 if (rwt == 0.0 && gwt == 0.0 && bwt == 0.0) {
840 sum = rwt + gwt + bwt;
841 if (L_ABS(sum - 1.0) > 0.0001) {
842 L_WARNING(
"weights don't sum to 1; maintaining ratios\n", __func__);
850 wpls = pixGetWpl(pixs);
852 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
853 pixCopyResolution(pixd, pixs);
854 pixCopyInputFormat(pixd, pixs);
856 wpld = pixGetWpl(pixd);
858 for (i = 0; i < h; i++) {
859 lines = datas + i * wpls;
860 lined = datad + i * wpld;
861 for (j = 0; j < w; j++) {
863 val = (l_int32)(rwt * ((word >> L_RED_SHIFT) & 0xff) +
864 gwt * ((word >> L_GREEN_SHIFT) & 0xff) +
865 bwt * ((word >> L_BLUE_SHIFT) & 0xff) + 0.5);
893 l_int32 i, j, w, h, wpls, wpld, val;
894 l_uint32 *datas, *lines, *datad, *lined;
898 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
899 if (pixGetDepth(pixs) != 32)
900 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
904 wpls = pixGetWpl(pixs);
906 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
907 pixCopyResolution(pixd, pixs);
908 pixCopyInputFormat(pixd, pixs);
910 wpld = pixGetWpl(pixd);
912 for (i = 0; i < h; i++) {
913 lines = datas + i * wpls;
914 lined = datad + i * wpld;
915 for (j = 0; j < w; j++, lines++) {
916 val = ((*lines) >> L_GREEN_SHIFT) & 0xff;
950 l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, val, minval, maxval;
951 l_uint32 *datas, *lines, *datad, *lined;
955 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
956 if (pixGetDepth(pixs) != 32)
957 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
958 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
959 type != L_CHOOSE_MAXDIFF && type != L_CHOOSE_MIN_BOOST &&
960 type != L_CHOOSE_MAX_BOOST)
961 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
965 wpls = pixGetWpl(pixs);
967 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
968 pixCopyResolution(pixd, pixs);
969 pixCopyInputFormat(pixd, pixs);
971 wpld = pixGetWpl(pixd);
973 for (i = 0; i < h; i++) {
974 lines = datas + i * wpls;
975 lined = datad + i * wpld;
976 for (j = 0; j < w; j++) {
978 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MIN_BOOST) {
979 val = L_MIN(rval, gval);
980 val = L_MIN(val, bval);
981 if (type == L_CHOOSE_MIN_BOOST)
982 val = L_MIN(255, (val * val) / var_NEUTRAL_BOOST_VAL);
983 }
else if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAX_BOOST) {
984 val = L_MAX(rval, gval);
985 val = L_MAX(val, bval);
986 if (type == L_CHOOSE_MAX_BOOST)
987 val = L_MIN(255, (val * val) / var_NEUTRAL_BOOST_VAL);
989 minval = L_MIN(rval, gval);
990 minval = L_MIN(minval, bval);
991 maxval = L_MAX(rval, gval);
992 maxval = L_MAX(maxval, bval);
993 val = maxval - minval;
1035 l_int32 w, h, d, i, j, wplt, wpld;
1036 l_int32 rval, gval, bval, sval, minrg, maxrg, min, max, delta;
1037 l_int32 fullsat, newval;
1038 l_float32 *invmax, *ratio;
1039 l_uint32 *linet, *lined, *datat, *datad;
1043 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1045 if (d != 32 && !pixGetColormap(pixs))
1046 return (
PIX *)ERROR_PTR(
"pixs not cmapped or rgb", __func__, NULL);
1047 if (refval < 1 || refval > 255)
1048 return (
PIX *)ERROR_PTR(
"refval not in [1 ... 255]", __func__, NULL);
1052 pixCopyResolution(pixd, pixs);
1053 pixCopyInputFormat(pixd, pixs);
1054 wplt = pixGetWpl(pixt);
1056 wpld = pixGetWpl(pixd);
1058 invmax = (l_float32 *)LEPT_CALLOC(256,
sizeof(l_float32));
1059 ratio = (l_float32 *)LEPT_CALLOC(256,
sizeof(l_float32));
1060 for (i = 1; i < 256; i++) {
1061 invmax[i] = 1.0 / (l_float32)i;
1062 ratio[i] = (l_float32)i / (l_float32)refval;
1064 for (i = 0; i < h; i++) {
1065 linet = datat + i * wplt;
1066 lined = datad + i * wpld;
1067 for (j = 0; j < w; j++) {
1069 minrg = L_MIN(rval, gval);
1070 min = L_MIN(minrg, bval);
1071 maxrg = L_MAX(rval, gval);
1072 max = L_MAX(maxrg, bval);
1077 sval = (l_int32)(255. * (l_float32)delta * invmax[max] + 0.5);
1079 fullsat = L_MIN(255, 255 * ratio[max]);
1080 newval = (sval * fullsat + (255 - sval) * max) / 255;
1113 l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, val;
1114 l_uint32 *datas, *lines, *datad, *lined;
1118 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1119 if (pixGetDepth(pixs) != 32)
1120 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
1121 if (rc <= 0 && gc <= 0 && bc <= 0)
1122 return (
PIX *)ERROR_PTR(
"all coefficients <= 0", __func__, NULL);
1126 wpls = pixGetWpl(pixs);
1127 if ((pixd =
pixCreate(w, h, 8)) == NULL)
1128 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1129 pixCopyResolution(pixd, pixs);
1130 pixCopyInputFormat(pixd, pixs);
1132 wpld = pixGetWpl(pixd);
1134 for (i = 0; i < h; i++) {
1135 lines = datas + i * wpls;
1136 lined = datad + i * wpld;
1137 for (j = 0; j < w; j++) {
1139 val = (l_int32)(rc * rval + gc * gval + bc * bval);
1140 val = L_MIN(255, L_MAX(0, val));
1178 if (!pixs || pixGetDepth(pixs) != 32)
1179 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
1180 if (rc <= 0 && gc <= 0 && bc <= 0)
1181 return (
PIX *)ERROR_PTR(
"all coefficients <= 0", __func__, NULL);
1184 return (
PIX *)ERROR_PTR(
"invalid relation", __func__, NULL);
1188 thresh : thresh + 1;
1230 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1231 d = pixGetDepth(pixs);
1232 if (d != 2 && d != 4 && d != 8)
1233 return (
PIX *)ERROR_PTR(
"pixs not 2, 4 or 8 bpp", __func__, NULL);
1235 if (pixGetColormap(pixs)) {
1236 L_INFO(
"pixs already has a colormap\n", __func__);
1248 pixCopyInputFormat(pixd, pixs);
1279 l_int32 ncolors, w, h, depth, i, j, wpls, wpld;
1280 l_int32 index, num, val, newval;
1282 l_uint32 *lines, *lined, *datas, *datad;
1288 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1289 if (pixGetDepth(pixs) != 8)
1290 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
1291 if (mindepth != 2 && mindepth != 4 && mindepth != 8) {
1292 L_WARNING(
"invalid value of mindepth; setting to 8\n", __func__);
1296 if (pixGetColormap(pixs)) {
1297 L_INFO(
"pixs already has a colormap\n", __func__);
1303 if (mindepth == 8 || ncolors > 16)
1305 else if (mindepth == 4 || ncolors > 4)
1314 pixCopyInputFormat(pixd, pixs);
1315 pixCopyResolution(pixd, pixs);
1318 for (i = 0; i < 256; i++) {
1329 wpls = pixGetWpl(pixs);
1331 wpld = pixGetWpl(pixd);
1332 for (i = 0; i < h; i++) {
1333 lines = datas + i * wpls;
1334 lined = datad + i * wpld;
1335 for (j = 0; j < w; j++) {
1337 newval = array[val];
1340 else if (depth == 4)
1375 l_int32 i, j, w, h, wplt, wpld, val8;
1376 l_uint32 *datad, *datat, *lined, *linet, *tab;
1381 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1382 if (pixGetDepth(pixs) != 8 && !pixGetColormap(pixs))
1383 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp or cmapped", __func__, NULL);
1385 if (pixGetColormap(pixs))
1402 pixCopyResolution(pixd, pixs);
1403 pixCopyInputFormat(pixd, pixs);
1405 wpld = pixGetWpl(pixd);
1407 wplt = pixGetWpl(pixt);
1408 for (i = 0; i < h; i++) {
1409 lined = datad + i * wpld;
1410 linet = datat + i * wplt;
1411 for (j = 0; j < w; j++) {
1413 lined[j] = tab[val8];
1464 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1465 if (pixGetDepth(pixs) != 32)
1466 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
1467 if (pixGetSpp(pixs) == 4)
1468 L_WARNING(
"pixs has alpha; removing\n", __func__);
1478 if (ncolors <= 256) {
1480 pixCopyInputFormat(pixd, pixs);
1490 L_INFO(
"More than 256 colors; using octree quant with dithering\n",
1493 L_INFO(
"More than 256 colors; using octree quant; no dithering\n",
1520 l_int32 i, j, nc, w, h, imin, imax, factor, wpl1, wpld;
1521 l_int32 index, rmin, gmin, bmin, rmax, gmax, bmax, dmin, dmax;
1522 l_float32 minfract, ifract;
1524 l_uint32 *line1, *lined, *data1, *datad;
1530 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1531 if ((cmap = pixGetColormap(pixs)) == NULL)
1532 return (
PIX *)ERROR_PTR(
"no colormap", __func__, NULL);
1545 if ((lut = (l_int32 *)LEPT_CALLOC(nc,
sizeof(l_int32))) == NULL)
1546 return (
PIX *)ERROR_PTR(
"calloc fail for lut", __func__, NULL);
1548 factor = L_MAX(1, (l_int32)sqrt((l_float64)(w * h) / 50000. + 0.5));
1552 for (i = 0; i < nc; i++) {
1569 wpl1 = pixGetWpl(pix1);
1570 wpld = pixGetWpl(pixd);
1571 for (i = 0; i < h; i++) {
1572 line1 = data1 + i * wpl1;
1573 lined = datad + i * wpld;
1574 for (j = 0; j < w; j++) {
1584 if (minfract > 0.5) {
1585 L_INFO(
"minfract = %5.3f; inverting\n", __func__, minfract);
1629 l_int32 mingraycolors,
1633 l_int32 d, ncolors, iscolor, graycolors;
1637 return ERROR_INT(
"&pixd not defined", __func__, 1);
1640 return ERROR_INT(
"pixs not defined", __func__, 1);
1641 d = pixGetDepth(pixs);
1642 if (d != 8 && d != 32)
1643 return ERROR_INT(
"pixs not defined", __func__, 1);
1644 if (pixGetColormap(pixs) != NULL) {
1651 L_WARNING(
"maxcolors > 50; very large!\n", __func__);
1652 if (mingraycolors <= 0)
1654 if (mingraycolors > 30)
1655 L_WARNING(
"mingraycolors > 30; very large!\n", __func__);
1656 if (octlevel != 3 && octlevel != 4) {
1657 L_WARNING(
"invalid octlevel; setting to 3\n", __func__);
1664 if (ncolors > maxcolors)
1665 return ERROR_INT(
"too many colors", __func__, 1);
1682 L_WARNING(
"quantized at level 2; low quality\n", __func__);
1689 graycolors = L_MAX(mingraycolors, (l_int32)(1.5 * ncolors));
1690 graycolors = L_MIN(graycolors, 256);
1691 if (graycolors < 16)
1700 return ERROR_INT(
"pixd not made", __func__, 1);
1701 pixCopyInputFormat(pixd, pixs);
1730 l_int32 w, h, wpls, wpld, i, j, val, use_lsb;
1731 l_uint32 sword, first, second;
1732 l_uint32 *datas, *datad, *lines, *lined;
1736 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1737 if (pixGetDepth(pixs) != 16)
1738 return (
PIX *)ERROR_PTR(
"pixs not 16 bpp", __func__, NULL);
1741 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1744 if ((pixd =
pixCreate(w, h, 8)) == NULL)
1745 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1746 pixCopyInputFormat(pixd, pixs);
1747 pixCopyResolution(pixd, pixs);
1748 wpls = pixGetWpl(pixs);
1750 wpld = pixGetWpl(pixd);
1755 for (i = 0; i < h; i++) {
1756 lines = datas + i * wpls;
1757 for (j = 0; j < wpls; j++) {
1764 if (!use_lsb)
break;
1770 for (i = 0; i < h; i++) {
1771 lines = datas + i * wpls;
1772 lined = datad + i * wpld;
1774 for (j = 0; j < wpls; j++) {
1775 sword = *(lines + j);
1776 dword = ((sword >> 8) & 0xff00) | (sword & 0xff);
1780 for (j = 0; j < wpls; j++) {
1781 sword = *(lines + j);
1782 dword = ((sword >> 16) & 0xff00) | ((sword >> 8) & 0xff);
1786 for (j = 0; j < wpls; j++) {
1787 sword = *(lines + j);
1788 first = (sword >> 24) ? 255 : ((sword >> 16) & 0xff);
1789 second = ((sword >> 8) & 0xff) ? 255 : (sword & 0xff);
1790 dword = (first << 8) | second;
1828 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1829 d = pixGetDepth(pixs);
1830 if (d != 8 && d != 16)
1831 return (
PIX *)ERROR_PTR(
"pixs not 8 or 16 bpp", __func__, NULL);
1836 if (pixGetColormap(pixs))
1842 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1846 pixCopyResolution(pixd, pixs);
1847 pixCopyInputFormat(pixd, pixs);
1880 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1881 if (pixGetDepth(pixs) != 1)
1882 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
1883 if (depth != 2 && depth != 4 && depth != 8 && depth != 16 && depth != 32)
1884 return (
PIX *)ERROR_PTR(
"depth not 2, 4, 8, 16 or 32 bpp",
1892 }
else if (depth == 4) {
1897 }
else if (depth == 8) {
1902 }
else if (depth == 16) {
1914 pixCopyInputFormat(pixd, pixs);
1941 l_int32 w, h, i, j, dibit, ndibits, wpls, wpld;
1944 l_uint32 *tab, *datas, *datad, *lines, *lined;
1947 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1948 if (pixGetDepth(pixs) != 1)
1949 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
1953 if (w != pixGetWidth(pixd) || h != pixGetHeight(pixd))
1954 return (
PIX *)ERROR_PTR(
"pix sizes unequal", __func__, pixd);
1955 if (pixGetDepth(pixd) != 16)
1956 return (
PIX *)ERROR_PTR(
"pixd not 16 bpp", __func__, pixd);
1958 if ((pixd =
pixCreate(w, h, 16)) == NULL)
1959 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1961 pixCopyResolution(pixd, pixs);
1962 pixCopyInputFormat(pixd, pixs);
1965 tab = (l_uint32 *)LEPT_CALLOC(4,
sizeof(l_uint32));
1968 for (index = 0; index < 4; index++) {
1969 tab[index] = (val[(index >> 1) & 1] << 16) | val[index & 1];
1973 wpls = pixGetWpl(pixs);
1975 wpld = pixGetWpl(pixd);
1976 ndibits = (w + 1) / 2;
1977 for (i = 0; i < h; i++) {
1978 lines = datas + i * wpls;
1979 lined = datad + i * wpld;
1980 for (j = 0; j < ndibits; j++) {
1982 lined[j] = tab[dibit];
2013 l_int32 w, h, i, j, wpls, wpld, bit;
2015 l_uint32 *datas, *datad, *lines, *lined;
2018 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2019 if (pixGetDepth(pixs) != 1)
2020 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
2024 if (w != pixGetWidth(pixd) || h != pixGetHeight(pixd))
2025 return (
PIX *)ERROR_PTR(
"pix sizes unequal", __func__, pixd);
2026 if (pixGetDepth(pixd) != 32)
2027 return (
PIX *)ERROR_PTR(
"pixd not 32 bpp", __func__, pixd);
2029 if ((pixd =
pixCreate(w, h, 32)) == NULL)
2030 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2032 pixCopyResolution(pixd, pixs);
2033 pixCopyInputFormat(pixd, pixs);
2038 wpls = pixGetWpl(pixs);
2040 wpld = pixGetWpl(pixd);
2041 for (i = 0; i < h; i++) {
2042 lines = datas + i * wpls;
2043 lined = datad + i * wpld;
2044 for (j = 0; j <w; j++) {
2046 lined[j] = val[bit];
2075 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2076 if (pixGetDepth(pixs) != 1)
2077 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
2080 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2085 pixCopyInputFormat(pixd, pixs);
2115 l_int32 w, h, i, j, byteval, nbytes, wpls, wpld;
2119 l_uint32 *datas, *datad, *lines, *lined;
2122 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
2123 if (pixGetDepth(pixs) != 1)
2124 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, pixd);
2128 if (w != pixGetWidth(pixd) || h != pixGetHeight(pixd))
2129 return (
PIX *)ERROR_PTR(
"pix sizes unequal", __func__, pixd);
2130 if (pixGetDepth(pixd) != 2)
2131 return (
PIX *)ERROR_PTR(
"pixd not 2 bpp", __func__, pixd);
2133 if ((pixd =
pixCreate(w, h, 2)) == NULL)
2134 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2136 pixCopyResolution(pixd, pixs);
2137 pixCopyInputFormat(pixd, pixs);
2140 tab = (l_uint16 *)LEPT_CALLOC(256,
sizeof(l_uint16));
2143 for (index = 0; index < 256; index++) {
2144 tab[index] = (val[(index >> 7) & 1] << 14) |
2145 (val[(index >> 6) & 1] << 12) |
2146 (val[(index >> 5) & 1] << 10) |
2147 (val[(index >> 4) & 1] << 8) |
2148 (val[(index >> 3) & 1] << 6) |
2149 (val[(index >> 2) & 1] << 4) |
2150 (val[(index >> 1) & 1] << 2) | val[index & 1];
2154 wpls = pixGetWpl(pixs);
2156 wpld = pixGetWpl(pixd);
2157 nbytes = (w + 7) / 8;
2158 for (i = 0; i < h; i++) {
2159 lines = datas + i * wpls;
2160 lined = datad + i * wpld;
2161 for (j = 0; j < nbytes; j++) {
2193 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2194 if (pixGetDepth(pixs) != 1)
2195 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
2198 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2203 pixCopyInputFormat(pixd, pixs);
2233 l_int32 w, h, i, j, byteval, nbytes, wpls, wpld;
2236 l_uint32 *tab, *datas, *datad, *lines, *lined;
2239 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
2240 if (pixGetDepth(pixs) != 1)
2241 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, pixd);
2245 if (w != pixGetWidth(pixd) || h != pixGetHeight(pixd))
2246 return (
PIX *)ERROR_PTR(
"pix sizes unequal", __func__, pixd);
2247 if (pixGetDepth(pixd) != 4)
2248 return (
PIX *)ERROR_PTR(
"pixd not 4 bpp", __func__, pixd);
2250 if ((pixd =
pixCreate(w, h, 4)) == NULL)
2251 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2253 pixCopyResolution(pixd, pixs);
2254 pixCopyInputFormat(pixd, pixs);
2257 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
2260 for (index = 0; index < 256; index++) {
2261 tab[index] = (val[(index >> 7) & 1] << 28) |
2262 (val[(index >> 6) & 1] << 24) |
2263 (val[(index >> 5) & 1] << 20) |
2264 (val[(index >> 4) & 1] << 16) |
2265 (val[(index >> 3) & 1] << 12) |
2266 (val[(index >> 2) & 1] << 8) |
2267 (val[(index >> 1) & 1] << 4) | val[index & 1];
2271 wpls = pixGetWpl(pixs);
2273 wpld = pixGetWpl(pixd);
2274 nbytes = (w + 7) / 8;
2275 for (i = 0; i < h; i++) {
2276 lines = datas + i * wpls;
2277 lined = datad + i * wpld;
2278 for (j = 0; j < nbytes; j++) {
2280 lined[j] = tab[byteval];
2310 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2311 if (pixGetDepth(pixs) != 1)
2312 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
2315 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2320 pixCopyInputFormat(pixd, pixs);
2350 l_int32 w, h, i, j, qbit, nqbits, wpls, wpld;
2353 l_uint32 *tab, *datas, *datad, *lines, *lined;
2356 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, pixd);
2357 if (pixGetDepth(pixs) != 1)
2358 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, pixd);
2362 if (w != pixGetWidth(pixd) || h != pixGetHeight(pixd))
2363 return (
PIX *)ERROR_PTR(
"pix sizes unequal", __func__, pixd);
2364 if (pixGetDepth(pixd) != 8)
2365 return (
PIX *)ERROR_PTR(
"pixd not 8 bpp", __func__, pixd);
2367 if ((pixd =
pixCreate(w, h, 8)) == NULL)
2368 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2370 pixCopyResolution(pixd, pixs);
2371 pixCopyInputFormat(pixd, pixs);
2375 tab = (l_uint32 *)LEPT_CALLOC(16,
sizeof(l_uint32));
2378 for (index = 0; index < 16; index++) {
2379 tab[index] = ((l_uint32)val[(index >> 3) & 1] << 24) |
2380 (val[(index >> 2) & 1] << 16) |
2381 (val[(index >> 1) & 1] << 8) | val[index & 1];
2385 wpls = pixGetWpl(pixs);
2387 wpld = pixGetWpl(pixd);
2388 nqbits = (w + 3) / 4;
2389 for (i = 0; i < h; i++) {
2390 lines = datas + i * wpls;
2391 lined = datad + i * wpld;
2392 for (j = 0; j < nqbits; j++) {
2394 lined[j] = tab[qbit];
2441 l_int32 w, h, i, j, nbytes, wpls, wpld, dibit, byte;
2444 l_uint32 *tab, *datas, *datad, *lines, *lined;
2449 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2450 if (pixGetDepth(pixs) != 2)
2451 return (
PIX *)ERROR_PTR(
"pixs not 2 bpp", __func__, NULL);
2453 cmaps = pixGetColormap(pixs);
2454 if (cmaps && cmapflag == FALSE)
2458 if ((pixd =
pixCreate(w, h, 8)) == NULL)
2459 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2461 pixCopyResolution(pixd, pixs);
2462 pixCopyInputFormat(pixd, pixs);
2464 wpls = pixGetWpl(pixs);
2466 wpld = pixGetWpl(pixd);
2468 if (cmapflag == TRUE) {
2479 for (i = 0; i < h; i++) {
2480 lines = datas + i * wpls;
2481 lined = datad + i * wpld;
2482 for (j = 0; j < w; j++) {
2493 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
2498 for (index = 0; index < 256; index++) {
2499 tab[index] = (val[(index >> 6) & 3] << 24) |
2500 (val[(index >> 4) & 3] << 16) |
2501 (val[(index >> 2) & 3] << 8) | val[index & 3];
2504 nbytes = (w + 3) / 4;
2505 for (i = 0; i < h; i++) {
2506 lines = datas + i * wpls;
2507 lined = datad + i * wpld;
2508 for (j = 0; j < nbytes; j++) {
2510 lined[j] = tab[byte];
2547 l_int32 w, h, i, j, wpls, wpld, byte, qbit;
2548 l_uint32 *datas, *datad, *lines, *lined;
2553 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2554 if (pixGetDepth(pixs) != 4)
2555 return (
PIX *)ERROR_PTR(
"pixs not 4 bpp", __func__, NULL);
2557 cmaps = pixGetColormap(pixs);
2558 if (cmaps && cmapflag == FALSE)
2562 if ((pixd =
pixCreate(w, h, 8)) == NULL)
2563 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2564 pixCopyResolution(pixd, pixs);
2565 pixCopyInputFormat(pixd, pixs);
2567 wpls = pixGetWpl(pixs);
2569 wpld = pixGetWpl(pixd);
2571 if (cmapflag == TRUE) {
2576 for (i = 0; i < 16; i++)
2580 for (i = 0; i < h; i++) {
2581 lines = datas + i * wpls;
2582 lined = datad + i * wpld;
2583 for (j = 0; j < w; j++) {
2593 for (i = 0; i < h; i++) {
2594 lines = datas + i * wpls;
2595 lined = datad + i * wpld;
2596 for (j = 0; j < w; j++) {
2598 byte = (qbit << 4) | qbit;
2630 l_int32 i, j, w, h, d, wplt, wpld, val;
2631 l_uint32 *datat, *datad, *linet, *lined;
2635 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2638 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
2639 if (leftshift < 0 || leftshift > 8)
2640 return (
PIX *)ERROR_PTR(
"leftshift not in [0 ... 8]", __func__, NULL);
2642 if (pixGetColormap(pixs) != NULL)
2648 pixCopyResolution(pixd, pixs);
2649 pixCopyInputFormat(pixd, pixs);
2652 wplt = pixGetWpl(pixt);
2653 wpld = pixGetWpl(pixd);
2654 for (i = 0; i < h; i++) {
2655 linet = datat + i * wplt;
2656 lined = datad + i * wpld;
2657 for (j = 0; j < w; j++) {
2660 val = val | (val << leftshift);
2694 PIX *pix1, *pix2, *pix3, *pixd;
2697 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2698 d = pixGetDepth(pixs);
2699 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 24 && d != 32)
2700 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,24,32}", __func__, NULL);
2702 if (pixGetColormap(pixs) != NULL) {
2704 d = pixGetDepth(pix1);
2708 if (d == 24 || d == 32)
2715 }
else if (d == 2) {
2717 }
else if (d == 4) {
2743 l_int32 i, j, w, h, wpls, wpld;
2745 l_uint32 *datas, *lines, *datad, *lined;
2748 if (!pix || pixGetDepth(pix) != 8)
2749 return (
PIX *)ERROR_PTR(
"pix undefined or not 8 bpp", __func__, NULL);
2751 if (pixGetColormap(pix) != NULL)
2757 wpls = pixGetWpl(pixs);
2760 wpld = pixGetWpl(pixd);
2761 for (i = 0; i < h; i++) {
2762 lines = datas + i * wpls;
2763 lined = datad + i * wpld;
2764 for (j = 0; j < wpls; j++) {
2765 word = lines[j] & 0xc0c0c0c0;
2766 word = (word >> 24) | ((word & 0xff0000) >> 18) |
2767 ((word & 0xff00) >> 12) | ((word & 0xff) >> 6);
2798 PIX *pix1, *pix2, *pix3, *pixd;
2801 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2802 d = pixGetDepth(pixs);
2803 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 24 && d != 32)
2804 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,24,32}", __func__, NULL);
2806 if (pixGetColormap(pixs) != NULL) {
2808 d = pixGetDepth(pix1);
2812 if (d == 24 || d == 32)
2819 }
else if (d == 2) {
2823 }
else if (d == 4) {
2847 l_int32 i, j, w, h, wpls, wpld, val;
2848 l_uint32 *datas, *lines, *datad, *lined;
2851 if (!pix || pixGetDepth(pix) != 8)
2852 return (
PIX *)ERROR_PTR(
"pix undefined or not 8 bpp", __func__, NULL);
2854 if (pixGetColormap(pix) != NULL)
2860 wpls = pixGetWpl(pixs);
2863 wpld = pixGetWpl(pixd);
2864 for (i = 0; i < h; i++) {
2865 lines = datas + i * wpls;
2866 lined = datad + i * wpld;
2867 for (j = 0; j < w; j++) {
2897 l_int32 d, color0, color1, rval, gval, bval;
2898 PIX *pix1, *pix2, *pixd;
2902 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2903 d = pixGetDepth(pixs);
2904 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
2905 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
2907 cmap = pixGetColormap(pixs);
2914 color0 = rval + gval + bval;
2916 color1 = rval + gval + bval;
2919 if (color1 > color0)
2955 l_int32 d, color0, color1, rval, gval, bval;
2960 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2961 d = pixGetDepth(pixs);
2962 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
2963 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
2965 cmap = pixGetColormap(pixs);
2972 color0 = rval + gval + bval;
2974 color1 = rval + gval + bval;
2977 if (color1 > color0)
3010 l_float32 scalefactor;
3014 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3016 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3018 scalefactor = 1. / (l_float32)factor;
3063 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3064 d = pixGetDepth(pixs);
3065 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
3066 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
3073 }
else if (d == 2) {
3075 }
else if (d == 4) {
3077 }
else if (d == 8) {
3078 cmap = pixGetColormap(pixs);
3079 if ((cmap && cmapflag) || (!cmap && !cmapflag)) {
3088 }
else if (d == 16) {
3093 }
else if (d == 24) {
3128 l_float32 scalefactor;
3132 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3134 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3136 scalefactor = 1. / (l_float32)factor;
3172 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3173 d = pixGetDepth(pixs);
3174 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
3175 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,32}", __func__, NULL);
3204 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3206 d = pixGetDepth(pixs);
3212 return (
PIX *)ERROR_PTR(
"src depth not 1 or 8 bpp", __func__, NULL);
3252 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3254 d = pixGetDepth(pixs);
3257 }
else if (d == 2) {
3262 }
else if (d == 4) {
3267 }
else if (d == 8) {
3269 }
else if (d == 16) {
3274 }
else if (d == 24) {
3276 }
else if (d == 32) {
3279 return (
PIX *)ERROR_PTR(
"depth not 1, 2, 4, 8, 16, 32 bpp",
3302 l_float32 scalefactor;
3306 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3308 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3310 scalefactor = 1. / (l_float32)factor;
3334 l_int32 i, j, w, h, wpls, wpld, val;
3335 l_uint32 *datas, *datad, *lines, *lined;
3340 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3341 if (pixGetDepth(pixs) != 8)
3342 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
3344 if (pixGetColormap(pixs))
3349 wpls = pixGetWpl(pixs);
3350 if ((pixd =
pixCreate(w, h, 32)) == NULL)
3351 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3352 pixCopyResolution(pixd, pixs);
3353 pixCopyInputFormat(pixd, pixs);
3355 wpld = pixGetWpl(pixd);
3358 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
3359 for (i = 0; i < 256; i++)
3360 tab[i] = ((l_uint32)i << 24) | (i << 16) | (i << 8);
3363 for (i = 0; i < h; i++) {
3364 lines = datas + i * wpls;
3365 lined = datad + i * wpld;
3366 for (j = 0; j < w; j++) {
3368 lined[j] = tab[val];
3408 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3410 return (
PIX *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
3412 d = pixGetDepth(pixs);
3413 if (pixGetColormap(pixs)) {
3414 if (warnflag) L_WARNING(
"pix has colormap; removing\n", __func__);
3416 }
else if (d == 8 || d == 32) {
3426 d = pixGetDepth(pixd);
3427 if (d != 8 && d != 32) {
3429 return (
PIX *)ERROR_PTR(
"depth not 8 or 32 bpp", __func__, NULL);
3464 l_int32 w, h, d, i, j, wpls, wpld, rval, gval, bval;
3466 l_uint32 *datas, *datad, *lined;
3470 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3473 return (
PIX *)ERROR_PTR(
"pixs not 24 bpp", __func__, NULL);
3478 wpls = pixGetWpl(pixs);
3479 wpld = pixGetWpl(pixd);
3480 for (i = 0; i < h; i++) {
3481 lines = (l_uint8 *)(datas + i * wpls);
3482 lined = datad + i * wpld;
3483 for (j = 0; j < w; j++) {
3491 pixCopyResolution(pixd, pixs);
3492 pixCopyInputFormat(pixd, pixs);
3512 l_int32 w, h, d, i, j, wpls, wpld, rval, gval, bval;
3513 l_uint32 *datas, *lines, *rgbdata;
3517 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3520 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
3523 wpls = pixGetWpl(pixs);
3526 wpld = pixGetWpl(pixd);
3527 for (i = 0; i < h; i++) {
3528 lines = datas + i * wpls;
3529 rgbdata8 = (l_uint8 *)(rgbdata + i * wpld);
3530 for (j = 0; j < w; j++) {
3537 pixCopyResolution(pixd, pixs);
3538 pixCopyInputFormat(pixd, pixs);
3564 l_int32 w, h, i, j, wpls, wpld;
3566 l_uint32 *datas, *lines, *datad, *lined;
3569 if (!pixs || pixGetDepth(pixs) != 32)
3570 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
3573 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
3576 if ((pixd =
pixCreate(w, h, 16)) == NULL)
3577 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3578 pixCopyResolution(pixd, pixs);
3579 pixCopyInputFormat(pixd, pixs);
3580 wpls = pixGetWpl(pixs);
3582 wpld = pixGetWpl(pixd);
3585 for (i = 0; i < h; i++) {
3586 lines = datas + i * wpls;
3587 lined = datad + i * wpld;
3589 for (j = 0; j < wpls; j++) {
3590 sword = *(lines + j);
3591 dword = sword & 0xffff;
3595 for (j = 0; j < wpls; j++) {
3596 sword = *(lines + j);
3597 dword = sword >> 16;
3601 for (j = 0; j < wpls; j++) {
3602 sword = *(lines + j);
3603 dword = (sword >> 16) ? 0xffff : (sword & 0xffff);
3628 if (!pixs || pixGetDepth(pixs) != 32)
3629 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
3632 return (
PIX *)ERROR_PTR(
"invalid type16", __func__, NULL);
3634 return (
PIX *)ERROR_PTR(
"invalid type8", __func__, NULL);
3662 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3664 if (pixGetDepth(pixs) == 32 && pixGetSpp(pixs) == 4)
3699 if (!pixs || (pixGetDepth(pixs) != 1))
3700 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
3701 if (pixd && (pixd != pixs))
3702 return (
PIX *)ERROR_PTR(
"pixd defined but != pixs", __func__, NULL);
3737 l_int32 w, h, ds, wpls, wpld, i, j, val;
3738 l_uint32 *datas, *datad, *lines, *lined;
3742 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3743 if (pixGetColormap(pixs))
3744 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
3745 if (d != 2 && d != 4 && d != 8)
3746 return (
PIX *)ERROR_PTR(
"invalid dest depth", __func__, NULL);
3750 return (
PIX *)ERROR_PTR(
"depth > d", __func__, NULL);
3754 if ((pixd =
pixCreate(w, h, d)) == NULL)
3755 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3756 pixCopyResolution(pixd, pixs);
3757 pixCopyInputFormat(pixd, pixs);
3761 wpls = pixGetWpl(pixs);
3763 wpld = pixGetWpl(pixd);
3764 for (i = 0; i < h; i++) {
3765 lines = datas + i * wpls;
3766 lined = datad + i * wpld;
3770 for (j = 0; j < w; j++) {
3781 for (j = 0; j < w; j++) {
3790 for (j = 0; j < w; j++) {
3830 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3832 cmap = pixGetColormap(pixs);
3833 d = pixGetDepth(pixs);
3910 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3911 d = pixGetDepth(pixs);
3912 cmap = pixGetColormap(pixs);
3913 if (d != 8 && d != 32 && !cmap)
3914 return (
PIX *)ERROR_PTR(
"pix not 8 or 32 bpp and not cmapped",
3916 if (scalex <= 0.0 || scaley <= 0.0)
3917 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
3920 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
3922 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
3924 d = pixGetDepth(pix1);
3931 L_ERROR(
"invalid depth %d\n", __func__, d);
3973 l_int32 w, h, d, wd, hd, wplt, wpld, i, j, rval, gval, bval, direction;
3974 l_uint32 *datat, *datad, *linet, *lined;
3975 PIX *pix1, *pix2, *pixd;
3979 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3980 d = pixGetDepth(pixs);
3981 cmap = pixGetColormap(pixs);
3982 if (d != 8 && !cmap)
3983 return (
PIX *)ERROR_PTR(
"pix not 8 bpp & not cmapped", __func__, NULL);
3984 if (scalex <= 0.0 || scaley <= 0.0)
3985 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
3988 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
3994 if (direction == L_HORIZ)
3995 pix2 =
pixScale(pix1, 3.0 * scalex, scaley);
3997 pix2 =
pixScale(pix1, scalex, 3.0 * scaley);
4000 wd = (direction == L_HORIZ) ? w / 3 : w;
4001 hd = (direction == L_VERT) ? h / 3 : h;
4004 wpld = pixGetWpl(pixd);
4006 wplt = pixGetWpl(pix2);
4007 if (direction == L_HORIZ) {
4008 for (i = 0; i < hd; i++) {
4009 linet = datat + i * wplt;
4010 lined = datad + i * wpld;
4011 for (j = 0; j < wd; j++) {
4022 for (i = 0; i < hd; i++) {
4023 linet = datat + 3 * i * wplt;
4024 lined = datad + i * wpld;
4025 for (j = 0; j < wd; j++) {
4076 l_int32 w, h, d, wd, hd, wplt, wpld, i, j, rval, gval, bval, direction;
4077 l_uint32 *datat, *datad, *linet, *lined;
4078 PIX *pix1, *pix2, *pixd;
4082 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
4083 d = pixGetDepth(pixs);
4084 cmap = pixGetColormap(pixs);
4085 if (d != 32 && !cmap)
4086 return (
PIX *)ERROR_PTR(
"pix not 32 bpp & not cmapped", __func__, NULL);
4087 if (scalex <= 0.0 || scaley <= 0.0)
4088 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
4091 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
4097 if (direction == L_HORIZ)
4098 pix2 =
pixScale(pix1, 3.0 * scalex, scaley);
4100 pix2 =
pixScale(pix1, scalex, 3.0 * scaley);
4103 wd = (direction == L_HORIZ) ? w / 3 : w;
4104 hd = (direction == L_VERT) ? h / 3 : h;
4106 pixCopyInputFormat(pixd, pixs);
4108 wpld = pixGetWpl(pixd);
4110 wplt = pixGetWpl(pix2);
4111 if (direction == L_HORIZ) {
4112 for (i = 0; i < hd; i++) {
4113 linet = datat + i * wplt;
4114 lined = datad + i * wpld;
4115 for (j = 0; j < wd; j++) {
4129 for (i = 0; i < hd; i++) {
4130 linet = datat + 3 * i * wplt;
4131 lined = datad + i * wpld;
4132 for (j = 0; j < wd; j++) {
4147 if (pixGetSpp(pixs) == 4)
4175 L_ERROR(
"invalid reference value for neutral boost\n", __func__);
4178 var_NEUTRAL_BOOST_VAL = val;
PIX * pixBackgroundNormSimple(PIX *pixs, PIX *pixim, PIX *pixg)
pixBackgroundNormSimple()
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(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 * pixAlphaBlendUniform(PIX *pixs, l_uint32 color)
pixAlphaBlendUniform()
l_ok pixColorsForQuantization(PIX *pixs, l_int32 thresh, l_int32 *pncolors, l_int32 *piscolor, l_int32 debug)
pixColorsForQuantization()
l_ok pixNumColors(PIX *pixs, l_int32 factor, l_int32 *pncolors)
pixNumColors()
void pixcmapDestroy(PIXCMAP **pcmap)
pixcmapDestroy()
l_ok pixcmapHasColor(PIXCMAP *cmap, l_int32 *pcolor)
pixcmapHasColor()
l_int32 pixcmapGetCount(const PIXCMAP *cmap)
pixcmapGetCount()
l_ok pixcmapGetDistanceToColor(PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pdist)
pixcmapGetDistanceToColor()
PIXCMAP * pixcmapConvertTo8(PIXCMAP *cmaps)
pixcmapConvertTo8()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
l_ok pixcmapAddRGBA(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval)
pixcmapAddRGBA()
PIXCMAP * pixcmapGrayToFalseColor(l_float32 gamma)
pixcmapGrayToFalseColor()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixcmapIsOpaque(PIXCMAP *cmap, l_int32 *popaque)
pixcmapIsOpaque()
PIXCMAP * pixcmapGrayToColor(l_uint32 color)
pixcmapGrayToColor()
l_ok pixcmapGetRangeValues(PIXCMAP *cmap, l_int32 select, l_int32 *pminval, l_int32 *pmaxval, l_int32 *pminindex, l_int32 *pmaxindex)
pixcmapGetRangeValues()
PIXCMAP * pixcmapCreateLinear(l_int32 d, l_int32 nlevels)
pixcmapCreateLinear()
l_ok pixcmapToArrays(const PIXCMAP *cmap, l_int32 **prmap, l_int32 **pgmap, l_int32 **pbmap, l_int32 **pamap)
pixcmapToArrays()
l_ok pixcmapIsBlackAndWhite(PIXCMAP *cmap, l_int32 *pblackwhite)
pixcmapIsBlackAndWhite()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
l_ok pixcmapToRGBTable(PIXCMAP *cmap, l_uint32 **ptab, l_int32 *pncolors)
pixcmapToRGBTable()
PIX * pixFewColorsOctcubeQuant1(PIX *pixs, l_int32 level)
pixFewColorsOctcubeQuant1()
NUMA * pixOctcubeHistogram(PIX *pixs, l_int32 level, l_int32 *pncolors)
pixOctcubeHistogram()
PIX * pixOctreeColorQuant(PIX *pixs, l_int32 colors, l_int32 ditherflag)
pixOctreeColorQuant()
PIX * pixFewColorsOctcubeQuant2(PIX *pixs, l_int32 level, NUMA *na, l_int32 ncolors, l_int32 *pnerrors)
pixFewColorsOctcubeQuant2()
PIX * pixConvertRGBToHue(PIX *pixs)
pixConvertRGBToHue()
PIX * pixConvertRGBToSaturation(PIX *pixs)
pixConvertRGBToSaturation()
PIX * pixThresholdTo2bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdTo2bpp()
PIX * pixThresholdTo4bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdTo4bpp()
PIX * pixThresholdOn8bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdOn8bpp()
PIX * pixThresholdToBinary(PIX *pixs, l_int32 thresh)
pixThresholdToBinary()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok numaGetCountRelativeToZero(NUMA *na, l_int32 type, l_int32 *pcount)
numaGetCountRelativeToZero()
NUMA * numaNormalizeHistogram(NUMA *nas, l_float32 tsum)
numaNormalizeHistogram()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
l_ok pixDestroyColormap(PIX *pix)
pixDestroyColormap()
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 * pixCreateTemplate(const PIX *pixs)
pixCreateTemplate()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
l_ok composeRGBAPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_int32 aval, l_uint32 *ppixel)
composeRGBAPixel()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
PIX * pixInvert(PIX *pixd, PIX *pixs)
pixInvert()
NUMA * pixGetGrayHistogram(PIX *pixs, l_int32 factor)
pixGetGrayHistogram()
NUMA * pixGetCmapHistogram(PIX *pixs, l_int32 factor)
pixGetCmapHistogram()
static const l_float32 L_BLUE_WEIGHT
static const l_float32 L_RED_WEIGHT
@ REMOVE_CMAP_TO_FULL_COLOR
@ REMOVE_CMAP_TO_GRAYSCALE
@ REMOVE_CMAP_BASED_ON_SRC
static const l_float32 L_GREEN_WEIGHT
PIX * pixConvertRGBToGrayGeneral(PIX *pixs, l_int32 type, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixConvertRGBToGrayGeneral()
PIX * pixUnpackBinary(PIX *pixs, l_int32 depth, l_int32 invert)
pixUnpackBinary()
PIX * pixConvert1To8Cmap(PIX *pixs)
pixConvert1To8Cmap()
PIX * pixConvertColorToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertColorToSubpixelRGB()
PIX * pixConvert1To32(PIX *pixd, PIX *pixs, l_uint32 val0, l_uint32 val1)
pixConvert1To32()
PIX * pixConvertTo1Adaptive(PIX *pixs)
pixConvertTo1Adaptive()
PIX * pixConvert1To16(PIX *pixd, PIX *pixs, l_uint16 val0, l_uint16 val1)
pixConvert1To16()
PIX * pixConvertRGBToGrayMinMax(PIX *pixs, l_int32 type)
pixConvertRGBToGrayMinMax()
l_ok pixQuantizeIfFewColors(PIX *pixs, l_int32 maxcolors, l_int32 mingraycolors, l_int32 octlevel, PIX **ppixd)
pixQuantizeIfFewColors()
PIX * pixConvertTo8Or32(PIX *pixs, l_int32 copyflag, l_int32 warnflag)
pixConvertTo8Or32()
PIX * pixRemoveAlpha(PIX *pixs)
pixRemoveAlpha()
PIX * pixConvertTo1BySampling(PIX *pixs, l_int32 factor, l_int32 threshold)
pixConvertTo1BySampling()
PIX * pixConvertTo2(PIX *pixs)
pixConvertTo2()
PIX * pixConvertCmapTo1(PIX *pixs)
pixConvertCmapTo1()
PIX * pixConvert4To8(PIX *pixs, l_int32 cmapflag)
pixConvert4To8()
PIX * pixConvertRGBToGray(PIX *pixs, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixConvertRGBToGray()
PIX * pixAddAlphaTo1bpp(PIX *pixd, PIX *pixs)
pixAddAlphaTo1bpp()
PIX * pixConvert2To8(PIX *pixs, l_uint8 val0, l_uint8 val1, l_uint8 val2, l_uint8 val3, l_int32 cmapflag)
pixConvert2To8()
PIX * pixConvert1To4(PIX *pixd, PIX *pixs, l_int32 val0, l_int32 val1)
pixConvert1To4()
PIX * pixConvert1To4Cmap(PIX *pixs)
pixConvert1To4Cmap()
PIX * pixConvert32To16(PIX *pixs, l_int32 type)
pixConvert32To16()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertRGBToColormap(PIX *pixs, l_int32 ditherflag)
pixConvertRGBToColormap()
l_ok pixAddGrayColormap8(PIX *pixs)
pixAddGrayColormap8()
PIX * pixColorizeGray(PIX *pixs, l_uint32 color, l_int32 cmapflag)
pixColorizeGray()
PIX * pixConvertGrayToColormap8(PIX *pixs, l_int32 mindepth)
pixConvertGrayToColormap8()
PIX * pixConvertTo8BySampling(PIX *pixs, l_int32 factor, l_int32 cmapflag)
pixConvertTo8BySampling()
PIX * pixConvertTo8Colormap(PIX *pixs, l_int32 dither)
pixConvertTo8Colormap()
PIX * pixConvertGrayToFalseColor(PIX *pixs, l_float32 gamma)
pixConvertGrayToFalseColor()
PIX * pixThreshold8(PIX *pixs, l_int32 d, l_int32 nlevels, l_int32 cmapflag)
pixThreshold8()
PIX * pixConvert8To16(PIX *pixs, l_int32 leftshift)
pixConvert8To16()
PIX * pixConvertTo1(PIX *pixs, l_int32 threshold)
pixConvertTo1()
PIX * pixConvertForPSWrap(PIX *pixs)
pixConvertForPSWrap()
PIX * pixAddMinimalGrayColormap8(PIX *pixs)
pixAddMinimalGrayColormap8()
PIX * pixConvert1To2Cmap(PIX *pixs)
pixConvert1To2Cmap()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixConvertLossless(PIX *pixs, l_int32 d)
pixConvertLossless()
PIX * pixConvertTo32BySampling(PIX *pixs, l_int32 factor)
pixConvertTo32BySampling()
PIX * pixConvert1To2(PIX *pixd, PIX *pixs, l_int32 val0, l_int32 val1)
pixConvert1To2()
PIX * pixConvertTo4(PIX *pixs)
pixConvertTo4()
PIX * pixConvertTo16(PIX *pixs)
pixConvertTo16()
PIX * pixRemoveColormapGeneral(PIX *pixs, l_int32 type, l_int32 ifnocmap)
pixRemoveColormapGeneral()
PIX * pixConvertRGBToGrayArb(PIX *pixs, l_float32 rc, l_float32 gc, l_float32 bc)
pixConvertRGBToGrayArb()
PIX * pixConvert8To32(PIX *pixs)
pixConvert8To32()
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixConvertRGBToGraySatBoost(PIX *pixs, l_int32 refval)
pixConvertRGBToGraySatBoost()
PIX * pixConvert8To4(PIX *pix)
pixConvert8To4()
PIX * pixConvert8To2(PIX *pix)
pixConvert8To2()
PIX * pixConvertGrayToColormap(PIX *pixs)
pixConvertGrayToColormap()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
PIX * pixConvert32To8(PIX *pixs, l_int32 type16, l_int32 type8)
pixConvert32To8()
PIX * pixConvertRGBToGrayFast(PIX *pixs)
pixConvertRGBToGrayFast()
PIX * pixConvert16To8(PIX *pixs, l_int32 type)
pixConvert16To8()
PIX * pixConvert24To32(PIX *pixs)
pixConvert24To32()
void l_setNeutralBoostVal(l_int32 val)
l_setNeutralBoostVal()
PIX * pixConvertGrayToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertGrayToSubpixelRGB()
PIX * pixConvertRGBToBinaryArb(PIX *pixs, l_float32 rc, l_float32 gc, l_float32 bc, l_int32 thresh, l_int32 relation)
pixConvertRGBToBinaryArb()
PIX * pixConvert32To24(PIX *pixs)
pixConvert32To24()
PIX * pixConvertToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertToSubpixelRGB()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
PIX * pixScaleBySampling(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBySampling()
l_ok pixScaleAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleAndTransferAlpha()
void lept_stderr(const char *fmt,...)
lept_stderr()