158#include <config_auto.h>
163#include "allheaders.h"
167static l_int32 var_NEUTRAL_BOOST_VAL = 180;
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);
227 pixd = pixThresholdToBinary(pixs, 128);
229 cmap = pixcmapCreateLinear(1, 2);
230 pixSetColormap(pixd, cmap);
234 pixd = pixThresholdTo2bpp(pixs, nlevels, cmapflag);
237 pixd = pixThresholdTo4bpp(pixs, nlevels, cmapflag);
240 pixd = pixThresholdOn8bpp(pixs, nlevels, cmapflag);
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))
289 return pixClone(pixs);
291 return pixCopy(NULL, pixs);
327l_int32 sval, rval, gval, bval, val0, val1;
328l_int32 i, j, k, w, h, d, wpls, wpld, ncolors, nalloc, count;
329l_int32 opaque, colorfound, blackwhite;
330l_int32 *rmap, *gmap, *bmap, *amap;
331l_uint32 *datas, *lines, *datad, *lined, *lut, *graymap;
332l_uint32 sword, dword;
337 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
338 if ((cmap = pixGetColormap(pixs)) == NULL)
339 return pixClone(pixs);
345 L_WARNING(
"Invalid type; converting based on src\n", __func__);
348 pixGetDimensions(pixs, &w, &h, &d);
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);
352 ncolors = pixcmapGetCount(cmap);
354 if (ncolors > nalloc)
355 return (
PIX *)ERROR_PTR(
"too many colors for pixel depth",
358 if (pixcmapToArrays(cmap, &rmap, &gmap, &bmap, &amap))
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__);
368 pixcmapIsOpaque(cmap, &opaque);
369 pixcmapHasColor(cmap, &colorfound);
370 pixcmapIsBlackAndWhite(cmap, &blackwhite);
373 }
else if (colorfound) {
376 if (d == 1 && blackwhite)
383 datas = pixGetData(pixs);
384 wpls = pixGetWpl(pixs);
386 if ((pixd = pixCopy(NULL, pixs)) == NULL) {
387 L_ERROR(
"pixd not made\n", __func__);
390 pixcmapGetColor(cmap, 0, &rval, &gval, &bval);
391 val0 = rval + gval + bval;
392 pixcmapGetColor(cmap, 1, &rval, &gval, &bval);
393 val1 = rval + gval + bval;
395 pixInvert(pixd, pixd);
396 pixDestroyColormap(pixd);
398 if ((pixd = pixCreate(w, h, 8)) == NULL) {
399 L_ERROR(
"pixd not made\n", __func__);
402 pixCopyResolution(pixd, pixs);
403 pixCopyInputFormat(pixd, pixs);
404 datad = pixGetData(pixd);
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);
561 datad = pixGetData(pixd);
562 wpld = pixGetWpl(pixd);
563 lut = (l_uint32 *)LEPT_CALLOC(nalloc,
sizeof(l_uint32));
564 for (i = 0; i < ncolors; i++) {
566 composeRGBPixel(rmap[i], gmap[i], bmap[i], lut + i);
568 composeRGBAPixel(rmap[i], gmap[i], bmap[i], amap[i], lut + 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))
625 cmap = pixcmapCreateLinear(8, 256);
626 pixSetColormap(pixs, cmap);
647l_int32 ncolors, w, h, i, j, wpl1, wpld, index, val;
648l_int32 *inta, *revmap;
649l_uint32 *data1, *datad, *line1, *lined;
653 if (!pixs || pixGetDepth(pixs) != 8)
654 return (
PIX *)ERROR_PTR(
"pixs undefined or not 8 bpp", __func__, NULL);
657 pixNumColors(pixs, 1, &ncolors);
658 cmap = pixGetColormap(pixs);
660 if (pixcmapGetCount(cmap) == ncolors)
661 return pixCopy(NULL, pixs);
665 if (ncolors == 256) {
666 pix1 = pixCopy(NULL, pixs);
670 pix1 = pixClone(pixs);
674 pixGetDimensions(pix1, &w, &h, NULL);
675 data1 = pixGetData(pix1);
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++) {
685 cmap = pixcmapCreate(8);
686 revmap = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
687 for (i = 0, index = 0; i < 256; i++) {
689 pixcmapAddColor(cmap, i, i, i);
695 pixd = pixCreateTemplate(pix1);
696 pixSetColormap(pixd, cmap);
697 pixCopyInputFormat(pixd, pixs);
698 pixCopyResolution(pixd, pixs);
699 datad = pixGetData(pixd);
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);
774 pix1 = pixGetRGBComponent(pixs,
COLOR_RED);
786 pix1 = pixConvertRGBToHue(pixs);
788 pix1 = pixConvertRGBToSaturation(pixs);
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);
820l_int32 i, j, w, h, wpls, wpld, val;
822l_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__);
848 pixGetDimensions(pixs, &w, &h, NULL);
849 datas = pixGetData(pixs);
850 wpls = pixGetWpl(pixs);
851 if ((pixd = pixCreate(w, h, 8)) == NULL)
852 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
853 pixCopyResolution(pixd, pixs);
854 pixCopyInputFormat(pixd, pixs);
855 datad = pixGetData(pixd);
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);
893l_int32 i, j, w, h, wpls, wpld, val;
894l_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);
902 pixGetDimensions(pixs, &w, &h, NULL);
903 datas = pixGetData(pixs);
904 wpls = pixGetWpl(pixs);
905 if ((pixd = pixCreate(w, h, 8)) == NULL)
906 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
907 pixCopyResolution(pixd, pixs);
908 pixCopyInputFormat(pixd, pixs);
909 datad = pixGetData(pixd);
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;
950l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, val, minval, maxval;
951l_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);
963 pixGetDimensions(pixs, &w, &h, NULL);
964 datas = pixGetData(pixs);
965 wpls = pixGetWpl(pixs);
966 if ((pixd = pixCreate(w, h, 8)) == NULL)
967 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
968 pixCopyResolution(pixd, pixs);
969 pixCopyInputFormat(pixd, pixs);
970 datad = pixGetData(pixd);
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++) {
977 extractRGBValues(lines[j], &rval, &gval, &bval);
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;
1035l_int32 w, h, d, i, j, wplt, wpld;
1036l_int32 rval, gval, bval, sval, minrg, maxrg, min, max, delta;
1037l_int32 fullsat, newval;
1038l_float32 *invmax, *ratio;
1039l_uint32 *linet, *lined, *datat, *datad;
1043 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1044 pixGetDimensions(pixs, &w, &h, &d);
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);
1051 pixd = pixCreate(w, h, 8);
1052 pixCopyResolution(pixd, pixs);
1053 pixCopyInputFormat(pixd, pixs);
1054 wplt = pixGetWpl(pixt);
1055 datat = pixGetData(pixt);
1056 wpld = pixGetWpl(pixd);
1057 datad = pixGetData(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.0f / (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++) {
1068 extractRGBValues(linet[j], &rval, &gval, &bval);
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;
1113l_int32 i, j, w, h, wpls, wpld, rval, gval, bval, val;
1114l_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);
1124 pixGetDimensions(pixs, &w, &h, NULL);
1125 datas = pixGetData(pixs);
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);
1131 datad = pixGetData(pixd);
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++) {
1138 extractRGBValues(lines[j], &rval, &gval, &bval);
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;
1189 pix2 = pixThresholdToBinary(pix1, threshold);
1191 pixInvert(pix2, pix2);
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__);
1237 return pixCopy(NULL, pixs);
1245 pixd = pixCopy(NULL, pixs);
1246 cmap = pixcmapCreateLinear(d, 1 << d);
1247 pixSetColormap(pixd, cmap);
1248 pixCopyInputFormat(pixd, pixs);
1279l_int32 ncolors, w, h, depth, i, j, wpls, wpld;
1280l_int32 index, num, val, newval;
1282l_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__);
1298 return pixCopy(NULL, pixs);
1301 na = pixGetGrayHistogram(pixs, 1);
1303 if (mindepth == 8 || ncolors > 16)
1305 else if (mindepth == 4 || ncolors > 4)
1310 pixGetDimensions(pixs, &w, &h, NULL);
1311 pixd = pixCreate(w, h, depth);
1312 cmap = pixcmapCreate(depth);
1313 pixSetColormap(pixd, cmap);
1314 pixCopyInputFormat(pixd, pixs);
1315 pixCopyResolution(pixd, pixs);
1318 for (i = 0; i < 256; i++) {
1320 numaGetIValue(na, i, &num);
1322 pixcmapAddColor(cmap, i, i, i);
1328 datas = pixGetData(pixs);
1329 wpls = pixGetWpl(pixs);
1330 datad = pixGetData(pixd);
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)
1375l_int32 i, j, w, h, wplt, wpld, val8;
1376l_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))
1388 pixt = pixClone(pixs);
1390 cmap = pixcmapGrayToColor(color);
1392 pixd = pixCopy(NULL, pixt);
1393 pixSetColormap(pixd, cmap);
1399 pixcmapToRGBTable(cmap, &tab, NULL);
1400 pixGetDimensions(pixt, &w, &h, NULL);
1401 pixd = pixCreate(w, h, 32);
1402 pixCopyResolution(pixd, pixs);
1403 pixCopyInputFormat(pixd, pixs);
1404 datad = pixGetData(pixd);
1405 wpld = pixGetWpl(pixd);
1406 datat = pixGetData(pixt);
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];
1418 pixcmapDestroy(&cmap);
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__);
1475 na = pixOctcubeHistogram(pixs, 4, &ncolors);
1478 if (ncolors <= 256) {
1479 pixd = pixFewColorsOctcubeQuant2(pixs, 4, na, ncolors, NULL);
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",
1495 return pixOctreeColorQuant(pixs, 240, ditherflag);
1520l_int32 i, j, nc, w, h, imin, imax, factor, wpl1, wpld;
1521l_int32 index, rmin, gmin, bmin, rmax, gmax, bmax, dmin, dmax;
1522l_float32 minfract, ifract;
1524l_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);
1538 pixcmapGetColor(cmap, imin, &rmin, &gmin, &bmin);
1539 pixcmapGetColor(cmap, imax, &rmax, &gmax, &bmax);
1540 nc = pixcmapGetCount(cmap);
1545 if ((lut = (l_int32 *)LEPT_CALLOC(nc,
sizeof(l_int32))) == NULL)
1546 return (
PIX *)ERROR_PTR(
"calloc fail for lut", __func__, NULL);
1547 pixGetDimensions(pixs, &w, &h, NULL);
1548 factor = L_MAX(1, (l_int32)sqrt((l_float64)(w * h) / 50000. + 0.5));
1549 na1 = pixGetCmapHistogram(pixs, factor);
1550 na2 = numaNormalizeHistogram(na1, 1.0);
1552 for (i = 0; i < nc; i++) {
1553 numaGetFValue(na2, i, &ifract);
1554 pixcmapGetDistanceToColor(cmap, i, rmin, gmin, bmin, &dmin);
1555 pixcmapGetDistanceToColor(cmap, i, rmax, gmax, bmax, &dmax);
1566 pixd = pixCreate(w, h, 1);
1567 data1 = pixGetData(pix1);
1568 datad = pixGetData(pixd);
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);
1586 pixInvert(pixd, pixd);
1629 l_int32 mingraycolors,
1633l_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) {
1645 *ppixd = pixClone(pixs);
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__);
1663 pixColorsForQuantization(pixs, 0, &ncolors, &iscolor, 0);
1664 if (ncolors > maxcolors)
1665 return ERROR_INT(
"too many colors", __func__, 1);
1678 pixd = pixFewColorsOctcubeQuant1(pixs, octlevel);
1680 pixd = pixFewColorsOctcubeQuant1(pixs, octlevel - 1);
1682 L_WARNING(
"quantized at level 2; low quality\n", __func__);
1688 pixg = pixClone(pixs);
1689 graycolors = L_MAX(mingraycolors, (l_int32)(1.5 * ncolors));
1690 graycolors = L_MIN(graycolors, 256);
1691 if (graycolors < 16)
1692 pixd = pixThresholdTo4bpp(pixg, graycolors, 1);
1694 pixd = pixThresholdOn8bpp(pixg, graycolors, 1);
1700 return ERROR_INT(
"pixd not made", __func__, 1);
1701 pixCopyInputFormat(pixd, pixs);
1730l_int32 w, h, wpls, wpld, i, j, val, use_lsb;
1731l_uint32 sword, first, second;
1732l_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);
1743 pixGetDimensions(pixs, &w, &h, 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);
1749 datas = pixGetData(pixs);
1750 wpld = pixGetWpl(pixd);
1751 datad = pixGetData(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))
1839 pixd = pixCopy(NULL, pixs);
1842 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1844 cmap = pixcmapGrayToFalseColor(gamma);
1845 pixSetColormap(pixd, cmap);
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);
1941l_int32 w, h, i, j, dibit, ndibits, wpls, wpld;
1944l_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);
1951 pixGetDimensions(pixs, &w, &h, 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];
1972 datas = pixGetData(pixs);
1973 wpls = pixGetWpl(pixs);
1974 datad = pixGetData(pixd);
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];
2013l_int32 w, h, i, j, wpls, wpld, bit;
2015l_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);
2022 pixGetDimensions(pixs, &w, &h, 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);
2037 datas = pixGetData(pixs);
2038 wpls = pixGetWpl(pixs);
2039 datad = pixGetData(pixd);
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);
2081 cmap = pixcmapCreate(2);
2082 pixcmapAddColor(cmap, 255, 255, 255);
2083 pixcmapAddColor(cmap, 0, 0, 0);
2084 pixSetColormap(pixd, cmap);
2085 pixCopyInputFormat(pixd, pixs);
2115l_int32 w, h, i, j, byteval, nbytes, wpls, wpld;
2119l_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);
2126 pixGetDimensions(pixs, &w, &h, NULL);
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];
2153 datas = pixGetData(pixs);
2154 wpls = pixGetWpl(pixs);
2155 datad = pixGetData(pixd);
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);
2199 cmap = pixcmapCreate(4);
2200 pixcmapAddColor(cmap, 255, 255, 255);
2201 pixcmapAddColor(cmap, 0, 0, 0);
2202 pixSetColormap(pixd, cmap);
2203 pixCopyInputFormat(pixd, pixs);
2233l_int32 w, h, i, j, byteval, nbytes, wpls, wpld;
2236l_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);
2243 pixGetDimensions(pixs, &w, &h, NULL);
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];
2270 datas = pixGetData(pixs);
2271 wpls = pixGetWpl(pixs);
2272 datad = pixGetData(pixd);
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);
2316 cmap = pixcmapCreate(8);
2317 pixcmapAddColor(cmap, 255, 255, 255);
2318 pixcmapAddColor(cmap, 0, 0, 0);
2319 pixSetColormap(pixd, cmap);
2320 pixCopyInputFormat(pixd, pixs);
2350l_int32 w, h, i, j, qbit, nqbits, wpls, wpld;
2353l_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);
2360 pixGetDimensions(pixs, &w, &h, NULL);
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);
2372 pixSetPadBits(pixs, 0);
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];
2384 datas = pixGetData(pixs);
2385 wpls = pixGetWpl(pixs);
2386 datad = pixGetData(pixd);
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];
2441l_int32 w, h, i, j, nbytes, wpls, wpld, dibit, byte;
2444l_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)
2457 pixGetDimensions(pixs, &w, &h, NULL);
2458 if ((pixd = pixCreate(w, h, 8)) == NULL)
2459 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2460 pixSetPadBits(pixs, 0);
2461 pixCopyResolution(pixd, pixs);
2462 pixCopyInputFormat(pixd, pixs);
2463 datas = pixGetData(pixs);
2464 wpls = pixGetWpl(pixs);
2465 datad = pixGetData(pixd);
2466 wpld = pixGetWpl(pixd);
2468 if (cmapflag == TRUE) {
2470 cmapd = pixcmapConvertTo8(cmaps);
2472 cmapd = pixcmapCreate(8);
2473 pixcmapAddColor(cmapd, val0, val0, val0);
2474 pixcmapAddColor(cmapd, val1, val1, val1);
2475 pixcmapAddColor(cmapd, val2, val2, val2);
2476 pixcmapAddColor(cmapd, val3, val3, val3);
2478 pixSetColormap(pixd, cmapd);
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];
2547l_int32 w, h, i, j, wpls, wpld, byte, qbit;
2548l_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)
2561 pixGetDimensions(pixs, &w, &h, NULL);
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);
2566 datas = pixGetData(pixs);
2567 wpls = pixGetWpl(pixs);
2568 datad = pixGetData(pixd);
2569 wpld = pixGetWpl(pixd);
2571 if (cmapflag == TRUE) {
2573 cmapd = pixcmapConvertTo8(cmaps);
2575 cmapd = pixcmapCreate(8);
2576 for (i = 0; i < 16; i++)
2577 pixcmapAddColor(cmapd, 17 * i, 17 * i, 17 * i);
2579 pixSetColormap(pixd, cmapd);
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;
2630l_int32 i, j, w, h, d, wplt, wpld, val;
2631l_uint32 *datat, *datad, *linet, *lined;
2635 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2636 pixGetDimensions(pixs, &w, &h, &d);
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)
2645 pixt = pixClone(pixs);
2647 pixd = pixCreate(w, h, 16);
2648 pixCopyResolution(pixd, pixs);
2649 pixCopyInputFormat(pixd, pixs);
2650 datat = pixGetData(pixt);
2651 datad = pixGetData(pixd);
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);
2694PIX *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);
2706 pix1 = pixCopy(NULL, pixs);
2708 if (d == 24 || d == 32)
2711 pix2 = pixClone(pix1);
2715 }
else if (d == 2) {
2716 pixd = pixClone(pix2);
2717 }
else if (d == 4) {
2743l_int32 i, j, w, h, wpls, wpld;
2745l_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)
2754 pixs = pixClone(pix);
2755 pixGetDimensions(pixs, &w, &h, NULL);
2756 datas = pixGetData(pixs);
2757 wpls = pixGetWpl(pixs);
2758 pixd = pixCreate(w, h, 2);
2759 datad = pixGetData(pixd);
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);
2798PIX *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);
2810 pix1 = pixCopy(NULL, pixs);
2812 if (d == 24 || d == 32)
2815 pix2 = pixClone(pix1);
2819 }
else if (d == 2) {
2823 }
else if (d == 4) {
2824 pixd = pixClone(pix2);
2847l_int32 i, j, w, h, wpls, wpld, val;
2848l_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)
2857 pixs = pixClone(pix);
2858 pixGetDimensions(pixs, &w, &h, NULL);
2859 datas = pixGetData(pixs);
2860 wpls = pixGetWpl(pixs);
2861 pixd = pixCreate(w, h, 4);
2862 datad = pixGetData(pixd);
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++) {
2899l_int32 d, color0, color1, rval, gval, bval;
2900PIX *pix1, *pix2, *pixd;
2904 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2905 d = pixGetDepth(pixs);
2906 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
2907 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
2909 cmap = pixGetColormap(pixs);
2912 return pixCopy(NULL, pixs);
2915 pixcmapGetColor(cmap, 0, &rval, &gval, &bval);
2916 color0 = rval + gval + bval;
2917 pixcmapGetColor(cmap, 1, &rval, &gval, &bval);
2918 color1 = rval + gval + bval;
2919 pixd = pixCopy(NULL, pixs);
2920 pixDestroyColormap(pixd);
2921 if (color1 > color0)
2922 pixInvert(pixd, pixd);
2930 pixd = pixThresholdToBinary(pix2, 180);
2957l_int32 d, color0, color1, rval, gval, bval;
2962 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2963 d = pixGetDepth(pixs);
2964 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
2965 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
2967 cmap = pixGetColormap(pixs);
2970 return pixCopy(NULL, pixs);
2973 pixcmapGetColor(cmap, 0, &rval, &gval, &bval);
2974 color0 = rval + gval + bval;
2975 pixcmapGetColor(cmap, 1, &rval, &gval, &bval);
2976 color1 = rval + gval + bval;
2977 pixd = pixCopy(NULL, pixs);
2978 pixDestroyColormap(pixd);
2979 if (color1 > color0)
2980 pixInvert(pixd, pixd);
2987 pixd = pixThresholdToBinary(pixg, threshold);
3012l_float32 scalefactor;
3016 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3018 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3020 scalefactor = 1.f / (l_float32)factor;
3021 pixt = pixScaleBySampling(pixs, scalefactor, scalefactor);
3065 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3066 d = pixGetDepth(pixs);
3067 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 24 && d != 32)
3068 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,24,32}", __func__, NULL);
3075 }
else if (d == 2) {
3077 }
else if (d == 4) {
3079 }
else if (d == 8) {
3080 cmap = pixGetColormap(pixs);
3081 if ((cmap && cmapflag) || (!cmap && !cmapflag)) {
3082 return pixCopy(NULL, pixs);
3086 pixd = pixCopy(NULL, pixs);
3090 }
else if (d == 16) {
3095 }
else if (d == 24) {
3130l_float32 scalefactor;
3134 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3136 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3138 scalefactor = 1.f / (l_float32)factor;
3139 pixt = pixScaleBySampling(pixs, scalefactor, scalefactor);
3174 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3175 d = pixGetDepth(pixs);
3176 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
3177 return (
PIX *)ERROR_PTR(
"depth not {1,2,4,8,16,32}", __func__, NULL);
3206 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3208 d = pixGetDepth(pixs);
3214 return (
PIX *)ERROR_PTR(
"src depth not 1 or 8 bpp", __func__, NULL);
3254 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3256 d = pixGetDepth(pixs);
3259 }
else if (d == 2) {
3264 }
else if (d == 4) {
3269 }
else if (d == 8) {
3271 }
else if (d == 16) {
3276 }
else if (d == 24) {
3278 }
else if (d == 32) {
3279 return pixCopy(NULL, pixs);
3281 return (
PIX *)ERROR_PTR(
"depth not 1, 2, 4, 8, 16, 32 bpp",
3304l_float32 scalefactor;
3308 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3310 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
3312 scalefactor = 1.f / (l_float32)factor;
3313 pix1 = pixScaleBySampling(pixs, scalefactor, scalefactor);
3336l_int32 i, j, w, h, wpls, wpld, val;
3337l_uint32 *datas, *datad, *lines, *lined;
3342 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3343 if (pixGetDepth(pixs) != 8)
3344 return (
PIX *)ERROR_PTR(
"pixs not 8 bpp", __func__, NULL);
3346 if (pixGetColormap(pixs))
3349 pixGetDimensions(pixs, &w, &h, NULL);
3350 datas = pixGetData(pixs);
3351 wpls = pixGetWpl(pixs);
3352 if ((pixd = pixCreate(w, h, 32)) == NULL)
3353 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3354 pixCopyResolution(pixd, pixs);
3355 pixCopyInputFormat(pixd, pixs);
3356 datad = pixGetData(pixd);
3357 wpld = pixGetWpl(pixd);
3360 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
3361 for (i = 0; i < 256; i++)
3362 tab[i] = ((l_uint32)i << 24) | (i << 16) | (i << 8);
3365 for (i = 0; i < h; i++) {
3366 lines = datas + i * wpls;
3367 lined = datad + i * wpld;
3368 for (j = 0; j < w; j++) {
3370 lined[j] = tab[val];
3410 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3412 return (
PIX *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
3414 d = pixGetDepth(pixs);
3415 if (pixGetColormap(pixs)) {
3416 if (warnflag) L_WARNING(
"pix has colormap; removing\n", __func__);
3418 }
else if (d == 8 || d == 32) {
3420 pixd = pixClone(pixs);
3422 pixd = pixCopy(NULL, pixs);
3428 d = pixGetDepth(pixd);
3429 if (d != 8 && d != 32) {
3431 return (
PIX *)ERROR_PTR(
"depth not 8 or 32 bpp", __func__, NULL);
3466l_int32 w, h, d, i, j, wpls, wpld, rval, gval, bval;
3468l_uint32 *datas, *datad, *lined;
3472 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3473 pixGetDimensions(pixs, &w, &h, &d);
3475 return (
PIX *)ERROR_PTR(
"pixs not 24 bpp", __func__, NULL);
3477 pixd = pixCreate(w, h, 32);
3478 datas = pixGetData(pixs);
3479 datad = pixGetData(pixd);
3480 wpls = pixGetWpl(pixs);
3481 wpld = pixGetWpl(pixd);
3482 for (i = 0; i < h; i++) {
3483 lines = (l_uint8 *)(datas + i * wpls);
3484 lined = datad + i * wpld;
3485 for (j = 0; j < w; j++) {
3489 composeRGBPixel(rval, gval, bval, &pixel);
3493 pixCopyResolution(pixd, pixs);
3494 pixCopyInputFormat(pixd, pixs);
3514l_int32 w, h, d, i, j, wpls, wpld, rval, gval, bval;
3515l_uint32 *datas, *lines, *rgbdata;
3519 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3520 pixGetDimensions(pixs, &w, &h, &d);
3522 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
3524 datas = pixGetData(pixs);
3525 wpls = pixGetWpl(pixs);
3526 pixd = pixCreate(w, h, 24);
3527 rgbdata = pixGetData(pixd);
3528 wpld = pixGetWpl(pixd);
3529 for (i = 0; i < h; i++) {
3530 lines = datas + i * wpls;
3531 rgbdata8 = (l_uint8 *)(rgbdata + i * wpld);
3532 for (j = 0; j < w; j++) {
3533 extractRGBValues(lines[j], &rval, &gval, &bval);
3539 pixCopyResolution(pixd, pixs);
3540 pixCopyInputFormat(pixd, pixs);
3566l_int32 w, h, i, j, wpls, wpld;
3568l_uint32 *datas, *lines, *datad, *lined;
3571 if (!pixs || pixGetDepth(pixs) != 32)
3572 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
3575 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
3577 pixGetDimensions(pixs, &w, &h, NULL);
3578 if ((pixd = pixCreate(w, h, 16)) == NULL)
3579 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3580 pixCopyResolution(pixd, pixs);
3581 pixCopyInputFormat(pixd, pixs);
3582 wpls = pixGetWpl(pixs);
3583 datas = pixGetData(pixs);
3584 wpld = pixGetWpl(pixd);
3585 datad = pixGetData(pixd);
3587 for (i = 0; i < h; i++) {
3588 lines = datas + i * wpls;
3589 lined = datad + i * wpld;
3591 for (j = 0; j < wpls; j++) {
3592 sword = *(lines + j);
3593 dword = sword & 0xffff;
3597 for (j = 0; j < wpls; j++) {
3598 sword = *(lines + j);
3599 dword = sword >> 16;
3603 for (j = 0; j < wpls; j++) {
3604 sword = *(lines + j);
3605 dword = (sword >> 16) ? 0xffff : (sword & 0xffff);
3630 if (!pixs || pixGetDepth(pixs) != 32)
3631 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
3634 return (
PIX *)ERROR_PTR(
"invalid type16", __func__, NULL);
3636 return (
PIX *)ERROR_PTR(
"invalid type8", __func__, NULL);
3664 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3666 if (pixGetDepth(pixs) == 32 && pixGetSpp(pixs) == 4)
3667 return pixAlphaBlendUniform(pixs, 0xffffff00);
3669 return pixClone(pixs);
3701 if (!pixs || (pixGetDepth(pixs) != 1))
3702 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
3703 if (pixd && (pixd != pixs))
3704 return (
PIX *)ERROR_PTR(
"pixd defined but != pixs", __func__, NULL);
3706 pixd = pixCopy(pixd, pixs);
3707 cmap = pixcmapCreate(1);
3708 pixSetColormap(pixd, cmap);
3709 pixcmapAddRGBA(cmap, 255, 255, 255, 0);
3710 pixcmapAddRGBA(cmap, 0, 0, 0, 255);
3739l_int32 w, h, ds, wpls, wpld, i, j, val;
3740l_uint32 *datas, *datad, *lines, *lined;
3744 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3745 if (pixGetColormap(pixs))
3746 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
3747 if (d != 2 && d != 4 && d != 8)
3748 return (
PIX *)ERROR_PTR(
"invalid dest depth", __func__, NULL);
3750 pixGetDimensions(pixs, &w, &h, &ds);
3752 return (
PIX *)ERROR_PTR(
"depth > d", __func__, NULL);
3754 return pixCopy(NULL, pixs);
3756 if ((pixd = pixCreate(w, h, d)) == NULL)
3757 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
3758 pixCopyResolution(pixd, pixs);
3759 pixCopyInputFormat(pixd, pixs);
3762 datas = pixGetData(pixs);
3763 wpls = pixGetWpl(pixs);
3764 datad = pixGetData(pixd);
3765 wpld = pixGetWpl(pixd);
3766 for (i = 0; i < h; i++) {
3767 lines = datas + i * wpls;
3768 lined = datad + i * wpld;
3772 for (j = 0; j < w; j++) {
3783 for (j = 0; j < w; j++) {
3792 for (j = 0; j < w; j++) {
3832 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3834 cmap = pixGetColormap(pixs);
3835 d = pixGetDepth(pixs);
3840 pixd = pixClone(pixs);
3861 lept_stderr(
"depth not in {1, 2, 4, 8, 16, 32}");
3912 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3913 d = pixGetDepth(pixs);
3914 cmap = pixGetColormap(pixs);
3915 if (d != 8 && d != 32 && !cmap)
3916 return (
PIX *)ERROR_PTR(
"pix not 8 or 32 bpp and not cmapped",
3918 if (scalex <= 0.0 || scaley <= 0.0)
3919 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
3922 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
3924 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
3926 d = pixGetDepth(pix1);
3933 L_ERROR(
"invalid depth %d\n", __func__, d);
3975l_int32 w, h, d, wd, hd, wplt, wpld, i, j, rval, gval, bval, direction;
3976l_uint32 *datat, *datad, *linet, *lined;
3977PIX *pix1, *pix2, *pixd;
3981 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
3982 d = pixGetDepth(pixs);
3983 cmap = pixGetColormap(pixs);
3984 if (d != 8 && !cmap)
3985 return (
PIX *)ERROR_PTR(
"pix not 8 bpp & not cmapped", __func__, NULL);
3986 if (scalex <= 0.0 || scaley <= 0.0)
3987 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
3990 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
3996 if (direction == L_HORIZ)
3997 pix2 = pixScale(pix1, 3.0f * scalex, scaley);
3999 pix2 = pixScale(pix1, scalex, 3.0f * scaley);
4001 pixGetDimensions(pix2, &w, &h, NULL);
4002 wd = (direction == L_HORIZ) ? w / 3 : w;
4003 hd = (direction == L_VERT) ? h / 3 : h;
4004 pixd = pixCreate(wd, hd, 32);
4005 datad = pixGetData(pixd);
4006 wpld = pixGetWpl(pixd);
4007 datat = pixGetData(pix2);
4008 wplt = pixGetWpl(pix2);
4009 if (direction == L_HORIZ) {
4010 for (i = 0; i < hd; i++) {
4011 linet = datat + i * wplt;
4012 lined = datad + i * wpld;
4013 for (j = 0; j < wd; j++) {
4018 composeRGBPixel(rval, gval, bval, &lined[j]);
4020 composeRGBPixel(bval, gval, rval, &lined[j]);
4024 for (i = 0; i < hd; i++) {
4025 linet = datat + 3 * i * wplt;
4026 lined = datad + i * wpld;
4027 for (j = 0; j < wd; j++) {
4032 composeRGBPixel(rval, gval, bval, &lined[j]);
4034 composeRGBPixel(bval, gval, rval, &lined[j]);
4078l_int32 w, h, d, wd, hd, wplt, wpld, i, j, rval, gval, bval, direction;
4079l_uint32 *datat, *datad, *linet, *lined;
4080PIX *pix1, *pix2, *pixd;
4084 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
4085 d = pixGetDepth(pixs);
4086 cmap = pixGetColormap(pixs);
4087 if (d != 32 && !cmap)
4088 return (
PIX *)ERROR_PTR(
"pix not 32 bpp & not cmapped", __func__, NULL);
4089 if (scalex <= 0.0 || scaley <= 0.0)
4090 return (
PIX *)ERROR_PTR(
"scale factors must be > 0", __func__, NULL);
4093 return (
PIX *)ERROR_PTR(
"invalid subpixel order", __func__, NULL);
4099 if (direction == L_HORIZ)
4100 pix2 = pixScale(pix1, 3.0f * scalex, scaley);
4102 pix2 = pixScale(pix1, scalex, 3.0f * scaley);
4104 pixGetDimensions(pix2, &w, &h, NULL);
4105 wd = (direction == L_HORIZ) ? w / 3 : w;
4106 hd = (direction == L_VERT) ? h / 3 : h;
4107 pixd = pixCreate(wd, hd, 32);
4108 pixCopyInputFormat(pixd, pixs);
4109 datad = pixGetData(pixd);
4110 wpld = pixGetWpl(pixd);
4111 datat = pixGetData(pix2);
4112 wplt = pixGetWpl(pix2);
4113 if (direction == L_HORIZ) {
4114 for (i = 0; i < hd; i++) {
4115 linet = datat + i * wplt;
4116 lined = datad + i * wpld;
4117 for (j = 0; j < wd; j++) {
4119 extractRGBValues(linet[3 * j], &rval, NULL, NULL);
4120 extractRGBValues(linet[3 * j + 1], NULL, &gval, NULL);
4121 extractRGBValues(linet[3 * j + 2], NULL, NULL, &bval);
4123 extractRGBValues(linet[3 * j], NULL, NULL, &bval);
4124 extractRGBValues(linet[3 * j + 1], NULL, &gval, NULL);
4125 extractRGBValues(linet[3 * j + 2], &rval, NULL, NULL);
4127 composeRGBPixel(rval, gval, bval, &lined[j]);
4131 for (i = 0; i < hd; i++) {
4132 linet = datat + 3 * i * wplt;
4133 lined = datad + i * wpld;
4134 for (j = 0; j < wd; j++) {
4136 extractRGBValues(linet[j], &rval, NULL, NULL);
4137 extractRGBValues((linet + wplt)[j], NULL, &gval, NULL);
4138 extractRGBValues((linet + 2 * wplt)[j], NULL, NULL, &bval);
4140 extractRGBValues(linet[j], NULL, NULL, &bval);
4141 extractRGBValues((linet + wplt)[j], NULL, &gval, NULL);
4142 extractRGBValues((linet + 2 * wplt)[j], &rval, NULL, NULL);
4144 composeRGBPixel(rval, gval, bval, &lined[j]);
4149 if (pixGetSpp(pixs) == 4)
4150 pixScaleAndTransferAlpha(pixd, pixs, scalex, scaley);
4177 L_ERROR(
"invalid reference value for neutral boost\n", __func__);
4180 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)
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 * pixConvertGrayToColormap8(PIX *pixs, l_int32 mindepth)
pixConvertGrayToColormap8()
PIX * pixConvert1To16(PIX *pixd, PIX *pixs, l_uint16 val0, l_uint16 val1)
pixConvert1To16()
PIX * pixConvert32To16(PIX *pixs, l_int32 type)
pixConvert32To16()
l_ok pixQuantizeIfFewColors(PIX *pixs, l_int32 maxcolors, l_int32 mingraycolors, l_int32 octlevel, PIX **ppixd)
pixQuantizeIfFewColors()
PIX * pixConvertRGBToBinaryArb(PIX *pixs, l_float32 rc, l_float32 gc, l_float32 bc, l_int32 thresh, l_int32 relation)
pixConvertRGBToBinaryArb()
PIX * pixConvert8To4(PIX *pix)
pixConvert8To4()
PIX * pixConvert8To16(PIX *pixs, l_int32 leftshift)
pixConvert8To16()
PIX * pixThreshold8(PIX *pixs, l_int32 d, l_int32 nlevels, l_int32 cmapflag)
pixThreshold8()
PIX * pixConvert32To24(PIX *pixs)
pixConvert32To24()
PIX * pixConvertTo4(PIX *pixs)
pixConvertTo4()
PIX * pixConvertRGBToLuminance(PIX *pixs)
pixConvertRGBToLuminance()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixConvertRGBToGrayMinMax(PIX *pixs, l_int32 type)
pixConvertRGBToGrayMinMax()
PIX * pixConvert8To32(PIX *pixs)
pixConvert8To32()
PIX * pixConvertTo2(PIX *pixs)
pixConvertTo2()
PIX * pixConvertTo8Or32(PIX *pixs, l_int32 copyflag, l_int32 warnflag)
pixConvertTo8Or32()
PIX * pixConvertGrayToFalseColor(PIX *pixs, l_float32 gamma)
pixConvertGrayToFalseColor()
PIX * pixConvertTo8BySampling(PIX *pixs, l_int32 factor, l_int32 cmapflag)
pixConvertTo8BySampling()
l_ok pixAddGrayColormap8(PIX *pixs)
pixAddGrayColormap8()
PIX * pixConvertRGBToGrayFast(PIX *pixs)
pixConvertRGBToGrayFast()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvert2To8(PIX *pixs, l_uint8 val0, l_uint8 val1, l_uint8 val2, l_uint8 val3, l_int32 cmapflag)
pixConvert2To8()
PIX * pixConvertTo1Adaptive(PIX *pixs)
pixConvertTo1Adaptive()
PIX * pixConvertLossless(PIX *pixs, l_int32 d)
pixConvertLossless()
PIX * pixAddMinimalGrayColormap8(PIX *pixs)
pixAddMinimalGrayColormap8()
PIX * pixConvert1To8Cmap(PIX *pixs)
pixConvert1To8Cmap()
PIX * pixConvert1To32(PIX *pixd, PIX *pixs, l_uint32 val0, l_uint32 val1)
pixConvert1To32()
PIX * pixConvertGrayToColormap(PIX *pixs)
pixConvertGrayToColormap()
PIX * pixConvert1To2Cmap(PIX *pixs)
pixConvert1To2Cmap()
PIX * pixConvert16To8(PIX *pixs, l_int32 type)
pixConvert16To8()
PIX * pixConvertRGBToColormap(PIX *pixs, l_int32 ditherflag)
pixConvertRGBToColormap()
PIX * pixConvertToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertToSubpixelRGB()
PIX * pixConvertTo8Colormap(PIX *pixs, l_int32 dither)
pixConvertTo8Colormap()
PIX * pixConvert1To4Cmap(PIX *pixs)
pixConvert1To4Cmap()
PIX * pixConvertRGBToGrayGeneral(PIX *pixs, l_int32 type, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixConvertRGBToGrayGeneral()
PIX * pixConvertTo32BySampling(PIX *pixs, l_int32 factor)
pixConvertTo32BySampling()
PIX * pixConvert24To32(PIX *pixs)
pixConvert24To32()
PIX * pixConvert1To4(PIX *pixd, PIX *pixs, l_int32 val0, l_int32 val1)
pixConvert1To4()
PIX * pixConvertTo16(PIX *pixs)
pixConvertTo16()
PIX * pixConvertRGBToGrayArb(PIX *pixs, l_float32 rc, l_float32 gc, l_float32 bc)
pixConvertRGBToGrayArb()
PIX * pixConvertGrayToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertGrayToSubpixelRGB()
PIX * pixConvertForPSWrap(PIX *pixs)
pixConvertForPSWrap()
PIX * pixConvert1To2(PIX *pixd, PIX *pixs, l_int32 val0, l_int32 val1)
pixConvert1To2()
PIX * pixConvertRGBToGraySatBoost(PIX *pixs, l_int32 refval)
pixConvertRGBToGraySatBoost()
PIX * pixConvertRGBToGray(PIX *pixs, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixConvertRGBToGray()
PIX * pixConvert4To8(PIX *pixs, l_int32 cmapflag)
pixConvert4To8()
PIX * pixConvertCmapTo1(PIX *pixs)
pixConvertCmapTo1()
PIX * pixAddAlphaTo1bpp(PIX *pixd, PIX *pixs)
pixAddAlphaTo1bpp()
PIX * pixConvert8To2(PIX *pix)
pixConvert8To2()
PIX * pixRemoveAlpha(PIX *pixs)
pixRemoveAlpha()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
PIX * pixColorizeGray(PIX *pixs, l_uint32 color, l_int32 cmapflag)
pixColorizeGray()
PIX * pixConvertTo1(PIX *pixs, l_int32 threshold)
pixConvertTo1()
PIX * pixConvertTo1BySampling(PIX *pixs, l_int32 factor, l_int32 threshold)
pixConvertTo1BySampling()
PIX * pixConvertColorToSubpixelRGB(PIX *pixs, l_float32 scalex, l_float32 scaley, l_int32 order)
pixConvertColorToSubpixelRGB()
PIX * pixRemoveColormapGeneral(PIX *pixs, l_int32 type, l_int32 ifnocmap)
pixRemoveColormapGeneral()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
void l_setNeutralBoostVal(l_int32 val)
l_setNeutralBoostVal()
PIX * pixUnpackBinary(PIX *pixs, l_int32 depth, l_int32 invert)
pixUnpackBinary()
PIX * pixConvert32To8(PIX *pixs, l_int32 type16, l_int32 type8)
pixConvert32To8()