99 #include "allheaders.h" 102 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
103 l_uint32 *sumtab, l_uint8 *valtab);
107 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
108 l_uint32 *sumtab, l_uint8 *valtab);
112 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
113 l_uint32 *sumtab, l_uint8 *valtab);
117 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
118 l_int32 *tab8, l_uint8 *valtab);
121 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
122 l_int32 *tab8, l_uint8 *valtab);
125 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
127 static l_int32
scaleMipmapLow(l_uint32 *datad, l_int32 wd, l_int32 hd,
128 l_int32 wpld, l_uint32 *datas1, l_int32 wpls1,
129 l_uint32 *datas2, l_int32 wpls2, l_float32 red);
131 extern l_float32 AlphaMaskBorderVals[2];
205 l_float32 scalefactor)
207 l_int32 w, h, minsrc, mindest;
211 PROCNAME(
"pixScaleToGray");
214 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
215 if (pixGetDepth(pixs) != 1)
216 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
217 if (scalefactor <= 0.0)
218 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
219 if (scalefactor >= 1.0)
220 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
222 minsrc = L_MIN(w, h);
223 mindest = (l_int32)((l_float32)minsrc * scalefactor);
225 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
227 if (scalefactor > 0.5) {
228 mag = 2.0 * scalefactor;
231 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
233 }
else if (scalefactor == 0.5) {
235 }
else if (scalefactor > 0.33333) {
236 mag = 3.0 * scalefactor;
239 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
241 }
else if (scalefactor > 0.25) {
242 mag = 4.0 * scalefactor;
245 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
247 }
else if (scalefactor == 0.25) {
249 }
else if (scalefactor > 0.16667) {
250 mag = 6.0 * scalefactor;
253 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
255 }
else if (scalefactor == 0.16667) {
257 }
else if (scalefactor > 0.125) {
258 mag = 8.0 * scalefactor;
261 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
263 }
else if (scalefactor == 0.125) {
265 }
else if (scalefactor > 0.0625) {
266 red = 8.0 * scalefactor;
269 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
271 }
else if (scalefactor == 0.0625) {
274 red = 16.0 * scalefactor;
277 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
286 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
287 pixCopyInputFormat(pixd, pixs);
316 l_float32 scalefactor)
318 l_int32 w, h, minsrc, mindest;
319 l_float32 eps, factor;
322 PROCNAME(
"pixScaleToGrayFast");
325 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
326 if (pixGetDepth(pixs) != 1)
327 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
328 if (scalefactor <= 0.0)
329 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
330 if (scalefactor >= 1.0)
331 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
333 minsrc = L_MIN(w, h);
334 mindest = (l_int32)((l_float32)minsrc * scalefactor);
336 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
340 if (scalefactor > 0.5 - eps && scalefactor < 0.5 + eps)
342 else if (scalefactor > 0.33333 - eps && scalefactor < 0.33333 + eps)
344 else if (scalefactor > 0.25 - eps && scalefactor < 0.25 + eps)
346 else if (scalefactor > 0.16666 - eps && scalefactor < 0.16666 + eps)
348 else if (scalefactor > 0.125 - eps && scalefactor < 0.125 + eps)
350 else if (scalefactor > 0.0625 - eps && scalefactor < 0.0625 + eps)
353 if (scalefactor > 0.0625) {
354 factor = 2.0 * scalefactor;
356 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
359 factor = 16.0 * scalefactor;
361 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
369 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
370 pixCopyInputFormat(pixd, pixs);
389 l_int32 ws, hs, wd, hd;
392 l_uint32 *datas, *datad;
395 PROCNAME(
"pixScaleToGray2");
398 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
399 if (pixGetDepth(pixs) != 1)
400 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
405 if (wd == 0 || hd == 0)
406 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
408 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
409 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
410 pixCopyInputFormat(pixd, pixs);
411 pixCopyResolution(pixd, pixs);
412 pixScaleResolution(pixd, 0.5, 0.5);
415 wpls = pixGetWpl(pixs);
416 wpld = pixGetWpl(pixd);
446 l_int32 ws, hs, wd, hd;
449 l_uint32 *datas, *datad;
452 PROCNAME(
"pixScaleToGray3");
455 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
456 if (pixGetDepth(pixs) != 1)
457 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
460 wd = (ws / 3) & 0xfffffff8;
462 if (wd == 0 || hd == 0)
463 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
465 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
466 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
467 pixCopyInputFormat(pixd, pixs);
468 pixCopyResolution(pixd, pixs);
469 pixScaleResolution(pixd, 0.33333, 0.33333);
472 wpls = pixGetWpl(pixs);
473 wpld = pixGetWpl(pixd);
500 l_int32 ws, hs, wd, hd;
503 l_uint32 *datas, *datad;
506 PROCNAME(
"pixScaleToGray4");
509 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
510 if (pixGetDepth(pixs) != 1)
511 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
514 wd = (ws / 4) & 0xfffffffe;
516 if (wd == 0 || hd == 0)
517 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
519 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
520 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
521 pixCopyInputFormat(pixd, pixs);
522 pixCopyResolution(pixd, pixs);
523 pixScaleResolution(pixd, 0.25, 0.25);
526 wpls = pixGetWpl(pixs);
527 wpld = pixGetWpl(pixd);
555 l_int32 ws, hs, wd, hd, wpld, wpls;
557 l_uint32 *datas, *datad;
560 PROCNAME(
"pixScaleToGray6");
563 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
564 if (pixGetDepth(pixs) != 1)
565 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
568 wd = (ws / 6) & 0xfffffff8;
570 if (wd == 0 || hd == 0)
571 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
573 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
574 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
575 pixCopyInputFormat(pixd, pixs);
576 pixCopyResolution(pixd, pixs);
577 pixScaleResolution(pixd, 0.16667, 0.16667);
580 wpls = pixGetWpl(pixs);
581 wpld = pixGetWpl(pixd);
603 l_int32 ws, hs, wd, hd;
606 l_uint32 *datas, *datad;
609 PROCNAME(
"pixScaleToGray8");
612 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
613 if (pixGetDepth(pixs) != 1)
614 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
619 if (wd == 0 || hd == 0)
620 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
622 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
623 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
624 pixCopyInputFormat(pixd, pixs);
625 pixCopyResolution(pixd, pixs);
626 pixScaleResolution(pixd, 0.125, 0.125);
629 wpls = pixGetWpl(pixs);
630 wpld = pixGetWpl(pixd);
651 l_int32 ws, hs, wd, hd;
654 l_uint32 *datas, *datad;
657 PROCNAME(
"pixScaleToGray16");
660 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
661 if (pixGetDepth(pixs) != 1)
662 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
667 if (wd == 0 || hd == 0)
668 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
670 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
671 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
672 pixCopyInputFormat(pixd, pixs);
673 pixCopyResolution(pixd, pixs);
674 pixScaleResolution(pixd, 0.0625, 0.0625);
677 wpls = pixGetWpl(pixs);
678 wpld = pixGetWpl(pixd);
723 l_float32 scalefactor)
725 l_int32 w, h, minsrc, mindest;
727 PIX *pixs1, *pixs2, *pixt, *pixd;
729 PROCNAME(
"pixScaleToGrayMipmap");
732 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
733 if (pixGetDepth(pixs) != 1)
734 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
735 if (scalefactor <= 0.0)
736 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
737 if (scalefactor >= 1.0)
738 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
740 minsrc = L_MIN(w, h);
741 mindest = (l_int32)((l_float32)minsrc * scalefactor);
743 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
745 if (scalefactor > 0.5) {
749 }
else if (scalefactor == 0.5) {
751 }
else if (scalefactor > 0.25) {
754 red = 2. * scalefactor;
755 }
else if (scalefactor == 0.25) {
757 }
else if (scalefactor > 0.125) {
760 red = 4. * scalefactor;
761 }
else if (scalefactor == 0.125) {
763 }
else if (scalefactor > 0.0625) {
766 red = 8. * scalefactor;
767 }
else if (scalefactor == 0.0625) {
770 red = 16.0 * scalefactor;
772 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
782 pixCopyInputFormat(pixd, pixs);
814 l_int32 ws1, hs1, ws2, hs2, wd, hd, wpls1, wpls2, wpld;
815 l_uint32 *datas1, *datas2, *datad;
818 PROCNAME(
"pixScaleMipmap");
820 if (!pixs1 || pixGetDepth(pixs1) != 8 || pixGetColormap(pixs1))
821 return (
PIX *)ERROR_PTR(
"pixs1 underdefined, not 8 bpp, or cmapped",
823 if (!pixs2 || pixGetDepth(pixs2) != 8 || pixGetColormap(pixs2))
824 return (
PIX *)ERROR_PTR(
"pixs2 underdefined, not 8 bpp, or cmapped",
828 if (scale > 1.0 || scale < 0.5)
829 return (
PIX *)ERROR_PTR(
"scale not in [0.5, 1.0]", procName, NULL);
831 return (
PIX *)ERROR_PTR(
"invalid width ratio", procName, NULL);
833 return (
PIX *)ERROR_PTR(
"invalid height ratio", procName, NULL);
838 wpls1 = pixGetWpl(pixs1);
840 wpls2 = pixGetWpl(pixs2);
841 wd = (l_int32)(2. * scale * pixGetWidth(pixs2));
842 hd = (l_int32)(2. * scale * pixGetHeight(pixs2));
843 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
844 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
845 pixCopyInputFormat(pixd, pixs1);
846 pixCopyResolution(pixd, pixs1);
847 pixScaleResolution(pixd, scale, scale);
849 wpld = pixGetWpl(pixd);
851 scaleMipmapLow(datad, wd, hd, wpld, datas1, wpls1, datas2, wpls2, scale);
870 l_int32 w, h, d, wd, hd, wpls, wpld, start, i, j, k;
874 l_uint32 *lines, *datas, *lined, *datad;
877 PROCNAME(
"pixExpandReplicate");
880 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
882 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
883 return (
PIX *)ERROR_PTR(
"depth not in {1,2,4,8,16,32}", procName, NULL);
885 return (
PIX *)ERROR_PTR(
"factor <= 0; invalid", procName, NULL);
894 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
895 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
897 pixCopyInputFormat(pixd, pixs);
898 pixCopyResolution(pixd, pixs);
899 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
901 wpls = pixGetWpl(pixs);
903 wpld = pixGetWpl(pixd);
907 for (i = 0; i < h; i++) {
908 lines = datas + i * wpls;
909 lined = datad + factor * i * wpld;
910 for (j = 0; j < w; j++) {
913 for (k = 0; k < factor; k++)
916 for (k = 1; k < factor; k++)
917 memcpy(lined + k * wpld, lined, 4 * wpld);
921 for (i = 0; i < h; i++) {
922 lines = datas + i * wpls;
923 lined = datad + factor * i * wpld;
924 for (j = 0; j < w; j++) {
927 for (k = 0; k < factor; k++)
930 for (k = 1; k < factor; k++)
931 memcpy(lined + k * wpld, lined, 4 * wpld);
935 for (i = 0; i < h; i++) {
936 lines = datas + i * wpls;
937 lined = datad + factor * i * wpld;
938 for (j = 0; j < w; j++) {
941 for (k = 0; k < factor; k++)
944 for (k = 1; k < factor; k++)
945 memcpy(lined + k * wpld, lined, 4 * wpld);
949 for (i = 0; i < h; i++) {
950 lines = datas + i * wpls;
951 lined = datad + factor * i * wpld;
952 for (j = 0; j < w; j++) {
955 for (k = 0; k < factor; k++)
958 for (k = 1; k < factor; k++)
959 memcpy(lined + k * wpld, lined, 4 * wpld);
963 for (i = 0; i < h; i++) {
964 lines = datas + i * wpls;
965 lined = datad + factor * i * wpld;
966 for (j = 0; j < w; j++) {
967 sval32 = *(lines + j);
969 for (k = 0; k < factor; k++)
970 *(lined + start + k) = sval32;
972 for (k = 1; k < factor; k++)
973 memcpy(lined + k * wpld, lined, 4 * wpld);
977 fprintf(stderr,
"invalid depth\n");
980 if (d == 32 && pixGetSpp(pixs) == 4)
1019 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1020 l_int32 minval, maxval, val;
1021 l_uint32 *datas, *datad, *lines, *lined;
1024 PROCNAME(
"pixScaleGrayMinMax");
1026 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1027 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1030 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1031 type != L_CHOOSE_MAXDIFF)
1032 return (
PIX *)ERROR_PTR(
"invalid type", procName, NULL);
1033 if (xfact < 1 || yfact < 1)
1034 return (
PIX *)ERROR_PTR(
"xfact and yfact must be >= 1", procName, NULL);
1036 if (xfact == 2 && yfact == 2)
1049 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1050 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1051 pixCopyInputFormat(pixd, pixs);
1054 wpls = pixGetWpl(pixs);
1055 wpld = pixGetWpl(pixd);
1056 for (i = 0; i < hd; i++) {
1057 lined = datad + i * wpld;
1058 for (j = 0; j < wd; j++) {
1059 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1061 for (k = 0; k < yfact; k++) {
1062 lines = datas + (yfact * i + k) * wpls;
1063 for (m = 0; m < xfact; m++) {
1070 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1072 for (k = 0; k < yfact; k++) {
1073 lines = datas + (yfact * i + k) * wpls;
1074 for (m = 0; m < xfact; m++) {
1081 if (type == L_CHOOSE_MIN)
1083 else if (type == L_CHOOSE_MAX)
1124 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k;
1125 l_int32 minval, maxval;
1127 l_uint32 *datas, *datad, *lines, *lined;
1130 PROCNAME(
"pixScaleGrayMinMax2");
1132 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1133 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1136 if (ws < 2 || hs < 2)
1137 return (
PIX *)ERROR_PTR(
"too small: ws < 2 or hs < 2", procName, NULL);
1138 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1139 type != L_CHOOSE_MAXDIFF)
1140 return (
PIX *)ERROR_PTR(
"invalid type", procName, NULL);
1144 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1145 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1146 pixCopyInputFormat(pixd, pixs);
1149 wpls = pixGetWpl(pixs);
1150 wpld = pixGetWpl(pixd);
1151 for (i = 0; i < hd; i++) {
1152 lines = datas + 2 * i * wpls;
1153 lined = datad + i * wpld;
1154 for (j = 0; j < wd; j++) {
1159 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1161 for (k = 0; k < 4; k++) {
1162 if (val[k] < minval)
1166 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1168 for (k = 0; k < 4; k++) {
1169 if (val[k] > maxval)
1173 if (type == L_CHOOSE_MIN)
1175 else if (type == L_CHOOSE_MAX)
1210 PIX *pixt1, *pixt2, *pixt3, *pixt4;
1212 PROCNAME(
"pixScaleGrayRankCascade");
1214 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1215 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1217 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
1218 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", procName, NULL);
1221 L_WARNING(
"no reduction because level1 not > 0\n", procName);
1271 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1272 l_int32 minval, maxval, rankval, minindex, maxindex;
1275 l_uint32 *datas, *datad, *lines, *lined;
1278 PROCNAME(
"pixScaleGrayRank2");
1280 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1281 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1283 if (rank < 1 || rank > 4)
1284 return (
PIX *)ERROR_PTR(
"invalid rank", procName, NULL);
1294 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1295 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1296 pixCopyInputFormat(pixd, pixs);
1299 wpls = pixGetWpl(pixs);
1300 wpld = pixGetWpl(pixd);
1301 for (i = 0; i < hd; i++) {
1302 lines = datas + 2 * i * wpls;
1303 lined = datad + i * wpld;
1304 for (j = 0; j < wd; j++) {
1309 minval = maxval = val[0];
1310 minindex = maxindex = 0;
1311 for (k = 1; k < 4; k++) {
1312 if (val[k] < minval) {
1317 if (val[k] > maxval) {
1322 for (k = 0, m = 0; k < 4; k++) {
1323 if (k == minindex || k == maxindex)
1325 midval[m++] = val[k];
1330 rankval = L_MIN(midval[0], midval[1]);
1332 rankval = L_MAX(midval[0], midval[1]);
1365 PROCNAME(
"pixScaleAndTransferAlpha");
1368 return ERROR_INT(
"pixs and pixd not both defined", procName, 1);
1369 if (pixGetDepth(pixs) != 32 || pixGetSpp(pixs) != 4)
1370 return ERROR_INT(
"pixs not 32 bpp and 4 spp", procName, 1);
1371 if (pixGetDepth(pixd) != 32)
1372 return ERROR_INT(
"pixd not 32 bpp", procName, 1);
1374 if (scalex == 1.0 && scaley == 1.0) {
1380 pix2 =
pixScale(pix1, scalex, scaley);
1442 l_int32 ws, hs, d, spp;
1443 PIX *pixd, *pix32, *pixg2, *pixgs;
1445 PROCNAME(
"pixScaleWithAlpha");
1448 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1450 if (d != 32 && !pixGetColormap(pixs))
1451 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", procName, NULL);
1452 if (scalex <= 0.0 || scaley <= 0.0)
1453 return (
PIX *)ERROR_PTR(
"scale factor <= 0.0", procName, NULL);
1454 if (pixg && pixGetDepth(pixg) != 8) {
1455 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
1459 if (!pixg && (fract < 0.0 || fract > 1.0)) {
1460 L_WARNING(
"invalid fract; using fully opaque\n", procName);
1463 if (!pixg && fract == 0.0)
1464 L_WARNING(
"transparent alpha; image will not be blended\n", procName);
1471 spp = pixGetSpp(pix32);
1472 pixSetSpp(pix32, 3);
1473 pixd =
pixScale(pix32, scalex, scaley);
1474 pixSetSpp(pix32, spp);
1482 else if (fract > 0.0)
1487 if (ws > 10 && hs > 10) {
1489 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
1491 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
1497 pixCopyInputFormat(pixd, pixs);
1544 l_int32 i, j, l, k, m, wd4, extra;
1545 l_uint32 sbyte1, sbyte2, sum;
1546 l_uint32 *lines, *lined;
1554 wd4 = wd & 0xfffffffc;
1556 for (i = 0, l = 0; i < hd; i++, l += 2) {
1557 lines = datas + l * wpls;
1558 lined = datad + i * wpld;
1559 for (j = 0, k = 0; j < wd4; j += 4, k++) {
1562 sum = sumtab[sbyte1] + sumtab[sbyte2];
1571 sum = sumtab[sbyte1] + sumtab[sbyte2];
1572 for (m = 0; m < extra; m++) {
1574 valtab[((sum >> (24 - 8 * m)) & 0xff)]);
1597 l_int32 sum[] = {0, 1, 1, 2};
1600 PROCNAME(
"makeSumTabSG2");
1602 if ((tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32))) == NULL)
1603 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1606 for (i = 0; i < 256; i++) {
1607 tab[i] = (sum[i & 0x3] | sum[(i >> 2) & 0x3] << 8 |
1608 sum[(i >> 4) & 0x3] << 16 | sum[(i >> 6) & 0x3] << 24);
1630 PROCNAME(
"makeValTabSG2");
1632 if ((tab = (l_uint8 *)LEPT_CALLOC(5,
sizeof(l_uint8))) == NULL)
1633 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1634 for (i = 0; i < 5; i++)
1635 tab[i] = 255 - (i * 255) / 4;
1689 l_uint32 threebytes1, threebytes2, threebytes3, sum;
1690 l_uint32 *lines, *lined;
1699 for (i = 0, l = 0; i < hd; i++, l += 3) {
1700 lines = datas + l * wpls;
1701 lined = datad + i * wpld;
1702 for (j = 0, k = 0; j < wd; j += 8, k += 3) {
1713 sum = sumtab[(threebytes1 >> 18)] +
1714 sumtab[(threebytes2 >> 18)] +
1715 sumtab[(threebytes3 >> 18)];
1719 sum = sumtab[((threebytes1 >> 12) & 0x3f)] +
1720 sumtab[((threebytes2 >> 12) & 0x3f)] +
1721 sumtab[((threebytes3 >> 12) & 0x3f)];
1725 sum = sumtab[((threebytes1 >> 6) & 0x3f)] +
1726 sumtab[((threebytes2 >> 6) & 0x3f)] +
1727 sumtab[((threebytes3 >> 6) & 0x3f)];
1731 sum = sumtab[(threebytes1 & 0x3f)] +
1732 sumtab[(threebytes2 & 0x3f)] +
1733 sumtab[(threebytes3 & 0x3f)];
1758 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3};
1761 PROCNAME(
"makeSumTabSG3");
1763 if ((tab = (l_uint32 *)LEPT_CALLOC(64,
sizeof(l_uint32))) == NULL)
1764 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1767 for (i = 0; i < 64; i++) {
1768 tab[i] = (sum[i & 0x07]) | (sum[(i >> 3) & 0x07] << 8);
1788 PROCNAME(
"makeValTabSG3");
1790 if ((tab = (l_uint8 *)LEPT_CALLOC(10,
sizeof(l_uint8))) == NULL)
1791 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1792 for (i = 0; i < 10; i++)
1793 tab[i] = 0xff - (i * 255) / 9;
1834 l_uint32 sbyte1, sbyte2, sbyte3, sbyte4, sum;
1835 l_uint32 *lines, *lined;
1843 for (i = 0, l = 0; i < hd; i++, l += 4) {
1844 lines = datas + l * wpls;
1845 lined = datad + i * wpld;
1846 for (j = 0, k = 0; j < wd; j += 2, k++) {
1851 sum = sumtab[sbyte1] + sumtab[sbyte2] +
1852 sumtab[sbyte3] + sumtab[sbyte4];
1875 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
1878 PROCNAME(
"makeSumTabSG4");
1880 if ((tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32))) == NULL)
1881 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1884 for (i = 0; i < 256; i++) {
1885 tab[i] = (sum[i & 0xf]) | (sum[(i >> 4) & 0xf] << 8);
1907 PROCNAME(
"makeValTabSG4");
1909 if ((tab = (l_uint8 *)LEPT_CALLOC(17,
sizeof(l_uint8))) == NULL)
1910 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1911 for (i = 0; i < 17; i++)
1912 tab[i] = 0xff - (i * 255) / 16;
1966 l_uint32 threebytes1, threebytes2, threebytes3;
1967 l_uint32 threebytes4, threebytes5, threebytes6, sum;
1968 l_uint32 *lines, *lined;
1977 for (i = 0, l = 0; i < hd; i++, l += 6) {
1978 lines = datas + l * wpls;
1979 lined = datad + i * wpld;
1980 for (j = 0, k = 0; j < wd; j += 4, k += 3) {
2003 sum = tab8[(threebytes1 >> 18)] +
2004 tab8[(threebytes2 >> 18)] +
2005 tab8[(threebytes3 >> 18)] +
2006 tab8[(threebytes4 >> 18)] +
2007 tab8[(threebytes5 >> 18)] +
2008 tab8[(threebytes6 >> 18)];
2012 sum = tab8[((threebytes1 >> 12) & 0x3f)] +
2013 tab8[((threebytes2 >> 12) & 0x3f)] +
2014 tab8[((threebytes3 >> 12) & 0x3f)] +
2015 tab8[((threebytes4 >> 12) & 0x3f)] +
2016 tab8[((threebytes5 >> 12) & 0x3f)] +
2017 tab8[((threebytes6 >> 12) & 0x3f)];
2020 sum = tab8[((threebytes1 >> 6) & 0x3f)] +
2021 tab8[((threebytes2 >> 6) & 0x3f)] +
2022 tab8[((threebytes3 >> 6) & 0x3f)] +
2023 tab8[((threebytes4 >> 6) & 0x3f)] +
2024 tab8[((threebytes5 >> 6) & 0x3f)] +
2025 tab8[((threebytes6 >> 6) & 0x3f)];
2028 sum = tab8[(threebytes1 & 0x3f)] +
2029 tab8[(threebytes2 & 0x3f)] +
2030 tab8[(threebytes3 & 0x3f)] +
2031 tab8[(threebytes4 & 0x3f)] +
2032 tab8[(threebytes5 & 0x3f)] +
2033 tab8[(threebytes6 & 0x3f)];
2055 PROCNAME(
"makeValTabSG6");
2057 if ((tab = (l_uint8 *)LEPT_CALLOC(37,
sizeof(l_uint8))) == NULL)
2058 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
2059 for (i = 0; i < 37; i++)
2060 tab[i] = 0xff - (i * 255) / 36;
2099 l_int32 sbyte0, sbyte1, sbyte2, sbyte3, sbyte4, sbyte5, sbyte6, sbyte7, sum;
2100 l_uint32 *lines, *lined;
2107 for (i = 0, k = 0; i < hd; i++, k += 8) {
2108 lines = datas + k * wpls;
2109 lined = datad + i * wpld;
2110 for (j = 0; j < wd; j++) {
2119 sum = tab8[sbyte0] + tab8[sbyte1] +
2120 tab8[sbyte2] + tab8[sbyte3] +
2121 tab8[sbyte4] + tab8[sbyte5] +
2122 tab8[sbyte6] + tab8[sbyte7];
2145 PROCNAME(
"makeValTabSG8");
2147 if ((tab = (l_uint8 *)LEPT_CALLOC(65,
sizeof(l_uint8))) == NULL)
2148 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
2149 for (i = 0; i < 65; i++)
2150 tab[i] = 0xff - (i * 255) / 64;
2188 l_uint32 *lines, *lined;
2196 for (i = 0, k = 0; i < hd; i++, k += 16) {
2197 lines = datas + k * wpls;
2198 lined = datad + i * wpld;
2199 for (j = 0; j < wd; j++) {
2233 sum = L_MIN(sum, 255);
2264 l_int32 i, j, val1, val2, val, row2, col2;
2265 l_int32 *srow, *scol;
2266 l_uint32 *lines1, *lines2, *lined;
2267 l_float32 ratio, w1, w2;
2269 PROCNAME(
"scaleMipmapLow");
2272 memset(datad, 0, 4LL * wpld * hd);
2282 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
2283 return ERROR_INT(
"srow not made", procName, 1);
2284 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
2286 return ERROR_INT(
"scol not made", procName, 1);
2288 ratio = 1. / (2. * red);
2289 for (i = 0; i < hd; i++)
2290 srow[i] = (l_int32)(ratio * i);
2291 for (j = 0; j < wd; j++)
2292 scol[j] = (l_int32)(ratio * j);
2301 for (i = 0; i < hd; i++) {
2303 lines1 = datas1 + 2 * row2 * wpls1;
2304 lines2 = datas2 + row2 * wpls2;
2305 lined = datad + i * wpld;
2306 for (j = 0; j < wd; j++) {
2310 val = (l_int32)(w1 * val1 + w2 * val2);
l_ok pixCopyRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixCopyRGBComponent()
PIX * pixScaleWithAlpha(PIX *pixs, l_float32 scalex, l_float32 scaley, PIX *pixg, l_float32 fract)
pixScaleWithAlpha()
static l_uint8 * makeValTabSG2(void)
makeValTabSG2()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
PIX * pixScaleToGray(PIX *pixs, l_float32 scalefactor)
pixScaleToGray()
static l_uint32 * makeSumTabSG4(void)
makeSumTabSG4()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
PIX * pixScaleGrayRankCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixScaleGrayRankCascade()
PIX * pixScaleGrayMinMax(PIX *pixs, l_int32 xfact, l_int32 yfact, l_int32 type)
pixScaleGrayMinMax()
PIX * pixScaleGrayRank2(PIX *pixs, l_int32 rank)
pixScaleGrayRank2()
static l_uint8 * makeValTabSG6(void)
makeValTabSG6()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
static l_uint32 * makeSumTabSG2(void)
makeSumTabSG2()
PIX * pixScaleGeneral(PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 sharpfract, l_int32 sharpwidth)
pixScaleGeneral()
l_ok pixSetAll(PIX *pix)
pixSetAll()
PIX * pixScaleToGray6(PIX *pixs)
pixScaleToGray6()
#define SET_DATA_QBIT(pdata, n, val)
l_uint32 * pixGetData(PIX *pix)
pixGetData()
PIX * pixScaleToGray3(PIX *pixs)
pixScaleToGray3()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
#define SET_DATA_DIBIT(pdata, n, val)
PIX * pixScaleToGray8(PIX *pixs)
pixScaleToGray8()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
PIX * pixScaleBinary(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBinary()
static void scaleToGray16Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab8)
scaleToGray16Low()
static void scaleToGray3Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *sumtab, l_uint8 *valtab)
scaleToGray3Low()
PIX * pixScaleToGrayFast(PIX *pixs, l_float32 scalefactor)
pixScaleToGrayFast()
l_ok pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
#define SET_DATA_BYTE(pdata, n, val)
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_BYTE(pdata, n)
PIX * pixClone(PIX *pixs)
pixClone()
static l_uint32 * makeSumTabSG3(void)
makeSumTabSG3()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
static void scaleToGray4Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *sumtab, l_uint8 *valtab)
scaleToGray4Low()
static void scaleToGray6Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab8, l_uint8 *valtab)
scaleToGray6Low()
PIX * pixScaleGrayLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleGrayLI()
static l_uint8 * makeValTabSG3(void)
makeValTabSG3()
PIX * pixExpandReplicate(PIX *pixs, l_int32 factor)
pixExpandReplicate()
PIX * pixScaleMipmap(PIX *pixs1, PIX *pixs2, l_float32 scale)
pixScaleMipmap()
#define GET_DATA_TWO_BYTES(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
static void scaleToGray2Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_uint32 *sumtab, l_uint8 *valtab)
scaleToGray2Low()
PIX * pixScaleGrayMinMax2(PIX *pixs, l_int32 type)
pixScaleGrayMinMax2()
PIX * pixScaleToGray4(PIX *pixs)
pixScaleToGray4()
PIX * pixScaleToGray16(PIX *pixs)
pixScaleToGray16()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
static void scaleToGray8Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_int32 *tab8, l_uint8 *valtab)
scaleToGray8Low()
PIX * pixResizeToMatch(PIX *pixs, PIX *pixt, l_int32 w, l_int32 h)
pixResizeToMatch()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
static l_uint8 * makeValTabSG8(void)
makeValTabSG8()
static l_uint8 * makeValTabSG4(void)
makeValTabSG4()
PIX * pixScaleSmooth(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleSmooth()
l_ok pixScaleAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleAndTransferAlpha()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
#define SET_DATA_TWO_BYTES(pdata, n, val)
PIX * pixExpandBinaryReplicate(PIX *pixs, l_int32 xfact, l_int32 yfact)
pixExpandBinaryReplicate()
PIX * pixScaleToGrayMipmap(PIX *pixs, l_float32 scalefactor)
pixScaleToGrayMipmap()
PIX * pixScaleToGray2(PIX *pixs)
pixScaleToGray2()
static l_int32 scaleMipmapLow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas1, l_int32 wpls1, l_uint32 *datas2, l_int32 wpls2, l_float32 red)
scaleMipmapLow()