173 #include "allheaders.h" 194 l_int32 *histo, l_int32 histosize,
198 PIXCMAP *cmap, l_int32 *indexmap,
199 l_int32 mapsize, l_int32 sigbits);
201 l_uint32 mask, l_int32 sigbits,
211 l_int32 sigbits, l_int32 index,
212 l_int32 *prval, l_int32 *pgval,
217 l_int32 g2, l_int32 b1, l_int32 b2);
222 static const l_int32 DEFAULT_SIG_BITS = 5;
223 static const l_int32 MAX_ITERS_ALLOWED = 5000;
227 static const l_float32 FRACT_BY_POPULATION = 0.85;
231 static const l_int32 DIF_CAP = 100;
234 #ifndef NO_CONSOLE_IO 235 #define DEBUG_MC_COLORS 0 236 #define DEBUG_SPLIT_AXES 0 261 0, 256, DEFAULT_SIG_BITS, 1, 1);
316 l_int32 i, subsample, histosize, smalln, ncolors, niters, popcolors;
317 l_int32 w, h, minside, factor, index, rval, gval, bval;
319 l_float32 pixfract, colorfract;
325 PROCNAME(
"pixMedianCutQuantGeneral");
327 if (!pixs || pixGetDepth(pixs) != 32)
328 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
329 if (maxcolors < 2 || maxcolors > 256)
330 return (
PIX *)ERROR_PTR(
"maxcolors not in [2...256]", procName, NULL);
331 if (outdepth != 0 && outdepth != 1 && outdepth != 2 && outdepth != 4 &&
333 return (
PIX *)ERROR_PTR(
"outdepth not in {0,1,2,4,8}", procName, NULL);
334 if (outdepth > 0 && (maxcolors > (1 << outdepth)))
335 return (
PIX *)ERROR_PTR(
"maxcolors > 2^(outdepth)", procName, NULL);
337 sigbits = DEFAULT_SIG_BITS;
338 else if (sigbits < 5 || sigbits > 6)
339 return (
PIX *)ERROR_PTR(
"sigbits not 5 or 6", procName, NULL);
350 minside = L_MIN(w, h);
351 factor = L_MAX(1, minside / 400);
353 if (pixfract * colorfract < 0.00025) {
354 L_INFO(
"\n Pixel fraction neither white nor black = %6.3f" 355 "\n Color fraction of those pixels = %6.3f" 356 "\n Quantizing in gray\n",
357 procName, pixfract, colorfract);
367 subsample = (l_int32)(sqrt((l_float64)(w * h) / 100000.));
368 subsample = L_MAX(1, L_MIN(maxsub, subsample));
371 histosize = 1 << (3 * sigbits);
376 for (i = 0; i < histosize; i++) {
379 if (ncolors > maxcolors) {
388 else if (ncolors <= 4)
390 else if (ncolors <= 16)
396 histo, histosize, sigbits);
398 histo, histosize, sigbits);
404 if (ditherflag || subsample > 1)
406 0, (1 << sigbits) - 1,
407 0, (1 << sigbits) - 1);
420 popcolors = (l_int32)(FRACT_BY_POPULATION * maxcolors);
429 L_WARNING(
"vbox1 not defined; shouldn't happen!\n", procName);
433 vbox1->sortparam = vbox1->npix;
438 vbox2->sortparam = vbox2->npix;
442 if (ncolors >= popcolors)
444 if (niters++ > MAX_ITERS_ALLOWED) {
445 L_WARNING(
"infinite loop; perhaps too few pixels!\n", procName);
454 vbox->sortparam = vbox->npix * vbox->vol;
469 L_WARNING(
"vbox1 not defined; shouldn't happen!\n", procName);
473 vbox1->sortparam = vbox1->npix * vbox1->vol;
478 vbox2->sortparam = vbox2->npix * vbox2->vol;
482 if (ncolors >= maxcolors)
484 if (niters++ > MAX_ITERS_ALLOWED) {
485 L_WARNING(
"infinite loop; perhaps too few pixels!\n", procName);
494 vbox->sortparam = vbox->npix;
506 else if (ncolors <= 4)
508 else if (ncolors <= 16)
514 histo, histosize, sigbits);
519 if (rval < 5 && gval < 5 && bval < 5)
525 if (rval > 251 && gval > 251 && bval > 251)
586 l_int32 i, j, w, h, wplc, wplg, wpld, nc, unused, iscolor, factor, minside;
587 l_int32 rval, gval, bval, minval, maxval, val, grayval;
588 l_float32 pixfract, colorfract;
590 l_uint32 *datac, *datag, *datad, *linec, *lineg, *lined;
591 PIX *pixc, *pixg, *pixd;
594 PROCNAME(
"pixMedianCutQuantMixed");
596 if (!pixs || pixGetDepth(pixs) != 32)
597 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
599 return (
PIX *)ERROR_PTR(
"ngray < 2", procName, NULL);
600 if (ncolor + ngray > 255)
601 return (
PIX *)ERROR_PTR(
"ncolor + ngray > 255", procName, NULL);
602 if (darkthresh <= 0) darkthresh = 20;
603 if (lightthresh <= 0) lightthresh = 244;
604 if (diffthresh <= 0) diffthresh = 20;
611 minside = L_MIN(w, h);
612 factor = L_MAX(1, minside / 400);
614 &pixfract, &colorfract);
615 if (pixfract * colorfract < 0.0001) {
616 L_INFO(
"\n Pixel fraction neither white nor black = %6.3f" 617 "\n Color fraction of those pixels = %6.3f" 618 "\n Quantizing in gray\n",
619 procName, pixfract, colorfract);
633 wplc = pixGetWpl(pixc);
634 wplg = pixGetWpl(pixg);
635 lut = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
636 for (i = 0; i < 256; i++)
637 lut[i] = ncolor + 1 + (i * (ngray - 1) + 128) / 255;
638 for (i = 0; i < h; i++) {
639 linec = datac + i * wplc;
640 lineg = datag + i * wplg;
641 for (j = 0; j < w; j++) {
644 minval = L_MIN(rval, gval);
645 minval = L_MIN(minval, bval);
646 maxval = L_MAX(rval, gval);
647 maxval = L_MAX(maxval, bval);
648 if (maxval >= darkthresh &&
649 minval <= lightthresh &&
650 maxval - minval >= diffthresh) {
655 grayval = (maxval + minval) / 2;
663 DEFAULT_SIG_BITS, 1, 0);
667 cmap = pixGetColormap(pixd);
669 unused = ncolor + 1 - nc;
671 L_ERROR(
"Too many colors: extra = %d\n", procName, -unused);
673 L_INFO(
"%d unused colors\n", procName, unused);
674 for (i = 0; i < unused; i++)
677 for (i = 0; i < ngray; i++) {
678 grayval = (255 * i) / (ngray - 1);
684 wpld = pixGetWpl(pixd);
685 for (i = 0; i < h; i++) {
686 lined = datad + i * wpld;
687 lineg = datag + i * wplg;
688 for (j = 0; j < w; j++) {
762 l_int32 ncolors, iscolor;
765 PROCNAME(
"pixFewColorsMedianCutQuantMixed");
767 if (!pixs || pixGetDepth(pixs) != 32)
768 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
769 if (maxncolors <= 0) maxncolors = 20;
770 if (darkthresh <= 0) darkthresh = 20;
771 if (lightthresh <= 0) lightthresh = 244;
772 if (diffthresh <= 0) diffthresh = 15;
773 if (ncolor < maxncolors) {
774 L_WARNING(
"ncolor too small; setting to %d\n", procName, maxncolors);
777 if (ngray < maxncolors) {
778 L_WARNING(
"ngray too small; setting to %d\n", procName, maxncolors);
787 if (ncolors > maxncolors)
788 return (
PIX *)ERROR_PTR(
"too many colors", procName, NULL);
800 lightthresh, diffthresh);
830 l_int32 i, j, w, h, wpl, rshift, index, histosize;
832 l_uint32 mask, pixel;
833 l_uint32 *data, *line;
835 PROCNAME(
"pixMedianCutHisto");
838 return (l_int32 *)ERROR_PTR(
"pixs not defined", procName, NULL);
839 if (pixGetDepth(pixs) != 32)
840 return (l_int32 *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
841 if (sigbits < 5 || sigbits > 6)
842 return (l_int32 *)ERROR_PTR(
"sigbits not 5 or 6", procName, NULL);
844 return (l_int32 *)ERROR_PTR(
"subsample not > 0", procName, NULL);
846 histosize = 1 << (3 * sigbits);
847 if ((histo = (l_int32 *)LEPT_CALLOC(histosize,
sizeof(l_int32))) == NULL)
848 return (l_int32 *)ERROR_PTR(
"histo not made", procName, NULL);
850 rshift = 8 - sigbits;
851 mask = 0xff >> rshift;
854 wpl = pixGetWpl(pixs);
855 for (i = 0; i < h; i += subsample) {
856 line = data + i * wpl;
857 for (j = 0; j < w; j += subsample) {
896 l_int32 i, index, shift, rval, gval, bval;
900 PROCNAME(
"pixcmapGenerateFromHisto");
903 return (
PIXCMAP *)ERROR_PTR(
"pixs not defined", procName, NULL);
904 if (pixGetDepth(pixs) != 32)
905 return (
PIXCMAP *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
907 return (
PIXCMAP *)ERROR_PTR(
"histo not defined", procName, NULL);
913 mask = 0xff >> shift;
914 for (i = 0, index = 0; i < histosize; i++) {
916 rval = (i >> (2 * sigbits)) << shift;
917 gval = ((i >> sigbits) & mask) << shift;
918 bval = (i & mask) << shift;
957 l_uint8 *bufu8r, *bufu8g, *bufu8b;
958 l_int32 i, j, w, h, wpls, wpld, rshift, index, cmapindex, success;
959 l_int32 rval, gval, bval, rc, gc, bc;
960 l_int32 dif, val1, val2, val3;
961 l_int32 *buf1r, *buf1g, *buf1b, *buf2r, *buf2g, *buf2b;
962 l_uint32 *datas, *datad, *lines, *lined;
963 l_uint32 mask, pixel;
966 PROCNAME(
"pixQuantizeWithColormap");
968 if (!pixs || pixGetDepth(pixs) != 32)
969 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
971 return (
PIX *)ERROR_PTR(
"cmap not defined", procName, NULL);
973 return (
PIX *)ERROR_PTR(
"indexmap not defined", procName, NULL);
980 pixCopyResolution(pixd, pixs);
981 pixCopyInputFormat(pixd, pixs);
984 wpls = pixGetWpl(pixs);
985 wpld = pixGetWpl(pixd);
987 rshift = 8 - sigbits;
988 mask = 0xff >> rshift;
989 if (ditherflag == 0) {
990 for (i = 0; i < h; i++) {
991 lines = datas + i * wpls;
992 lined = datad + i * wpld;
994 for (j = 0; j < w; j++) {
1001 }
else if (outdepth == 2) {
1002 for (j = 0; j < w; j++) {
1008 }
else if (outdepth == 4) {
1009 for (j = 0; j < w; j++) {
1016 for (j = 0; j < w; j++) {
1026 bufu8r = bufu8g = bufu8b = NULL;
1027 buf1r = buf1g = buf1b = buf2r = buf2g = buf2b = NULL;
1028 bufu8r = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1029 bufu8g = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1030 bufu8b = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1031 buf1r = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1032 buf1g = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1033 buf1b = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1034 buf2r = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1035 buf2g = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1036 buf2b = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1037 if (!bufu8r || !bufu8g || !bufu8b || !buf1r || !buf1g ||
1038 !buf1b || !buf2r || !buf2g || !buf2b) {
1039 L_ERROR(
"buffer not made\n", procName);
1041 goto buffer_cleanup;
1046 for (j = 0; j < w; j++) {
1047 buf2r[j] = 64 * bufu8r[j];
1048 buf2g[j] = 64 * bufu8g[j];
1049 buf2b[j] = 64 * bufu8b[j];
1052 for (i = 0; i < h - 1; i++) {
1054 memcpy(buf1r, buf2r, 4 * w);
1055 memcpy(buf1g, buf2g, 4 * w);
1056 memcpy(buf1b, buf2b, 4 * w);
1058 for (j = 0; j < w; j++) {
1059 buf2r[j] = 64 * bufu8r[j];
1060 buf2g[j] = 64 * bufu8g[j];
1061 buf2b[j] = 64 * bufu8b[j];
1065 lined = datad + i * wpld;
1066 for (j = 0; j < w - 1; j++) {
1067 rval = buf1r[j] / 64;
1068 gval = buf1g[j] / 64;
1069 bval = buf1b[j] / 64;
1070 index = ((rval >> rshift) << (2 * sigbits)) +
1071 ((gval >> rshift) << sigbits) + (bval >> rshift);
1072 cmapindex = indexmap[index];
1076 dif = buf1r[j] / 8 - 8 * rc;
1077 if (dif > DIF_CAP) dif = DIF_CAP;
1078 if (dif < -DIF_CAP) dif = -DIF_CAP;
1080 val1 = buf1r[j + 1] + 3 * dif;
1081 val2 = buf2r[j] + 3 * dif;
1082 val3 = buf2r[j + 1] + 2 * dif;
1084 buf1r[j + 1] = L_MIN(16383, val1);
1085 buf2r[j] = L_MIN(16383, val2);
1086 buf2r[j + 1] = L_MIN(16383, val3);
1088 buf1r[j + 1] = L_MAX(0, val1);
1089 buf2r[j] = L_MAX(0, val2);
1090 buf2r[j + 1] = L_MAX(0, val3);
1094 dif = buf1g[j] / 8 - 8 * gc;
1095 if (dif > DIF_CAP) dif = DIF_CAP;
1096 if (dif < -DIF_CAP) dif = -DIF_CAP;
1098 val1 = buf1g[j + 1] + 3 * dif;
1099 val2 = buf2g[j] + 3 * dif;
1100 val3 = buf2g[j + 1] + 2 * dif;
1102 buf1g[j + 1] = L_MIN(16383, val1);
1103 buf2g[j] = L_MIN(16383, val2);
1104 buf2g[j + 1] = L_MIN(16383, val3);
1106 buf1g[j + 1] = L_MAX(0, val1);
1107 buf2g[j] = L_MAX(0, val2);
1108 buf2g[j + 1] = L_MAX(0, val3);
1112 dif = buf1b[j] / 8 - 8 * bc;
1113 if (dif > DIF_CAP) dif = DIF_CAP;
1114 if (dif < -DIF_CAP) dif = -DIF_CAP;
1116 val1 = buf1b[j + 1] + 3 * dif;
1117 val2 = buf2b[j] + 3 * dif;
1118 val3 = buf2b[j + 1] + 2 * dif;
1120 buf1b[j + 1] = L_MIN(16383, val1);
1121 buf2b[j] = L_MIN(16383, val2);
1122 buf2b[j + 1] = L_MIN(16383, val3);
1124 buf1b[j + 1] = L_MAX(0, val1);
1125 buf2b[j] = L_MAX(0, val2);
1126 buf2b[j + 1] = L_MAX(0, val3);
1132 rval = buf1r[w - 1] / 64;
1133 gval = buf1g[w - 1] / 64;
1134 bval = buf1b[w - 1] / 64;
1135 index = ((rval >> rshift) << (2 * sigbits)) +
1136 ((gval >> rshift) << sigbits) + (bval >> rshift);
1141 lined = datad + (h - 1) * wpld;
1142 for (j = 0; j < w; j++) {
1143 rval = buf2r[j] / 64;
1144 gval = buf2g[j] / 64;
1145 bval = buf2b[j] / 64;
1146 index = ((rval >> rshift) << (2 * sigbits)) +
1147 ((gval >> rshift) << sigbits) + (bval >> rshift);
1191 l_int32 rval, gval, bval;
1193 rval = pixel >> (24 + rshift);
1194 gval = (pixel >> (16 + rshift)) & mask;
1195 bval = (pixel >> (8 + rshift)) & mask;
1196 *pindex = (rval << (2 * sigbits)) + (gval << sigbits) + bval;
1221 l_int32 rmin, rmax, gmin, gmax, bmin, bmax, rval, gval, bval;
1222 l_int32 w, h, wpl, i, j, rshift;
1223 l_uint32 mask, pixel;
1224 l_uint32 *data, *line;
1226 PROCNAME(
"pixGetColorRegion");
1229 return (
L_BOX3D *)ERROR_PTR(
"pixs not defined", procName, NULL);
1231 rmin = gmin = bmin = 1000000;
1232 rmax = gmax = bmax = 0;
1233 rshift = 8 - sigbits;
1234 mask = 0xff >> rshift;
1237 wpl = pixGetWpl(pixs);
1238 for (i = 0; i < h; i += subsample) {
1239 line = data + i * wpl;
1240 for (j = 0; j < w; j += subsample) {
1242 rval = pixel >> (24 + rshift);
1243 gval = (pixel >> (16 + rshift)) & mask;
1244 bval = (pixel >> (8 + rshift)) & mask;
1247 else if (rval > rmax)
1251 else if (gval > gmax)
1255 else if (bval > bmax)
1260 return box3dCreate(rmin, rmax, gmin, gmax, bmin, bmax);
1280 l_int32 i, j, k, sum, rw, gw, bw, maxw, index;
1281 l_int32 total, left, right;
1282 l_int32 partialsum[128];
1285 PROCNAME(
"medianCutApply");
1287 if (pvbox1) *pvbox1 = NULL;
1288 if (pvbox2) *pvbox2 = NULL;
1290 return ERROR_INT(
"histo not defined", procName, 1);
1292 return ERROR_INT(
"vbox not defined", procName, 1);
1293 if (!pvbox1 || !pvbox2)
1294 return ERROR_INT(
"&vbox1 and &vbox2 not both defined", procName, 1);
1297 return ERROR_INT(
"no pixels in vbox", procName, 1);
1304 rw = vbox->r2 - vbox->r1 + 1;
1305 gw = vbox->g2 - vbox->g1 + 1;
1306 bw = vbox->b2 - vbox->b1 + 1;
1307 if (rw == 1 && gw == 1 && bw == 1) {
1313 maxw = L_MAX(rw, gw);
1314 maxw = L_MAX(maxw, bw);
1315 #if DEBUG_SPLIT_AXES 1317 fprintf(stderr,
"red split\n");
1318 else if (gw == maxw)
1319 fprintf(stderr,
"green split\n");
1321 fprintf(stderr,
"blue split\n");
1327 for (i = vbox->r1; i <= vbox->r2; i++) {
1329 for (j = vbox->g1; j <= vbox->g2; j++) {
1330 for (k = vbox->b1; k <= vbox->b2; k++) {
1331 index = (i << (2 * sigbits)) + (j << sigbits) + k;
1332 sum += histo[index];
1336 partialsum[i] = total;
1338 }
else if (maxw == gw) {
1339 for (i = vbox->g1; i <= vbox->g2; i++) {
1341 for (j = vbox->r1; j <= vbox->r2; j++) {
1342 for (k = vbox->b1; k <= vbox->b2; k++) {
1343 index = (i << sigbits) + (j << (2 * sigbits)) + k;
1344 sum += histo[index];
1348 partialsum[i] = total;
1351 for (i = vbox->b1; i <= vbox->b2; i++) {
1353 for (j = vbox->r1; j <= vbox->r2; j++) {
1354 for (k = vbox->g1; k <= vbox->g2; k++) {
1355 index = i + (j << (2 * sigbits)) + (k << sigbits);
1356 sum += histo[index];
1360 partialsum[i] = total;
1373 vbox1 = vbox2 = NULL;
1375 for (i = vbox->r1; i <= vbox->r2; i++) {
1376 if (partialsum[i] > total / 2) {
1379 left = i - vbox->r1;
1380 right = vbox->r2 - i;
1382 vbox1->r2 = L_MIN(vbox->r2 - 1, i + right / 2);
1384 vbox1->r2 = L_MAX(vbox->r1, i - 1 - left / 2);
1385 vbox2->r1 = vbox1->r2 + 1;
1389 }
else if (maxw == gw) {
1390 for (i = vbox->g1; i <= vbox->g2; i++) {
1391 if (partialsum[i] > total / 2) {
1394 left = i - vbox->g1;
1395 right = vbox->g2 - i;
1397 vbox1->g2 = L_MIN(vbox->g2 - 1, i + right / 2);
1399 vbox1->g2 = L_MAX(vbox->g1, i - 1 - left / 2);
1400 vbox2->g1 = vbox1->g2 + 1;
1405 for (i = vbox->b1; i <= vbox->b2; i++) {
1406 if (partialsum[i] > total / 2) {
1409 left = i - vbox->b1;
1410 right = vbox->b2 - i;
1412 vbox1->b2 = L_MIN(vbox->b2 - 1, i + right / 2);
1414 vbox1->b2 = L_MAX(vbox->b1, i - 1 - left / 2);
1415 vbox2->b1 = vbox1->b2 + 1;
1423 return ERROR_INT(
"vbox1 not made; shouldn't happen", procName, 1);
1425 return ERROR_INT(
"vbox2 not made; shouldn't happen", procName, 1);
1458 l_int32 index, rval, gval, bval;
1462 PROCNAME(
"pixcmapGenerateFromMedianCuts");
1465 return (
PIXCMAP *)ERROR_PTR(
"lh not defined", procName, NULL);
1467 return (
PIXCMAP *)ERROR_PTR(
"histo not defined", procName, NULL);
1469 rval = gval = bval = 0;
1518 l_int32 i, j, k, ntot, mult, histoindex, rsum, gsum, bsum;
1520 PROCNAME(
"vboxGetAverageColor");
1523 return ERROR_INT(
"vbox not defined", procName, 1);
1525 return ERROR_INT(
"histo not defined", procName, 1);
1526 if (!prval || !pgval || !pbval)
1527 return ERROR_INT(
"&p*val not all defined", procName, 1);
1529 *prval = *pgval = *pbval = 0;
1531 mult = 1 << (8 - sigbits);
1532 rsum = gsum = bsum = 0;
1533 for (i = vbox->r1; i <= vbox->r2; i++) {
1534 for (j = vbox->g1; j <= vbox->g2; j++) {
1535 for (k = vbox->b1; k <= vbox->b2; k++) {
1536 histoindex = (i << (2 * sigbits)) + (j << sigbits) + k;
1537 ntot += histo[histoindex];
1538 rsum += (l_int32)(histo[histoindex] * (i + 0.5) * mult);
1539 gsum += (l_int32)(histo[histoindex] * (j + 0.5) * mult);
1540 bsum += (l_int32)(histo[histoindex] * (k + 0.5) * mult);
1542 histo[histoindex] = index;
1548 *prval = mult * (vbox->r1 + vbox->r2 + 1) / 2;
1549 *pgval = mult * (vbox->g1 + vbox->g2 + 1) / 2;
1550 *pbval = mult * (vbox->b1 + vbox->b2 + 1) / 2;
1552 *prval = rsum / ntot;
1553 *pgval = gsum / ntot;
1554 *pbval = bsum / ntot;
1558 fprintf(stderr,
"ntot[%d] = %d: [%d, %d, %d], (%d, %d, %d)\n",
1559 index, ntot, vbox->r2 - vbox->r1 + 1,
1560 vbox->g2 - vbox->g1 + 1, vbox->b2 - vbox->b1 + 1,
1561 *prval, *pgval, *pbval);
1581 l_int32 i, j, k, npix, index;
1583 PROCNAME(
"vboxGetCount");
1586 return ERROR_INT(
"vbox not defined", procName, 0);
1588 return ERROR_INT(
"histo not defined", procName, 0);
1591 for (i = vbox->r1; i <= vbox->r2; i++) {
1592 for (j = vbox->g1; j <= vbox->g2; j++) {
1593 for (k = vbox->b1; k <= vbox->b2; k++) {
1594 index = (i << (2 * sigbits)) + (j << sigbits) + k;
1595 npix += histo[index];
1613 PROCNAME(
"vboxGetVolume");
1616 return ERROR_INT(
"vbox not defined", procName, 0);
1618 return ((vbox->r2 - vbox->r1 + 1) * (vbox->g2 - vbox->g1 + 1) *
1619 (vbox->b2 - vbox->b1 + 1));
1665 PROCNAME(
"box3dCopy");
1668 return (
L_BOX3D *)ERROR_PTR(
"vbox not defined", procName, NULL);
1670 vboxc =
box3dCreate(vbox->r1, vbox->r2, vbox->g1, vbox->g2,
1671 vbox->b1, vbox->b2);
1672 vboxc->npix = vbox->npix;
1673 vboxc->vol = vbox->vol;
l_ok lheapAdd(L_HEAP *lh, void *item)
lheapAdd()
PIX * pixMedianCutQuantMixed(PIX *pixs, l_int32 ncolor, l_int32 ngray, l_int32 darkthresh, l_int32 lightthresh, l_int32 diffthresh)
pixMedianCutQuantMixed()
PIX * pixThresholdOn8bpp(PIX *pixs, l_int32 nlevels, l_int32 cmapflag)
pixThresholdOn8bpp()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
#define SET_DATA_QBIT(pdata, n, val)
l_uint32 * pixGetData(PIX *pix)
pixGetData()
void lheapDestroy(L_HEAP **plh, l_int32 freeflag)
lheapDestroy()
static PIX * pixQuantizeWithColormap(PIX *pixs, l_int32 ditherflag, l_int32 outdepth, PIXCMAP *cmap, l_int32 *indexmap, l_int32 mapsize, l_int32 sigbits)
pixQuantizeWithColormap()
l_int32 * pixMedianCutHisto(PIX *pixs, l_int32 sigbits, l_int32 subsample)
pixMedianCutHisto()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
static l_int32 medianCutApply(l_int32 *histo, l_int32 sigbits, L_BOX3D *vbox, L_BOX3D **pvbox1, L_BOX3D **pvbox2)
medianCutApply()
static l_int32 vboxGetVolume(L_BOX3D *vbox)
vboxGetVolume()
l_int32 lheapGetCount(L_HEAP *lh)
lheapGetCount()
static L_BOX3D * pixGetColorRegion(PIX *pixs, l_int32 sigbits, l_int32 subsample)
pixGetColorRegion()
PIX * pixFewColorsMedianCutQuantMixed(PIX *pixs, l_int32 ncolor, l_int32 ngray, l_int32 maxncolors, l_int32 darkthresh, l_int32 lightthresh, l_int32 diffthresh)
pixFewColorsMedianCutQuantMixed()
#define SET_DATA_DIBIT(pdata, n, val)
l_ok pixColorsForQuantization(PIX *pixs, l_int32 thresh, l_int32 *pncolors, l_int32 *piscolor, l_int32 debug)
pixColorsForQuantization()
PIXCMAP * pixcmapCreate(l_int32 depth)
pixcmapCreate()
static L_BOX3D * box3dCreate(l_int32 r1, l_int32 r2, l_int32 g1, l_int32 g2, l_int32 b1, l_int32 b2)
box3dCreate()
static l_int32 vboxGetAverageColor(L_BOX3D *vbox, l_int32 *histo, l_int32 sigbits, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
vboxGetAverageColor()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
#define SET_DATA_BYTE(pdata, n, val)
L_HEAP * lheapCreate(l_int32 nalloc, l_int32 direction)
lheapCreate()
#define GET_DATA_BYTE(pdata, n)
void * lheapRemove(L_HEAP *lh)
lheapRemove()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetRGBLine(PIX *pixs, l_int32 row, l_uint8 *bufr, l_uint8 *bufg, l_uint8 *bufb)
pixGetRGBLine()
static PIXCMAP * pixcmapGenerateFromHisto(PIX *pixs, l_int32 depth, l_int32 *histo, l_int32 histosize, l_int32 sigbits)
pixcmapGenerateFromHisto()
l_ok pixcmapResetColor(PIXCMAP *cmap, l_int32 index, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapResetColor()
static l_int32 vboxGetCount(L_BOX3D *vbox, l_int32 *histo, l_int32 sigbits)
vboxGetCount()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
static L_BOX3D * box3dCopy(L_BOX3D *vbox)
box3dCopy()
l_ok pixColorFraction(PIX *pixs, l_int32 darkthresh, l_int32 lightthresh, l_int32 diffthresh, l_int32 factor, l_float32 *ppixfract, l_float32 *pcolorfract)
pixColorFraction()
PIX * pixMedianCutQuantGeneral(PIX *pixs, l_int32 ditherflag, l_int32 outdepth, l_int32 maxcolors, l_int32 sigbits, l_int32 maxsub, l_int32 checkbw)
pixMedianCutQuantGeneral()
l_int32 pixcmapGetCount(PIXCMAP *cmap)
pixcmapGetCount()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
PIX * pixMedianCutQuant(PIX *pixs, l_int32 ditherflag)
pixMedianCutQuant()
l_ok pixcmapAddColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval)
pixcmapAddColor()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
static void getColorIndexMedianCut(l_uint32 pixel, l_int32 rshift, l_uint32 mask, l_int32 sigbits, l_int32 *pindex)
getColorIndexMedianCut()
#define SET_DATA_BIT(pdata, n)
l_ok pixcmapGetRankIntensity(PIXCMAP *cmap, l_float32 rankval, l_int32 *pindex)
pixcmapGetRankIntensity()
static PIXCMAP * pixcmapGenerateFromMedianCuts(L_HEAP *lh, l_int32 *histo, l_int32 sigbits)
pixcmapGenerateFromMedianCuts()