172 #include <config_auto.h> 177 #include "allheaders.h" 198 l_int32 *histo, l_int32 histosize,
202 PIXCMAP *cmap, l_int32 *indexmap,
203 l_int32 mapsize, l_int32 sigbits);
205 l_uint32 mask, l_int32 sigbits,
215 l_int32 sigbits, l_int32 index,
216 l_int32 *prval, l_int32 *pgval,
221 l_int32 g2, l_int32 b1, l_int32 b2);
226 static const l_int32 DefaultSigBits = 5;
227 static const l_int32 MaxItersAllowed = 5000;
231 static const l_float32 FractByPopulation = 0.85;
235 static const l_int32 DifCap = 100;
238 #ifndef NO_CONSOLE_IO 239 #define DEBUG_MC_COLORS 0 240 #define DEBUG_SPLIT_AXES 0 264 0, 256, DefaultSigBits, 1, 1);
325 l_int32 i, subsample, histosize, smalln, ncolors, niters, popcolors;
326 l_int32 w, h, minside, factor, index, rval, gval, bval;
328 l_float32 maxprod, prod, norm, pixfract, colorfract;
334 PROCNAME(
"pixMedianCutQuantGeneral");
336 if (!pixs || pixGetDepth(pixs) != 32)
337 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
338 if (maxcolors < 2 || maxcolors > 256)
339 return (
PIX *)ERROR_PTR(
"maxcolors not in [2...256]", procName, NULL);
340 if (outdepth != 0 && outdepth != 1 && outdepth != 2 && outdepth != 4 &&
342 return (
PIX *)ERROR_PTR(
"outdepth not in {0,1,2,4,8}", procName, NULL);
343 if (outdepth > 0 && (maxcolors > (1 << outdepth)))
344 return (
PIX *)ERROR_PTR(
"maxcolors > 2^(outdepth)", procName, NULL);
346 sigbits = DefaultSigBits;
347 else if (sigbits < 5 || sigbits > 6)
348 return (
PIX *)ERROR_PTR(
"sigbits not 5 or 6", procName, NULL);
359 minside = L_MIN(w, h);
360 factor = L_MAX(1, minside / 400);
362 if (pixfract * colorfract < 0.00025) {
363 L_INFO(
"\n Pixel fraction neither white nor black = %6.3f" 364 "\n Color fraction of those pixels = %6.3f" 365 "\n Quantizing in gray\n",
366 procName, pixfract, colorfract);
376 subsample = (l_int32)(sqrt((l_float64)(w * h) / 100000.));
377 subsample = L_MAX(1, L_MIN(maxsub, subsample));
380 histosize = 1 << (3 * sigbits);
385 for (i = 0; i < histosize; i++) {
388 if (ncolors > maxcolors) {
397 else if (ncolors <= 4)
399 else if (ncolors <= 16)
405 histo, histosize, sigbits);
407 histo, histosize, sigbits);
413 if (ditherflag || subsample > 1)
415 0, (1 << sigbits) - 1,
416 0, (1 << sigbits) - 1);
429 popcolors = (l_int32)(FractByPopulation * maxcolors);
438 L_WARNING(
"vbox1 not defined; shouldn't happen!\n", procName);
442 vbox1->sortparam = vbox1->npix;
447 vbox2->sortparam = vbox2->npix;
451 if (ncolors >= popcolors)
453 if (niters++ > MaxItersAllowed) {
454 L_WARNING(
"infinite loop; perhaps too few pixels!\n", procName);
463 for (i = 0; i < lh->
n; i++) {
466 prod = (l_float32)vbox->npix * (l_float32)vbox->vol;
467 if (prod > maxprod) maxprod = prod;
469 norm = (maxprod == 0) ? 1.0 : 1000000.0 / maxprod;
472 vbox->sortparam = norm * vbox->npix * vbox->vol;
487 L_WARNING(
"vbox1 not defined; shouldn't happen!\n", procName);
491 vbox1->sortparam = norm * vbox1->npix * vbox1->vol;
496 vbox2->sortparam = norm * vbox2->npix * vbox2->vol;
500 if (ncolors >= maxcolors)
502 if (niters++ > MaxItersAllowed) {
503 L_WARNING(
"infinite loop; perhaps too few pixels!\n", procName);
512 vbox->sortparam = vbox->npix;
524 else if (ncolors <= 4)
526 else if (ncolors <= 16)
532 histo, histosize, sigbits);
537 if (rval < 5 && gval < 5 && bval < 5)
543 if (rval > 251 && gval > 251 && bval > 251)
604 l_int32 i, j, w, h, wplc, wplg, wpld, nc, unused, iscolor, factor, minside;
605 l_int32 rval, gval, bval, minval, maxval, val, grayval;
606 l_float32 pixfract, colorfract;
608 l_uint32 *datac, *datag, *datad, *linec, *lineg, *lined;
609 PIX *pixc, *pixg, *pixd;
612 PROCNAME(
"pixMedianCutQuantMixed");
614 if (!pixs || pixGetDepth(pixs) != 32)
615 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
617 return (
PIX *)ERROR_PTR(
"ngray < 2", procName, NULL);
618 if (ncolor + ngray > 255)
619 return (
PIX *)ERROR_PTR(
"ncolor + ngray > 255", procName, NULL);
620 if (darkthresh <= 0) darkthresh = 20;
621 if (lightthresh <= 0) lightthresh = 244;
622 if (diffthresh <= 0) diffthresh = 20;
629 minside = L_MIN(w, h);
630 factor = L_MAX(1, minside / 400);
632 &pixfract, &colorfract);
633 if (pixfract * colorfract < 0.0001) {
634 L_INFO(
"\n Pixel fraction neither white nor black = %6.3f" 635 "\n Color fraction of those pixels = %6.3f" 636 "\n Quantizing in gray\n",
637 procName, pixfract, colorfract);
651 wplc = pixGetWpl(pixc);
652 wplg = pixGetWpl(pixg);
653 lut = (l_int32 *)LEPT_CALLOC(256,
sizeof(l_int32));
654 for (i = 0; i < 256; i++)
655 lut[i] = ncolor + 1 + (i * (ngray - 1) + 128) / 255;
656 for (i = 0; i < h; i++) {
657 linec = datac + i * wplc;
658 lineg = datag + i * wplg;
659 for (j = 0; j < w; j++) {
662 minval = L_MIN(rval, gval);
663 minval = L_MIN(minval, bval);
664 maxval = L_MAX(rval, gval);
665 maxval = L_MAX(maxval, bval);
666 if (maxval >= darkthresh &&
667 minval <= lightthresh &&
668 maxval - minval >= diffthresh) {
673 grayval = (maxval + minval) / 2;
681 DefaultSigBits, 1, 0);
685 cmap = pixGetColormap(pixd);
687 unused = ncolor + 1 - nc;
689 L_ERROR(
"Too many colors: extra = %d\n", procName, -unused);
691 L_INFO(
"%d unused colors\n", procName, unused);
692 for (i = 0; i < unused; i++)
695 for (i = 0; i < ngray; i++) {
696 grayval = (255 * i) / (ngray - 1);
702 wpld = pixGetWpl(pixd);
703 for (i = 0; i < h; i++) {
704 lined = datad + i * wpld;
705 lineg = datag + i * wplg;
706 for (j = 0; j < w; j++) {
779 l_int32 ncolors, iscolor;
782 PROCNAME(
"pixFewColorsMedianCutQuantMixed");
784 if (!pixs || pixGetDepth(pixs) != 32)
785 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", procName, NULL);
786 if (maxncolors <= 0) maxncolors = 20;
787 if (darkthresh <= 0) darkthresh = 20;
788 if (lightthresh <= 0) lightthresh = 244;
789 if (diffthresh <= 0) diffthresh = 15;
790 if (ncolor < maxncolors) {
791 L_WARNING(
"ncolor too small; setting to %d\n", procName, maxncolors);
794 if (ngray < maxncolors) {
795 L_WARNING(
"ngray too small; setting to %d\n", procName, maxncolors);
804 if (ncolors > maxncolors)
805 return (
PIX *)ERROR_PTR(
"too many colors", procName, NULL);
817 lightthresh, diffthresh);
847 l_int32 i, j, w, h, wpl, rshift, index, histosize;
849 l_uint32 mask, pixel;
850 l_uint32 *data, *line;
852 PROCNAME(
"pixMedianCutHisto");
855 return (l_int32 *)ERROR_PTR(
"pixs not defined", procName, NULL);
856 if (pixGetDepth(pixs) != 32)
857 return (l_int32 *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
858 if (sigbits < 5 || sigbits > 6)
859 return (l_int32 *)ERROR_PTR(
"sigbits not 5 or 6", procName, NULL);
861 return (l_int32 *)ERROR_PTR(
"subsample not > 0", procName, NULL);
863 histosize = 1 << (3 * sigbits);
864 if ((histo = (l_int32 *)LEPT_CALLOC(histosize,
sizeof(l_int32))) == NULL)
865 return (l_int32 *)ERROR_PTR(
"histo not made", procName, NULL);
867 rshift = 8 - sigbits;
868 mask = 0xff >> rshift;
871 wpl = pixGetWpl(pixs);
872 for (i = 0; i < h; i += subsample) {
873 line = data + i * wpl;
874 for (j = 0; j < w; j += subsample) {
913 l_int32 i, index, shift, rval, gval, bval;
917 PROCNAME(
"pixcmapGenerateFromHisto");
920 return (
PIXCMAP *)ERROR_PTR(
"pixs not defined", procName, NULL);
921 if (pixGetDepth(pixs) != 32)
922 return (
PIXCMAP *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
924 return (
PIXCMAP *)ERROR_PTR(
"histo not defined", procName, NULL);
930 mask = 0xff >> shift;
931 for (i = 0, index = 0; i < histosize; i++) {
933 rval = (i >> (2 * sigbits)) << shift;
934 gval = ((i >> sigbits) & mask) << shift;
935 bval = (i & mask) << shift;
974 l_uint8 *bufu8r, *bufu8g, *bufu8b;
975 l_int32 i, j, w, h, wpls, wpld, rshift, index, cmapindex, success;
976 l_int32 rval, gval, bval, rc, gc, bc;
977 l_int32 dif, val1, val2, val3;
978 l_int32 *buf1r, *buf1g, *buf1b, *buf2r, *buf2g, *buf2b;
979 l_uint32 *datas, *datad, *lines, *lined;
980 l_uint32 mask, pixel;
983 PROCNAME(
"pixQuantizeWithColormap");
985 if (!pixs || pixGetDepth(pixs) != 32)
986 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", procName, NULL);
988 return (
PIX *)ERROR_PTR(
"cmap not defined", procName, NULL);
990 return (
PIX *)ERROR_PTR(
"indexmap not defined", procName, NULL);
997 pixCopyResolution(pixd, pixs);
998 pixCopyInputFormat(pixd, pixs);
1001 wpls = pixGetWpl(pixs);
1002 wpld = pixGetWpl(pixd);
1004 rshift = 8 - sigbits;
1005 mask = 0xff >> rshift;
1006 if (ditherflag == 0) {
1007 for (i = 0; i < h; i++) {
1008 lines = datas + i * wpls;
1009 lined = datad + i * wpld;
1010 if (outdepth == 1) {
1011 for (j = 0; j < w; j++) {
1015 if (indexmap[index])
1018 }
else if (outdepth == 2) {
1019 for (j = 0; j < w; j++) {
1025 }
else if (outdepth == 4) {
1026 for (j = 0; j < w; j++) {
1033 for (j = 0; j < w; j++) {
1043 bufu8r = bufu8g = bufu8b = NULL;
1044 buf1r = buf1g = buf1b = buf2r = buf2g = buf2b = NULL;
1045 bufu8r = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1046 bufu8g = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1047 bufu8b = (l_uint8 *)LEPT_CALLOC(w,
sizeof(l_uint8));
1048 buf1r = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1049 buf1g = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1050 buf1b = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1051 buf2r = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1052 buf2g = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1053 buf2b = (l_int32 *)LEPT_CALLOC(w,
sizeof(l_int32));
1054 if (!bufu8r || !bufu8g || !bufu8b || !buf1r || !buf1g ||
1055 !buf1b || !buf2r || !buf2g || !buf2b) {
1056 L_ERROR(
"buffer not made\n", procName);
1058 goto buffer_cleanup;
1063 for (j = 0; j < w; j++) {
1064 buf2r[j] = 64 * bufu8r[j];
1065 buf2g[j] = 64 * bufu8g[j];
1066 buf2b[j] = 64 * bufu8b[j];
1069 for (i = 0; i < h - 1; i++) {
1071 memcpy(buf1r, buf2r, 4 * w);
1072 memcpy(buf1g, buf2g, 4 * w);
1073 memcpy(buf1b, buf2b, 4 * w);
1075 for (j = 0; j < w; j++) {
1076 buf2r[j] = 64 * bufu8r[j];
1077 buf2g[j] = 64 * bufu8g[j];
1078 buf2b[j] = 64 * bufu8b[j];
1082 lined = datad + i * wpld;
1083 for (j = 0; j < w - 1; j++) {
1084 rval = buf1r[j] / 64;
1085 gval = buf1g[j] / 64;
1086 bval = buf1b[j] / 64;
1087 index = ((rval >> rshift) << (2 * sigbits)) +
1088 ((gval >> rshift) << sigbits) + (bval >> rshift);
1089 cmapindex = indexmap[index];
1093 dif = buf1r[j] / 8 - 8 * rc;
1094 if (dif > DifCap) dif = DifCap;
1095 if (dif < -DifCap) dif = -DifCap;
1097 val1 = buf1r[j + 1] + 3 * dif;
1098 val2 = buf2r[j] + 3 * dif;
1099 val3 = buf2r[j + 1] + 2 * dif;
1101 buf1r[j + 1] = L_MIN(16383, val1);
1102 buf2r[j] = L_MIN(16383, val2);
1103 buf2r[j + 1] = L_MIN(16383, val3);
1105 buf1r[j + 1] = L_MAX(0, val1);
1106 buf2r[j] = L_MAX(0, val2);
1107 buf2r[j + 1] = L_MAX(0, val3);
1111 dif = buf1g[j] / 8 - 8 * gc;
1112 if (dif > DifCap) dif = DifCap;
1113 if (dif < -DifCap) dif = -DifCap;
1115 val1 = buf1g[j + 1] + 3 * dif;
1116 val2 = buf2g[j] + 3 * dif;
1117 val3 = buf2g[j + 1] + 2 * dif;
1119 buf1g[j + 1] = L_MIN(16383, val1);
1120 buf2g[j] = L_MIN(16383, val2);
1121 buf2g[j + 1] = L_MIN(16383, val3);
1123 buf1g[j + 1] = L_MAX(0, val1);
1124 buf2g[j] = L_MAX(0, val2);
1125 buf2g[j + 1] = L_MAX(0, val3);
1129 dif = buf1b[j] / 8 - 8 * bc;
1130 if (dif > DifCap) dif = DifCap;
1131 if (dif < -DifCap) dif = -DifCap;
1133 val1 = buf1b[j + 1] + 3 * dif;
1134 val2 = buf2b[j] + 3 * dif;
1135 val3 = buf2b[j + 1] + 2 * dif;
1137 buf1b[j + 1] = L_MIN(16383, val1);
1138 buf2b[j] = L_MIN(16383, val2);
1139 buf2b[j + 1] = L_MIN(16383, val3);
1141 buf1b[j + 1] = L_MAX(0, val1);
1142 buf2b[j] = L_MAX(0, val2);
1143 buf2b[j + 1] = L_MAX(0, val3);
1149 rval = buf1r[w - 1] / 64;
1150 gval = buf1g[w - 1] / 64;
1151 bval = buf1b[w - 1] / 64;
1152 index = ((rval >> rshift) << (2 * sigbits)) +
1153 ((gval >> rshift) << sigbits) + (bval >> rshift);
1158 lined = datad + (h - 1) * wpld;
1159 for (j = 0; j < w; j++) {
1160 rval = buf2r[j] / 64;
1161 gval = buf2g[j] / 64;
1162 bval = buf2b[j] / 64;
1163 index = ((rval >> rshift) << (2 * sigbits)) +
1164 ((gval >> rshift) << sigbits) + (bval >> rshift);
1208 l_int32 rval, gval, bval;
1210 rval = pixel >> (24 + rshift);
1211 gval = (pixel >> (16 + rshift)) & mask;
1212 bval = (pixel >> (8 + rshift)) & mask;
1213 *pindex = (rval << (2 * sigbits)) + (gval << sigbits) + bval;
1238 l_int32 rmin, rmax, gmin, gmax, bmin, bmax, rval, gval, bval;
1239 l_int32 w, h, wpl, i, j, rshift;
1240 l_uint32 mask, pixel;
1241 l_uint32 *data, *line;
1243 PROCNAME(
"pixGetColorRegion");
1246 return (
L_BOX3D *)ERROR_PTR(
"pixs not defined", procName, NULL);
1248 rmin = gmin = bmin = 1000000;
1249 rmax = gmax = bmax = 0;
1250 rshift = 8 - sigbits;
1251 mask = 0xff >> rshift;
1254 wpl = pixGetWpl(pixs);
1255 for (i = 0; i < h; i += subsample) {
1256 line = data + i * wpl;
1257 for (j = 0; j < w; j += subsample) {
1259 rval = pixel >> (24 + rshift);
1260 gval = (pixel >> (16 + rshift)) & mask;
1261 bval = (pixel >> (8 + rshift)) & mask;
1264 else if (rval > rmax)
1268 else if (gval > gmax)
1272 else if (bval > bmax)
1277 return box3dCreate(rmin, rmax, gmin, gmax, bmin, bmax);
1297 l_int32 i, j, k, sum, rw, gw, bw, maxw, index;
1298 l_int32 total, left, right;
1299 l_int32 partialsum[128];
1302 PROCNAME(
"medianCutApply");
1304 if (pvbox1) *pvbox1 = NULL;
1305 if (pvbox2) *pvbox2 = NULL;
1307 return ERROR_INT(
"histo not defined", procName, 1);
1309 return ERROR_INT(
"vbox not defined", procName, 1);
1310 if (!pvbox1 || !pvbox2)
1311 return ERROR_INT(
"&vbox1 and &vbox2 not both defined", procName, 1);
1314 return ERROR_INT(
"no pixels in vbox", procName, 1);
1321 rw = vbox->r2 - vbox->r1 + 1;
1322 gw = vbox->g2 - vbox->g1 + 1;
1323 bw = vbox->b2 - vbox->b1 + 1;
1324 if (rw == 1 && gw == 1 && bw == 1) {
1330 maxw = L_MAX(rw, gw);
1331 maxw = L_MAX(maxw, bw);
1332 #if DEBUG_SPLIT_AXES 1335 else if (gw == maxw)
1344 for (i = vbox->r1; i <= vbox->r2; i++) {
1346 for (j = vbox->g1; j <= vbox->g2; j++) {
1347 for (k = vbox->b1; k <= vbox->b2; k++) {
1348 index = (i << (2 * sigbits)) + (j << sigbits) + k;
1349 sum += histo[index];
1353 partialsum[i] = total;
1355 }
else if (maxw == gw) {
1356 for (i = vbox->g1; i <= vbox->g2; i++) {
1358 for (j = vbox->r1; j <= vbox->r2; j++) {
1359 for (k = vbox->b1; k <= vbox->b2; k++) {
1360 index = (i << sigbits) + (j << (2 * sigbits)) + k;
1361 sum += histo[index];
1365 partialsum[i] = total;
1368 for (i = vbox->b1; i <= vbox->b2; i++) {
1370 for (j = vbox->r1; j <= vbox->r2; j++) {
1371 for (k = vbox->g1; k <= vbox->g2; k++) {
1372 index = i + (j << (2 * sigbits)) + (k << sigbits);
1373 sum += histo[index];
1377 partialsum[i] = total;
1390 vbox1 = vbox2 = NULL;
1392 for (i = vbox->r1; i <= vbox->r2; i++) {
1393 if (partialsum[i] > total / 2) {
1396 left = i - vbox->r1;
1397 right = vbox->r2 - i;
1399 vbox1->r2 = L_MIN(vbox->r2 - 1, i + right / 2);
1401 vbox1->r2 = L_MAX(vbox->r1, i - 1 - left / 2);
1402 vbox2->r1 = vbox1->r2 + 1;
1406 }
else if (maxw == gw) {
1407 for (i = vbox->g1; i <= vbox->g2; i++) {
1408 if (partialsum[i] > total / 2) {
1411 left = i - vbox->g1;
1412 right = vbox->g2 - i;
1414 vbox1->g2 = L_MIN(vbox->g2 - 1, i + right / 2);
1416 vbox1->g2 = L_MAX(vbox->g1, i - 1 - left / 2);
1417 vbox2->g1 = vbox1->g2 + 1;
1422 for (i = vbox->b1; i <= vbox->b2; i++) {
1423 if (partialsum[i] > total / 2) {
1426 left = i - vbox->b1;
1427 right = vbox->b2 - i;
1429 vbox1->b2 = L_MIN(vbox->b2 - 1, i + right / 2);
1431 vbox1->b2 = L_MAX(vbox->b1, i - 1 - left / 2);
1432 vbox2->b1 = vbox1->b2 + 1;
1440 return ERROR_INT(
"vbox1 not made; shouldn't happen", procName, 1);
1442 return ERROR_INT(
"vbox2 not made; shouldn't happen", procName, 1);
1475 l_int32 index, rval, gval, bval;
1479 PROCNAME(
"pixcmapGenerateFromMedianCuts");
1482 return (
PIXCMAP *)ERROR_PTR(
"lh not defined", procName, NULL);
1484 return (
PIXCMAP *)ERROR_PTR(
"histo not defined", procName, NULL);
1486 rval = gval = bval = 0;
1535 l_int32 i, j, k, ntot, mult, histoindex, rsum, gsum, bsum;
1537 PROCNAME(
"vboxGetAverageColor");
1540 return ERROR_INT(
"vbox not defined", procName, 1);
1542 return ERROR_INT(
"histo not defined", procName, 1);
1543 if (!prval || !pgval || !pbval)
1544 return ERROR_INT(
"&p*val not all defined", procName, 1);
1546 *prval = *pgval = *pbval = 0;
1548 mult = 1 << (8 - sigbits);
1549 rsum = gsum = bsum = 0;
1550 for (i = vbox->r1; i <= vbox->r2; i++) {
1551 for (j = vbox->g1; j <= vbox->g2; j++) {
1552 for (k = vbox->b1; k <= vbox->b2; k++) {
1553 histoindex = (i << (2 * sigbits)) + (j << sigbits) + k;
1554 ntot += histo[histoindex];
1555 rsum += (l_int32)(histo[histoindex] * (i + 0.5) * mult);
1556 gsum += (l_int32)(histo[histoindex] * (j + 0.5) * mult);
1557 bsum += (l_int32)(histo[histoindex] * (k + 0.5) * mult);
1559 histo[histoindex] = index;
1565 *prval = mult * (vbox->r1 + vbox->r2 + 1) / 2;
1566 *pgval = mult * (vbox->g1 + vbox->g2 + 1) / 2;
1567 *pbval = mult * (vbox->b1 + vbox->b2 + 1) / 2;
1569 *prval = rsum / ntot;
1570 *pgval = gsum / ntot;
1571 *pbval = bsum / ntot;
1575 lept_stderr(
"ntot[%d] = %d: [%d, %d, %d], (%d, %d, %d)\n",
1576 index, ntot, vbox->r2 - vbox->r1 + 1,
1577 vbox->g2 - vbox->g1 + 1, vbox->b2 - vbox->b1 + 1,
1578 *prval, *pgval, *pbval);
1598 l_int32 i, j, k, npix, index;
1600 PROCNAME(
"vboxGetCount");
1603 return ERROR_INT(
"vbox not defined", procName, 0);
1605 return ERROR_INT(
"histo not defined", procName, 0);
1608 for (i = vbox->r1; i <= vbox->r2; i++) {
1609 for (j = vbox->g1; j <= vbox->g2; j++) {
1610 for (k = vbox->b1; k <= vbox->b2; k++) {
1611 index = (i << (2 * sigbits)) + (j << sigbits) + k;
1612 npix += histo[index];
1630 PROCNAME(
"vboxGetVolume");
1633 return ERROR_INT(
"vbox not defined", procName, 0);
1635 return ((vbox->r2 - vbox->r1 + 1) * (vbox->g2 - vbox->g1 + 1) *
1636 (vbox->b2 - vbox->b1 + 1));
1682 PROCNAME(
"box3dCopy");
1685 return (
L_BOX3D *)ERROR_PTR(
"vbox not defined", procName, NULL);
1687 vboxc =
box3dCreate(vbox->r1, vbox->r2, vbox->g1, vbox->g2,
1688 vbox->b1, vbox->b2);
1689 vboxc->npix = vbox->npix;
1690 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()
void * lheapGetElement(L_HEAP *lh, l_int32 index)
lheapGetElement()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
void lept_stderr(const char *fmt,...)
lept_stderr()
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()
L_HEAP * lheapCreate(l_int32 n, l_int32 direction)
lheapCreate()
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)
#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(const PIXCMAP *cmap)
pixcmapGetCount()
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()