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)
1209 PIX *pixt1, *pixt2, *pixt3, *pixt4;
1211 PROCNAME(
"pixScaleGrayRankCascade");
1213 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1214 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1216 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
1217 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", procName, NULL);
1220 L_WARNING(
"no reduction because level1 not > 0\n", procName);
1270 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1271 l_int32 minval, maxval, rankval, minindex, maxindex;
1274 l_uint32 *datas, *datad, *lines, *lined;
1277 PROCNAME(
"pixScaleGrayRank2");
1279 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1280 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1282 if (rank < 1 || rank > 4)
1283 return (
PIX *)ERROR_PTR(
"invalid rank", procName, NULL);
1293 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1294 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1295 pixCopyInputFormat(pixd, pixs);
1298 wpls = pixGetWpl(pixs);
1299 wpld = pixGetWpl(pixd);
1300 for (i = 0; i < hd; i++) {
1301 lines = datas + 2 * i * wpls;
1302 lined = datad + i * wpld;
1303 for (j = 0; j < wd; j++) {
1308 minval = maxval = val[0];
1309 minindex = maxindex = 0;
1310 for (k = 1; k < 4; k++) {
1311 if (val[k] < minval) {
1316 if (val[k] > maxval) {
1321 for (k = 0, m = 0; k < 4; k++) {
1322 if (k == minindex || k == maxindex)
1324 midval[m++] = val[k];
1329 rankval = L_MIN(midval[0], midval[1]);
1331 rankval = L_MAX(midval[0], midval[1]);
1364 PROCNAME(
"pixScaleAndTransferAlpha");
1367 return ERROR_INT(
"pixs and pixd not both defined", procName, 1);
1368 if (pixGetDepth(pixs) != 32 || pixGetSpp(pixs) != 4)
1369 return ERROR_INT(
"pixs not 32 bpp and 4 spp", procName, 1);
1370 if (pixGetDepth(pixd) != 32)
1371 return ERROR_INT(
"pixd not 32 bpp", procName, 1);
1373 if (scalex == 1.0 && scaley == 1.0) {
1379 pix2 =
pixScale(pix1, scalex, scaley);
1441 l_int32 ws, hs, d, spp;
1442 PIX *pixd, *pix32, *pixg2, *pixgs;
1444 PROCNAME(
"pixScaleWithAlpha");
1447 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1449 if (d != 32 && !pixGetColormap(pixs))
1450 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", procName, NULL);
1451 if (scalex <= 0.0 || scaley <= 0.0)
1452 return (
PIX *)ERROR_PTR(
"scale factor <= 0.0", procName, NULL);
1453 if (pixg && pixGetDepth(pixg) != 8) {
1454 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
1458 if (!pixg && (fract < 0.0 || fract > 1.0)) {
1459 L_WARNING(
"invalid fract; using fully opaque\n", procName);
1462 if (!pixg && fract == 0.0)
1463 L_WARNING(
"transparent alpha; image will not be blended\n", procName);
1470 spp = pixGetSpp(pix32);
1471 pixSetSpp(pix32, 3);
1472 pixd =
pixScale(pix32, scalex, scaley);
1473 pixSetSpp(pix32, spp);
1481 else if (fract > 0.0)
1486 if (ws > 10 && hs > 10) {
1488 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
1490 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
1496 pixCopyInputFormat(pixd, pixs);
1543 l_int32 i, j, l, k, m, wd4, extra;
1544 l_uint32 sbyte1, sbyte2, sum;
1545 l_uint32 *lines, *lined;
1553 wd4 = wd & 0xfffffffc;
1555 for (i = 0, l = 0; i < hd; i++, l += 2) {
1556 lines = datas + l * wpls;
1557 lined = datad + i * wpld;
1558 for (j = 0, k = 0; j < wd4; j += 4, k++) {
1561 sum = sumtab[sbyte1] + sumtab[sbyte2];
1570 sum = sumtab[sbyte1] + sumtab[sbyte2];
1571 for (m = 0; m < extra; m++) {
1573 valtab[((sum >> (24 - 8 * m)) & 0xff)]);
1596 l_int32 sum[] = {0, 1, 1, 2};
1599 PROCNAME(
"makeSumTabSG2");
1601 if ((tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32))) == NULL)
1602 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1605 for (i = 0; i < 256; i++) {
1606 tab[i] = (sum[i & 0x3] | sum[(i >> 2) & 0x3] << 8 |
1607 sum[(i >> 4) & 0x3] << 16 | sum[(i >> 6) & 0x3] << 24);
1629 PROCNAME(
"makeValTabSG2");
1631 if ((tab = (l_uint8 *)LEPT_CALLOC(5,
sizeof(l_uint8))) == NULL)
1632 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1633 for (i = 0; i < 5; i++)
1634 tab[i] = 255 - (i * 255) / 4;
1688 l_uint32 threebytes1, threebytes2, threebytes3, sum;
1689 l_uint32 *lines, *lined;
1698 for (i = 0, l = 0; i < hd; i++, l += 3) {
1699 lines = datas + l * wpls;
1700 lined = datad + i * wpld;
1701 for (j = 0, k = 0; j < wd; j += 8, k += 3) {
1712 sum = sumtab[(threebytes1 >> 18)] +
1713 sumtab[(threebytes2 >> 18)] +
1714 sumtab[(threebytes3 >> 18)];
1718 sum = sumtab[((threebytes1 >> 12) & 0x3f)] +
1719 sumtab[((threebytes2 >> 12) & 0x3f)] +
1720 sumtab[((threebytes3 >> 12) & 0x3f)];
1724 sum = sumtab[((threebytes1 >> 6) & 0x3f)] +
1725 sumtab[((threebytes2 >> 6) & 0x3f)] +
1726 sumtab[((threebytes3 >> 6) & 0x3f)];
1730 sum = sumtab[(threebytes1 & 0x3f)] +
1731 sumtab[(threebytes2 & 0x3f)] +
1732 sumtab[(threebytes3 & 0x3f)];
1757 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3};
1760 PROCNAME(
"makeSumTabSG3");
1762 if ((tab = (l_uint32 *)LEPT_CALLOC(64,
sizeof(l_uint32))) == NULL)
1763 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1766 for (i = 0; i < 64; i++) {
1767 tab[i] = (sum[i & 0x07]) | (sum[(i >> 3) & 0x07] << 8);
1787 PROCNAME(
"makeValTabSG3");
1789 if ((tab = (l_uint8 *)LEPT_CALLOC(10,
sizeof(l_uint8))) == NULL)
1790 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1791 for (i = 0; i < 10; i++)
1792 tab[i] = 0xff - (i * 255) / 9;
1833 l_uint32 sbyte1, sbyte2, sbyte3, sbyte4, sum;
1834 l_uint32 *lines, *lined;
1842 for (i = 0, l = 0; i < hd; i++, l += 4) {
1843 lines = datas + l * wpls;
1844 lined = datad + i * wpld;
1845 for (j = 0, k = 0; j < wd; j += 2, k++) {
1850 sum = sumtab[sbyte1] + sumtab[sbyte2] +
1851 sumtab[sbyte3] + sumtab[sbyte4];
1874 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
1877 PROCNAME(
"makeSumTabSG4");
1879 if ((tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32))) == NULL)
1880 return (l_uint32 *)ERROR_PTR(
"tab not made", procName, NULL);
1883 for (i = 0; i < 256; i++) {
1884 tab[i] = (sum[i & 0xf]) | (sum[(i >> 4) & 0xf] << 8);
1906 PROCNAME(
"makeValTabSG4");
1908 if ((tab = (l_uint8 *)LEPT_CALLOC(17,
sizeof(l_uint8))) == NULL)
1909 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
1910 for (i = 0; i < 17; i++)
1911 tab[i] = 0xff - (i * 255) / 16;
1965 l_uint32 threebytes1, threebytes2, threebytes3;
1966 l_uint32 threebytes4, threebytes5, threebytes6, sum;
1967 l_uint32 *lines, *lined;
1976 for (i = 0, l = 0; i < hd; i++, l += 6) {
1977 lines = datas + l * wpls;
1978 lined = datad + i * wpld;
1979 for (j = 0, k = 0; j < wd; j += 4, k += 3) {
2002 sum = tab8[(threebytes1 >> 18)] +
2003 tab8[(threebytes2 >> 18)] +
2004 tab8[(threebytes3 >> 18)] +
2005 tab8[(threebytes4 >> 18)] +
2006 tab8[(threebytes5 >> 18)] +
2007 tab8[(threebytes6 >> 18)];
2011 sum = tab8[((threebytes1 >> 12) & 0x3f)] +
2012 tab8[((threebytes2 >> 12) & 0x3f)] +
2013 tab8[((threebytes3 >> 12) & 0x3f)] +
2014 tab8[((threebytes4 >> 12) & 0x3f)] +
2015 tab8[((threebytes5 >> 12) & 0x3f)] +
2016 tab8[((threebytes6 >> 12) & 0x3f)];
2019 sum = tab8[((threebytes1 >> 6) & 0x3f)] +
2020 tab8[((threebytes2 >> 6) & 0x3f)] +
2021 tab8[((threebytes3 >> 6) & 0x3f)] +
2022 tab8[((threebytes4 >> 6) & 0x3f)] +
2023 tab8[((threebytes5 >> 6) & 0x3f)] +
2024 tab8[((threebytes6 >> 6) & 0x3f)];
2027 sum = tab8[(threebytes1 & 0x3f)] +
2028 tab8[(threebytes2 & 0x3f)] +
2029 tab8[(threebytes3 & 0x3f)] +
2030 tab8[(threebytes4 & 0x3f)] +
2031 tab8[(threebytes5 & 0x3f)] +
2032 tab8[(threebytes6 & 0x3f)];
2054 PROCNAME(
"makeValTabSG6");
2056 if ((tab = (l_uint8 *)LEPT_CALLOC(37,
sizeof(l_uint8))) == NULL)
2057 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
2058 for (i = 0; i < 37; i++)
2059 tab[i] = 0xff - (i * 255) / 36;
2098 l_int32 sbyte0, sbyte1, sbyte2, sbyte3, sbyte4, sbyte5, sbyte6, sbyte7, sum;
2099 l_uint32 *lines, *lined;
2106 for (i = 0, k = 0; i < hd; i++, k += 8) {
2107 lines = datas + k * wpls;
2108 lined = datad + i * wpld;
2109 for (j = 0; j < wd; j++) {
2118 sum = tab8[sbyte0] + tab8[sbyte1] +
2119 tab8[sbyte2] + tab8[sbyte3] +
2120 tab8[sbyte4] + tab8[sbyte5] +
2121 tab8[sbyte6] + tab8[sbyte7];
2144 PROCNAME(
"makeValTabSG8");
2146 if ((tab = (l_uint8 *)LEPT_CALLOC(65,
sizeof(l_uint8))) == NULL)
2147 return (l_uint8 *)ERROR_PTR(
"tab not made", procName, NULL);
2148 for (i = 0; i < 65; i++)
2149 tab[i] = 0xff - (i * 255) / 64;
2187 l_uint32 *lines, *lined;
2195 for (i = 0, k = 0; i < hd; i++, k += 16) {
2196 lines = datas + k * wpls;
2197 lined = datad + i * wpld;
2198 for (j = 0; j < wd; j++) {
2232 sum = L_MIN(sum, 255);
2263 l_int32 i, j, val1, val2, val, row2, col2;
2264 l_int32 *srow, *scol;
2265 l_uint32 *lines1, *lines2, *lined;
2266 l_float32 ratio, w1, w2;
2268 PROCNAME(
"scaleMipmapLow");
2271 memset((
char *)datad, 0, 4 * wpld * hd);
2281 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
2282 return ERROR_INT(
"srow not made", procName, 1);
2283 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
2285 return ERROR_INT(
"scol not made", procName, 1);
2287 ratio = 1. / (2. * red);
2288 for (i = 0; i < hd; i++)
2289 srow[i] = (l_int32)(ratio * i);
2290 for (j = 0; j < wd; j++)
2291 scol[j] = (l_int32)(ratio * j);
2300 for (i = 0; i < hd; i++) {
2302 lines1 = datas1 + 2 * row2 * wpls1;
2303 lines2 = datas2 + row2 * wpls2;
2304 lined = datad + i * wpld;
2305 for (j = 0; j < wd; j++) {
2309 val = (l_int32)(w1 * val1 + w2 * val2);
PIX * pixScaleWithAlpha(PIX *pixs, l_float32 scalex, l_float32 scaley, PIX *pixg, l_float32 fract)
pixScaleWithAlpha()
static l_uint8 * makeValTabSG2(void)
makeValTabSG2()
l_int32 pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
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()
l_int32 pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
PIX * pixScaleGrayRank2(PIX *pixs, l_int32 rank)
pixScaleGrayRank2()
l_int32 pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
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()
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()
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_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_int32 pixCopyRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixCopyRGBComponent()
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()
l_int32 pixScaleAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleAndTransferAlpha()
l_int32 pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
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()
l_int32 pixSetAll(PIX *pix)
pixSetAll()
l_int32 pixGetDimensions(PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
static l_uint8 * makeValTabSG8(void)
makeValTabSG8()
static l_uint8 * makeValTabSG4(void)
makeValTabSG4()
PIX * pixScaleSmooth(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleSmooth()
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()