99 #include <config_auto.h>
103 #include "allheaders.h"
106 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
107 l_uint32 *sumtab, l_uint8 *valtab);
111 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
112 l_uint32 *sumtab, l_uint8 *valtab);
116 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
117 l_uint32 *sumtab, 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,
126 l_int32 *tab8, l_uint8 *valtab);
129 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
131 static l_int32
scaleMipmapLow(l_uint32 *datad, l_int32 wd, l_int32 hd,
132 l_int32 wpld, l_uint32 *datas1, l_int32 wpls1,
133 l_uint32 *datas2, l_int32 wpls2, l_float32 red);
135 extern l_float32 AlphaMaskBorderVals[2];
209 l_float32 scalefactor)
211 l_int32 w, h, minsrc, mindest;
216 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
217 if (pixGetDepth(pixs) != 1)
218 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
219 if (scalefactor <= 0.0)
220 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", __func__, NULL);
221 if (scalefactor >= 1.0)
222 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", __func__, NULL);
224 minsrc = L_MIN(w, h);
225 mindest = (l_int32)((l_float32)minsrc * scalefactor);
227 return (
PIX *)ERROR_PTR(
"scalefactor too small", __func__, NULL);
229 if (scalefactor > 0.5) {
230 mag = 2.0 * scalefactor;
233 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
235 }
else if (scalefactor == 0.5) {
237 }
else if (scalefactor > 0.33333) {
238 mag = 3.0 * scalefactor;
241 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
243 }
else if (scalefactor > 0.25) {
244 mag = 4.0 * scalefactor;
247 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
249 }
else if (scalefactor == 0.25) {
251 }
else if (scalefactor > 0.16667) {
252 mag = 6.0 * scalefactor;
255 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
257 }
else if (scalefactor == 0.16667) {
259 }
else if (scalefactor > 0.125) {
260 mag = 8.0 * scalefactor;
263 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
265 }
else if (scalefactor == 0.125) {
267 }
else if (scalefactor > 0.0625) {
268 red = 8.0 * scalefactor;
271 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
273 }
else if (scalefactor == 0.0625) {
276 red = 16.0 * scalefactor;
279 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
288 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
289 pixCopyInputFormat(pixd, pixs);
318 l_float32 scalefactor)
320 l_int32 w, h, minsrc, mindest;
321 l_float32 eps, factor;
325 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
326 if (pixGetDepth(pixs) != 1)
327 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
328 if (scalefactor <= 0.0)
329 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", __func__, NULL);
330 if (scalefactor >= 1.0)
331 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", __func__, NULL);
333 minsrc = L_MIN(w, h);
334 mindest = (l_int32)((l_float32)minsrc * scalefactor);
336 return (
PIX *)ERROR_PTR(
"scalefactor too small", __func__, 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", __func__, NULL);
359 factor = 16.0 * scalefactor;
361 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
369 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
370 pixCopyInputFormat(pixd, pixs);
389 l_int32 ws, hs, wd, hd;
392 l_uint32 *datas, *datad;
396 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
397 if (pixGetDepth(pixs) != 1)
398 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", __func__, NULL);
403 if (wd == 0 || hd == 0)
404 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
406 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
407 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
409 pixCopyInputFormat(pixd, pixs);
410 pixCopyResolution(pixd, pixs);
411 pixScaleResolution(pixd, 0.5, 0.5);
414 wpls = pixGetWpl(pixs);
415 wpld = pixGetWpl(pixd);
445 l_int32 ws, hs, wd, hd;
448 l_uint32 *datas, *datad;
452 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
453 if (pixGetDepth(pixs) != 1)
454 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
457 wd = (ws / 3) & 0xfffffff8;
459 if (wd == 0 || hd == 0)
460 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
462 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
463 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
464 pixCopyInputFormat(pixd, pixs);
465 pixCopyResolution(pixd, pixs);
466 pixScaleResolution(pixd, 0.33333, 0.33333);
469 wpls = pixGetWpl(pixs);
470 wpld = pixGetWpl(pixd);
497 l_int32 ws, hs, wd, hd;
500 l_uint32 *datas, *datad;
504 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
505 if (pixGetDepth(pixs) != 1)
506 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", __func__, NULL);
509 wd = (ws / 4) & 0xfffffffe;
511 if (wd == 0 || hd == 0)
512 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
514 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
515 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
516 pixCopyInputFormat(pixd, pixs);
517 pixCopyResolution(pixd, pixs);
518 pixScaleResolution(pixd, 0.25, 0.25);
521 wpls = pixGetWpl(pixs);
522 wpld = pixGetWpl(pixd);
550 l_int32 ws, hs, wd, hd, wpld, wpls;
552 l_uint32 *datas, *datad;
556 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
557 if (pixGetDepth(pixs) != 1)
558 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
561 wd = (ws / 6) & 0xfffffff8;
563 if (wd == 0 || hd == 0)
564 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
566 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
567 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
568 pixCopyInputFormat(pixd, pixs);
569 pixCopyResolution(pixd, pixs);
570 pixScaleResolution(pixd, 0.16667, 0.16667);
573 wpls = pixGetWpl(pixs);
574 wpld = pixGetWpl(pixd);
596 l_int32 ws, hs, wd, hd;
599 l_uint32 *datas, *datad;
603 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
604 if (pixGetDepth(pixs) != 1)
605 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", __func__, NULL);
610 if (wd == 0 || hd == 0)
611 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
613 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
614 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
615 pixCopyInputFormat(pixd, pixs);
616 pixCopyResolution(pixd, pixs);
617 pixScaleResolution(pixd, 0.125, 0.125);
620 wpls = pixGetWpl(pixs);
621 wpld = pixGetWpl(pixd);
642 l_int32 ws, hs, wd, hd;
645 l_uint32 *datas, *datad;
649 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
650 if (pixGetDepth(pixs) != 1)
651 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", __func__, NULL);
656 if (wd == 0 || hd == 0)
657 return (
PIX *)ERROR_PTR(
"pixs too small", __func__, NULL);
659 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
660 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
661 pixCopyInputFormat(pixd, pixs);
662 pixCopyResolution(pixd, pixs);
663 pixScaleResolution(pixd, 0.0625, 0.0625);
666 wpls = pixGetWpl(pixs);
667 wpld = pixGetWpl(pixd);
712 l_float32 scalefactor)
714 l_int32 w, h, minsrc, mindest;
716 PIX *pixs1, *pixs2, *pixt, *pixd;
719 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
720 if (pixGetDepth(pixs) != 1)
721 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", __func__, NULL);
722 if (scalefactor <= 0.0)
723 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", __func__, NULL);
724 if (scalefactor >= 1.0)
725 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", __func__, NULL);
727 minsrc = L_MIN(w, h);
728 mindest = (l_int32)((l_float32)minsrc * scalefactor);
730 return (
PIX *)ERROR_PTR(
"scalefactor too small", __func__, NULL);
732 if (scalefactor > 0.5) {
736 }
else if (scalefactor == 0.5) {
738 }
else if (scalefactor > 0.25) {
741 red = 2. * scalefactor;
742 }
else if (scalefactor == 0.25) {
744 }
else if (scalefactor > 0.125) {
747 red = 4. * scalefactor;
748 }
else if (scalefactor == 0.125) {
750 }
else if (scalefactor > 0.0625) {
753 red = 8. * scalefactor;
754 }
else if (scalefactor == 0.0625) {
757 red = 16.0 * scalefactor;
759 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
769 pixCopyInputFormat(pixd, pixs);
801 l_int32 ws1, hs1, ws2, hs2, wd, hd, wpls1, wpls2, wpld;
802 l_uint32 *datas1, *datas2, *datad;
805 if (!pixs1 || pixGetDepth(pixs1) != 8 || pixGetColormap(pixs1))
806 return (
PIX *)ERROR_PTR(
"pixs1 underdefined, not 8 bpp, or cmapped",
808 if (!pixs2 || pixGetDepth(pixs2) != 8 || pixGetColormap(pixs2))
809 return (
PIX *)ERROR_PTR(
"pixs2 underdefined, not 8 bpp, or cmapped",
813 if (scale > 1.0 || scale < 0.5)
814 return (
PIX *)ERROR_PTR(
"scale not in [0.5, 1.0]", __func__, NULL);
816 return (
PIX *)ERROR_PTR(
"invalid width ratio", __func__, NULL);
818 return (
PIX *)ERROR_PTR(
"invalid height ratio", __func__, NULL);
823 wpls1 = pixGetWpl(pixs1);
825 wpls2 = pixGetWpl(pixs2);
826 wd = (l_int32)(2. * scale * pixGetWidth(pixs2));
827 hd = (l_int32)(2. * scale * pixGetHeight(pixs2));
828 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
829 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
830 pixCopyInputFormat(pixd, pixs1);
831 pixCopyResolution(pixd, pixs1);
832 pixScaleResolution(pixd, scale, scale);
834 wpld = pixGetWpl(pixd);
836 scaleMipmapLow(datad, wd, hd, wpld, datas1, wpls1, datas2, wpls2, scale);
855 l_int32 w, h, d, wd, hd, wpls, wpld, start, i, j, k;
859 l_uint32 *lines, *datas, *lined, *datad;
863 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
865 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
866 return (
PIX *)ERROR_PTR(
"depth not in {1,2,4,8,16,32}", __func__, NULL);
868 return (
PIX *)ERROR_PTR(
"factor <= 0; invalid", __func__, NULL);
877 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
878 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
880 pixCopyInputFormat(pixd, pixs);
881 pixCopyResolution(pixd, pixs);
882 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
884 wpls = pixGetWpl(pixs);
886 wpld = pixGetWpl(pixd);
890 for (i = 0; i < h; i++) {
891 lines = datas + i * wpls;
892 lined = datad + factor * i * wpld;
893 for (j = 0; j < w; j++) {
896 for (k = 0; k < factor; k++)
899 for (k = 1; k < factor; k++)
900 memcpy(lined + k * wpld, lined, 4 * wpld);
904 for (i = 0; i < h; i++) {
905 lines = datas + i * wpls;
906 lined = datad + factor * i * wpld;
907 for (j = 0; j < w; j++) {
910 for (k = 0; k < factor; k++)
913 for (k = 1; k < factor; k++)
914 memcpy(lined + k * wpld, lined, 4 * wpld);
918 for (i = 0; i < h; i++) {
919 lines = datas + i * wpls;
920 lined = datad + factor * i * wpld;
921 for (j = 0; j < w; j++) {
924 for (k = 0; k < factor; k++)
927 for (k = 1; k < factor; k++)
928 memcpy(lined + k * wpld, lined, 4 * wpld);
932 for (i = 0; i < h; i++) {
933 lines = datas + i * wpls;
934 lined = datad + factor * i * wpld;
935 for (j = 0; j < w; j++) {
938 for (k = 0; k < factor; k++)
941 for (k = 1; k < factor; k++)
942 memcpy(lined + k * wpld, lined, 4 * wpld);
946 for (i = 0; i < h; i++) {
947 lines = datas + i * wpls;
948 lined = datad + factor * i * wpld;
949 for (j = 0; j < w; j++) {
950 sval32 = *(lines + j);
952 for (k = 0; k < factor; k++)
953 *(lined + start + k) = sval32;
955 for (k = 1; k < factor; k++)
956 memcpy(lined + k * wpld, lined, 4 * wpld);
963 if (d == 32 && pixGetSpp(pixs) == 4)
1002 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1003 l_int32 minval, maxval, val;
1004 l_uint32 *datas, *datad, *lines, *lined;
1007 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1008 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1011 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1012 type != L_CHOOSE_MAXDIFF)
1013 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1014 if (xfact < 1 || yfact < 1)
1015 return (
PIX *)ERROR_PTR(
"xfact and yfact must be >= 1", __func__, NULL);
1017 if (xfact == 2 && yfact == 2)
1030 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1031 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1032 pixCopyInputFormat(pixd, pixs);
1035 wpls = pixGetWpl(pixs);
1036 wpld = pixGetWpl(pixd);
1037 for (i = 0; i < hd; i++) {
1038 lined = datad + i * wpld;
1039 for (j = 0; j < wd; j++) {
1040 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1042 for (k = 0; k < yfact; k++) {
1043 lines = datas + (yfact * i + k) * wpls;
1044 for (m = 0; m < xfact; m++) {
1051 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1053 for (k = 0; k < yfact; k++) {
1054 lines = datas + (yfact * i + k) * wpls;
1055 for (m = 0; m < xfact; m++) {
1062 if (type == L_CHOOSE_MIN)
1064 else if (type == L_CHOOSE_MAX)
1105 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k;
1106 l_int32 minval, maxval;
1108 l_uint32 *datas, *datad, *lines, *lined;
1111 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1112 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1115 if (ws < 2 || hs < 2)
1116 return (
PIX *)ERROR_PTR(
"too small: ws < 2 or hs < 2", __func__, NULL);
1117 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1118 type != L_CHOOSE_MAXDIFF)
1119 return (
PIX *)ERROR_PTR(
"invalid type", __func__, NULL);
1123 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1124 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1125 pixCopyInputFormat(pixd, pixs);
1128 wpls = pixGetWpl(pixs);
1129 wpld = pixGetWpl(pixd);
1130 for (i = 0; i < hd; i++) {
1131 lines = datas + 2 * i * wpls;
1132 lined = datad + i * wpld;
1133 for (j = 0; j < wd; j++) {
1138 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1140 for (k = 0; k < 4; k++) {
1141 if (val[k] < minval)
1145 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1147 for (k = 0; k < 4; k++) {
1148 if (val[k] > maxval)
1152 if (type == L_CHOOSE_MIN)
1154 else if (type == L_CHOOSE_MAX)
1189 PIX *pixt1, *pixt2, *pixt3, *pixt4;
1191 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1192 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1194 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
1195 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", __func__, NULL);
1198 L_WARNING(
"no reduction because level1 not > 0\n", __func__);
1248 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1249 l_int32 minval, maxval, rankval, minindex, maxindex;
1252 l_uint32 *datas, *datad, *lines, *lined;
1255 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1256 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1258 if (rank < 1 || rank > 4)
1259 return (
PIX *)ERROR_PTR(
"invalid rank", __func__, NULL);
1269 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1270 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1271 pixCopyInputFormat(pixd, pixs);
1274 wpls = pixGetWpl(pixs);
1275 wpld = pixGetWpl(pixd);
1276 for (i = 0; i < hd; i++) {
1277 lines = datas + 2 * i * wpls;
1278 lined = datad + i * wpld;
1279 for (j = 0; j < wd; j++) {
1284 minval = maxval = val[0];
1285 minindex = maxindex = 0;
1286 for (k = 1; k < 4; k++) {
1287 if (val[k] < minval) {
1292 if (val[k] > maxval) {
1297 for (k = 0, m = 0; k < 4; k++) {
1298 if (k == minindex || k == maxindex)
1300 midval[m++] = val[k];
1305 rankval = L_MIN(midval[0], midval[1]);
1307 rankval = L_MAX(midval[0], midval[1]);
1342 return ERROR_INT(
"pixs and pixd not both defined", __func__, 1);
1343 if (pixGetDepth(pixs) != 32 || pixGetSpp(pixs) != 4)
1344 return ERROR_INT(
"pixs not 32 bpp and 4 spp", __func__, 1);
1345 if (pixGetDepth(pixd) != 32)
1346 return ERROR_INT(
"pixd not 32 bpp", __func__, 1);
1348 if (scalex == 1.0 && scaley == 1.0) {
1354 pix2 =
pixScale(pix1, scalex, scaley);
1417 l_int32 ws, hs, d, spp;
1418 PIX *pixd, *pix32, *pixg2, *pixgs;
1421 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1423 if (d != 32 && !pixGetColormap(pixs))
1424 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", __func__, NULL);
1425 if (scalex <= 0.0 || scaley <= 0.0)
1426 return (
PIX *)ERROR_PTR(
"scale factor <= 0.0", __func__, NULL);
1427 if (pixg && pixGetDepth(pixg) != 8) {
1428 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
1432 if (!pixg && (fract < 0.0 || fract > 1.0)) {
1433 L_WARNING(
"invalid fract; using fully opaque\n", __func__);
1436 if (!pixg && fract == 0.0)
1437 L_WARNING(
"transparent alpha; image will not be blended\n", __func__);
1444 spp = pixGetSpp(pix32);
1445 pixSetSpp(pix32, 3);
1446 pixd =
pixScale(pix32, scalex, scaley);
1447 pixSetSpp(pix32, spp);
1455 else if (fract > 0.0)
1460 if (ws > 10 && hs > 10) {
1462 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
1464 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
1470 pixCopyInputFormat(pixd, pixs);
1520 l_int32 i, j, l, k, m, wd4, extra;
1521 l_uint32 sbyte1, sbyte2, sum;
1522 l_uint32 *lines, *lined;
1530 wd4 = wd & 0xfffffffc;
1532 for (i = 0, l = 0; i < hd; i++, l += 2) {
1533 lines = datas + l * wpls;
1534 lined = datad + i * wpld;
1535 for (j = 0, k = 0; j < wd4; j += 4, k++) {
1538 sum = sumtab[sbyte1] + sumtab[sbyte2];
1547 sum = sumtab[sbyte1] + sumtab[sbyte2];
1548 for (m = 0; m < extra; m++) {
1550 valtab[((sum >> (24 - 8 * m)) & 0xff)]);
1574 l_int32 sum[] = {0, 1, 1, 2};
1578 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1579 for (i = 0; i < 256; i++) {
1580 tab[i] = (sum[i & 0x3] | sum[(i >> 2) & 0x3] << 8 |
1581 sum[(i >> 4) & 0x3] << 16 | sum[(i >> 6) & 0x3] << 24);
1604 tab = (l_uint8 *)LEPT_CALLOC(5,
sizeof(l_uint8));
1605 for (i = 0; i < 5; i++)
1606 tab[i] = 255 - (i * 255) / 4;
1659 l_uint32 threebytes1, threebytes2, threebytes3, sum;
1660 l_uint32 *lines, *lined;
1669 for (i = 0, l = 0; i < hd; i++, l += 3) {
1670 lines = datas + l * wpls;
1671 lined = datad + i * wpld;
1672 for (j = 0, k = 0; j < wd; j += 8, k += 3) {
1683 sum = sumtab[(threebytes1 >> 18)] +
1684 sumtab[(threebytes2 >> 18)] +
1685 sumtab[(threebytes3 >> 18)];
1689 sum = sumtab[((threebytes1 >> 12) & 0x3f)] +
1690 sumtab[((threebytes2 >> 12) & 0x3f)] +
1691 sumtab[((threebytes3 >> 12) & 0x3f)];
1695 sum = sumtab[((threebytes1 >> 6) & 0x3f)] +
1696 sumtab[((threebytes2 >> 6) & 0x3f)] +
1697 sumtab[((threebytes3 >> 6) & 0x3f)];
1701 sum = sumtab[(threebytes1 & 0x3f)] +
1702 sumtab[(threebytes2 & 0x3f)] +
1703 sumtab[(threebytes3 & 0x3f)];
1729 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3};
1733 tab = (l_uint32 *)LEPT_CALLOC(64,
sizeof(l_uint32));
1734 for (i = 0; i < 64; i++) {
1735 tab[i] = (sum[i & 0x07]) | (sum[(i >> 3) & 0x07] << 8);
1758 tab = (l_uint8 *)LEPT_CALLOC(10,
sizeof(l_uint8));
1759 for (i = 0; i < 10; i++)
1760 tab[i] = 0xff - (i * 255) / 9;
1804 l_uint32 sbyte1, sbyte2, sbyte3, sbyte4, sum;
1805 l_uint32 *lines, *lined;
1813 for (i = 0, l = 0; i < hd; i++, l += 4) {
1814 lines = datas + l * wpls;
1815 lined = datad + i * wpld;
1816 for (j = 0, k = 0; j < wd; j += 2, k++) {
1821 sum = sumtab[sbyte1] + sumtab[sbyte2] +
1822 sumtab[sbyte3] + sumtab[sbyte4];
1846 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
1850 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1851 for (i = 0; i < 256; i++) {
1852 tab[i] = (sum[i & 0xf]) | (sum[(i >> 4) & 0xf] << 8);
1875 tab = (l_uint8 *)LEPT_CALLOC(17,
sizeof(l_uint8));
1876 for (i = 0; i < 17; i++)
1877 tab[i] = 0xff - (i * 255) / 16;
1929 l_uint32 threebytes1, threebytes2, threebytes3;
1930 l_uint32 threebytes4, threebytes5, threebytes6, sum;
1931 l_uint32 *lines, *lined;
1940 for (i = 0, l = 0; i < hd; i++, l += 6) {
1941 lines = datas + l * wpls;
1942 lined = datad + i * wpld;
1943 for (j = 0, k = 0; j < wd; j += 4, k += 3) {
1966 sum = tab8[(threebytes1 >> 18)] +
1967 tab8[(threebytes2 >> 18)] +
1968 tab8[(threebytes3 >> 18)] +
1969 tab8[(threebytes4 >> 18)] +
1970 tab8[(threebytes5 >> 18)] +
1971 tab8[(threebytes6 >> 18)];
1975 sum = tab8[((threebytes1 >> 12) & 0x3f)] +
1976 tab8[((threebytes2 >> 12) & 0x3f)] +
1977 tab8[((threebytes3 >> 12) & 0x3f)] +
1978 tab8[((threebytes4 >> 12) & 0x3f)] +
1979 tab8[((threebytes5 >> 12) & 0x3f)] +
1980 tab8[((threebytes6 >> 12) & 0x3f)];
1983 sum = tab8[((threebytes1 >> 6) & 0x3f)] +
1984 tab8[((threebytes2 >> 6) & 0x3f)] +
1985 tab8[((threebytes3 >> 6) & 0x3f)] +
1986 tab8[((threebytes4 >> 6) & 0x3f)] +
1987 tab8[((threebytes5 >> 6) & 0x3f)] +
1988 tab8[((threebytes6 >> 6) & 0x3f)];
1991 sum = tab8[(threebytes1 & 0x3f)] +
1992 tab8[(threebytes2 & 0x3f)] +
1993 tab8[(threebytes3 & 0x3f)] +
1994 tab8[(threebytes4 & 0x3f)] +
1995 tab8[(threebytes5 & 0x3f)] +
1996 tab8[(threebytes6 & 0x3f)];
2020 tab = (l_uint8 *)LEPT_CALLOC(37,
sizeof(l_uint8));
2021 for (i = 0; i < 37; i++)
2022 tab[i] = 0xff - (i * 255) / 36;
2065 l_int32 sbyte0, sbyte1, sbyte2, sbyte3, sbyte4, sbyte5, sbyte6, sbyte7, sum;
2066 l_uint32 *lines, *lined;
2073 for (i = 0, k = 0; i < hd; i++, k += 8) {
2074 lines = datas + k * wpls;
2075 lined = datad + i * wpld;
2076 for (j = 0; j < wd; j++) {
2085 sum = tab8[sbyte0] + tab8[sbyte1] +
2086 tab8[sbyte2] + tab8[sbyte3] +
2087 tab8[sbyte4] + tab8[sbyte5] +
2088 tab8[sbyte6] + tab8[sbyte7];
2112 tab = (l_uint8 *)LEPT_CALLOC(65,
sizeof(l_uint8));
2113 for (i = 0; i < 65; i++)
2114 tab[i] = 0xff - (i * 255) / 64;
2155 l_uint32 *lines, *lined;
2163 for (i = 0, k = 0; i < hd; i++, k += 16) {
2164 lines = datas + k * wpls;
2165 lined = datad + i * wpld;
2166 for (j = 0; j < wd; j++) {
2200 sum = L_MIN(sum, 255);
2232 l_int32 i, j, val1, val2, val, row2, col2;
2233 l_int32 *srow, *scol;
2234 l_uint32 *lines1, *lines2, *lined;
2235 l_float32 ratio, w1, w2;
2238 memset(datad, 0, 4LL * wpld * hd);
2248 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
2249 return ERROR_INT(
"srow not made", __func__, 1);
2250 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
2252 return ERROR_INT(
"scol not made", __func__, 1);
2254 ratio = 1. / (2. * red);
2255 for (i = 0; i < hd; i++)
2256 srow[i] = (l_int32)(ratio * i);
2257 for (j = 0; j < wd; j++)
2258 scol[j] = (l_int32)(ratio * j);
2267 for (i = 0; i < hd; i++) {
2269 lines1 = datas1 + 2 * row2 * wpls1;
2270 lines2 = datas2 + row2 * wpls2;
2271 lined = datad + i * wpld;
2272 for (j = 0; j < wd; j++) {
2276 val = (l_int32)(w1 * val1 + w2 * val2);
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define GET_DATA_DIBIT(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
#define SET_DATA_QBIT(pdata, n, val)
PIX * pixExpandBinaryReplicate(PIX *pixs, l_int32 xfact, l_int32 yfact)
pixExpandBinaryReplicate()
l_uint32 * pixGetData(PIX *pix)
pixGetData()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok pixSetBorderRingVal(PIX *pixs, l_int32 dist, l_uint32 val)
pixSetBorderRingVal()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
l_ok pixCopyRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixCopyRGBComponent()
l_ok pixSetAll(PIX *pix)
pixSetAll()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
l_ok pixSetRGBComponent(PIX *pixd, PIX *pixs, l_int32 comp)
pixSetRGBComponent()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
l_int32 * makePixelSumTab8(void)
makePixelSumTab8()
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()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
PIX * pixScaleGrayLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleGrayLI()
PIX * pixScaleGeneral(PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 sharpfract, l_int32 sharpwidth)
pixScaleGeneral()
PIX * pixScaleBinary(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBinary()
PIX * pixScaleSmooth(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleSmooth()
PIX * pixScaleToGray8(PIX *pixs)
pixScaleToGray8()
PIX * pixScaleToGrayFast(PIX *pixs, l_float32 scalefactor)
pixScaleToGrayFast()
PIX * pixScaleToGray3(PIX *pixs)
pixScaleToGray3()
static l_uint8 * makeValTabSG3(void)
makeValTabSG3()
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()
PIX * pixScaleGrayMinMax2(PIX *pixs, l_int32 type)
pixScaleGrayMinMax2()
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()
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()
PIX * pixScaleWithAlpha(PIX *pixs, l_float32 scalex, l_float32 scaley, PIX *pixg, l_float32 fract)
pixScaleWithAlpha()
l_ok pixScaleAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleAndTransferAlpha()
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()
static l_uint32 * makeSumTabSG2(void)
makeSumTabSG2()
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()
static l_uint8 * makeValTabSG2(void)
makeValTabSG2()
PIX * pixScaleGrayRankCascade(PIX *pixs, l_int32 level1, l_int32 level2, l_int32 level3, l_int32 level4)
pixScaleGrayRankCascade()
PIX * pixScaleToGray6(PIX *pixs)
pixScaleToGray6()
PIX * pixScaleToGray2(PIX *pixs)
pixScaleToGray2()
PIX * pixScaleToGrayMipmap(PIX *pixs, l_float32 scalefactor)
pixScaleToGrayMipmap()
PIX * pixExpandReplicate(PIX *pixs, l_int32 factor)
pixExpandReplicate()
static l_uint32 * makeSumTabSG3(void)
makeSumTabSG3()
PIX * pixScaleToGray16(PIX *pixs)
pixScaleToGray16()
static l_uint8 * makeValTabSG4(void)
makeValTabSG4()
static l_uint8 * makeValTabSG6(void)
makeValTabSG6()
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 * pixScaleGrayMinMax(PIX *pixs, l_int32 xfact, l_int32 yfact, l_int32 type)
pixScaleGrayMinMax()
static l_uint8 * makeValTabSG8(void)
makeValTabSG8()
PIX * pixScaleMipmap(PIX *pixs1, PIX *pixs2, l_float32 scale)
pixScaleMipmap()
static l_uint32 * makeSumTabSG4(void)
makeSumTabSG4()
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()
PIX * pixScaleToGray(PIX *pixs, l_float32 scalefactor)
pixScaleToGray()
PIX * pixScaleGrayRank2(PIX *pixs, l_int32 rank)
pixScaleGrayRank2()
PIX * pixScaleToGray4(PIX *pixs)
pixScaleToGray4()
void lept_stderr(const char *fmt,...)
lept_stderr()