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;
215 PROCNAME(
"pixScaleToGray");
218 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
219 if (pixGetDepth(pixs) != 1)
220 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
221 if (scalefactor <= 0.0)
222 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
223 if (scalefactor >= 1.0)
224 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
226 minsrc = L_MIN(w, h);
227 mindest = (l_int32)((l_float32)minsrc * scalefactor);
229 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
231 if (scalefactor > 0.5) {
232 mag = 2.0 * scalefactor;
235 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
237 }
else if (scalefactor == 0.5) {
239 }
else if (scalefactor > 0.33333) {
240 mag = 3.0 * scalefactor;
243 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
245 }
else if (scalefactor > 0.25) {
246 mag = 4.0 * scalefactor;
249 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
251 }
else if (scalefactor == 0.25) {
253 }
else if (scalefactor > 0.16667) {
254 mag = 6.0 * scalefactor;
257 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
259 }
else if (scalefactor == 0.16667) {
261 }
else if (scalefactor > 0.125) {
262 mag = 8.0 * scalefactor;
265 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
267 }
else if (scalefactor == 0.125) {
269 }
else if (scalefactor > 0.0625) {
270 red = 8.0 * scalefactor;
273 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
275 }
else if (scalefactor == 0.0625) {
278 red = 16.0 * scalefactor;
281 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
290 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
291 pixCopyInputFormat(pixd, pixs);
320 l_float32 scalefactor)
322 l_int32 w, h, minsrc, mindest;
323 l_float32 eps, factor;
326 PROCNAME(
"pixScaleToGrayFast");
329 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
330 if (pixGetDepth(pixs) != 1)
331 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
332 if (scalefactor <= 0.0)
333 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
334 if (scalefactor >= 1.0)
335 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
337 minsrc = L_MIN(w, h);
338 mindest = (l_int32)((l_float32)minsrc * scalefactor);
340 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
344 if (scalefactor > 0.5 - eps && scalefactor < 0.5 + eps)
346 else if (scalefactor > 0.33333 - eps && scalefactor < 0.33333 + eps)
348 else if (scalefactor > 0.25 - eps && scalefactor < 0.25 + eps)
350 else if (scalefactor > 0.16666 - eps && scalefactor < 0.16666 + eps)
352 else if (scalefactor > 0.125 - eps && scalefactor < 0.125 + eps)
354 else if (scalefactor > 0.0625 - eps && scalefactor < 0.0625 + eps)
357 if (scalefactor > 0.0625) {
358 factor = 2.0 * scalefactor;
360 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
363 factor = 16.0 * scalefactor;
365 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
373 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
374 pixCopyInputFormat(pixd, pixs);
393 l_int32 ws, hs, wd, hd;
396 l_uint32 *datas, *datad;
399 PROCNAME(
"pixScaleToGray2");
402 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
403 if (pixGetDepth(pixs) != 1)
404 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
409 if (wd == 0 || hd == 0)
410 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
412 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
413 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
415 pixCopyInputFormat(pixd, pixs);
416 pixCopyResolution(pixd, pixs);
417 pixScaleResolution(pixd, 0.5, 0.5);
420 wpls = pixGetWpl(pixs);
421 wpld = pixGetWpl(pixd);
451 l_int32 ws, hs, wd, hd;
454 l_uint32 *datas, *datad;
457 PROCNAME(
"pixScaleToGray3");
460 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
461 if (pixGetDepth(pixs) != 1)
462 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
465 wd = (ws / 3) & 0xfffffff8;
467 if (wd == 0 || hd == 0)
468 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
470 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
471 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
472 pixCopyInputFormat(pixd, pixs);
473 pixCopyResolution(pixd, pixs);
474 pixScaleResolution(pixd, 0.33333, 0.33333);
477 wpls = pixGetWpl(pixs);
478 wpld = pixGetWpl(pixd);
505 l_int32 ws, hs, wd, hd;
508 l_uint32 *datas, *datad;
511 PROCNAME(
"pixScaleToGray4");
514 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
515 if (pixGetDepth(pixs) != 1)
516 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
519 wd = (ws / 4) & 0xfffffffe;
521 if (wd == 0 || hd == 0)
522 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
524 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
525 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
526 pixCopyInputFormat(pixd, pixs);
527 pixCopyResolution(pixd, pixs);
528 pixScaleResolution(pixd, 0.25, 0.25);
531 wpls = pixGetWpl(pixs);
532 wpld = pixGetWpl(pixd);
560 l_int32 ws, hs, wd, hd, wpld, wpls;
562 l_uint32 *datas, *datad;
565 PROCNAME(
"pixScaleToGray6");
568 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
569 if (pixGetDepth(pixs) != 1)
570 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
573 wd = (ws / 6) & 0xfffffff8;
575 if (wd == 0 || hd == 0)
576 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
578 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
579 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
580 pixCopyInputFormat(pixd, pixs);
581 pixCopyResolution(pixd, pixs);
582 pixScaleResolution(pixd, 0.16667, 0.16667);
585 wpls = pixGetWpl(pixs);
586 wpld = pixGetWpl(pixd);
608 l_int32 ws, hs, wd, hd;
611 l_uint32 *datas, *datad;
614 PROCNAME(
"pixScaleToGray8");
617 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
618 if (pixGetDepth(pixs) != 1)
619 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
624 if (wd == 0 || hd == 0)
625 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
627 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
628 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
629 pixCopyInputFormat(pixd, pixs);
630 pixCopyResolution(pixd, pixs);
631 pixScaleResolution(pixd, 0.125, 0.125);
634 wpls = pixGetWpl(pixs);
635 wpld = pixGetWpl(pixd);
656 l_int32 ws, hs, wd, hd;
659 l_uint32 *datas, *datad;
662 PROCNAME(
"pixScaleToGray16");
665 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
666 if (pixGetDepth(pixs) != 1)
667 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", procName, NULL);
672 if (wd == 0 || hd == 0)
673 return (
PIX *)ERROR_PTR(
"pixs too small", procName, NULL);
675 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
676 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
677 pixCopyInputFormat(pixd, pixs);
678 pixCopyResolution(pixd, pixs);
679 pixScaleResolution(pixd, 0.0625, 0.0625);
682 wpls = pixGetWpl(pixs);
683 wpld = pixGetWpl(pixd);
728 l_float32 scalefactor)
730 l_int32 w, h, minsrc, mindest;
732 PIX *pixs1, *pixs2, *pixt, *pixd;
734 PROCNAME(
"pixScaleToGrayMipmap");
737 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
738 if (pixGetDepth(pixs) != 1)
739 return (
PIX *)ERROR_PTR(
"pixs not 1 bpp", procName, NULL);
740 if (scalefactor <= 0.0)
741 return (
PIX *)ERROR_PTR(
"scalefactor <= 0.0", procName, NULL);
742 if (scalefactor >= 1.0)
743 return (
PIX *)ERROR_PTR(
"scalefactor >= 1.0", procName, NULL);
745 minsrc = L_MIN(w, h);
746 mindest = (l_int32)((l_float32)minsrc * scalefactor);
748 return (
PIX *)ERROR_PTR(
"scalefactor too small", procName, NULL);
750 if (scalefactor > 0.5) {
754 }
else if (scalefactor == 0.5) {
756 }
else if (scalefactor > 0.25) {
759 red = 2. * scalefactor;
760 }
else if (scalefactor == 0.25) {
762 }
else if (scalefactor > 0.125) {
765 red = 4. * scalefactor;
766 }
else if (scalefactor == 0.125) {
768 }
else if (scalefactor > 0.0625) {
771 red = 8. * scalefactor;
772 }
else if (scalefactor == 0.0625) {
775 red = 16.0 * scalefactor;
777 return (
PIX *)ERROR_PTR(
"pixt not made", procName, NULL);
787 pixCopyInputFormat(pixd, pixs);
819 l_int32 ws1, hs1, ws2, hs2, wd, hd, wpls1, wpls2, wpld;
820 l_uint32 *datas1, *datas2, *datad;
823 PROCNAME(
"pixScaleMipmap");
825 if (!pixs1 || pixGetDepth(pixs1) != 8 || pixGetColormap(pixs1))
826 return (
PIX *)ERROR_PTR(
"pixs1 underdefined, not 8 bpp, or cmapped",
828 if (!pixs2 || pixGetDepth(pixs2) != 8 || pixGetColormap(pixs2))
829 return (
PIX *)ERROR_PTR(
"pixs2 underdefined, not 8 bpp, or cmapped",
833 if (scale > 1.0 || scale < 0.5)
834 return (
PIX *)ERROR_PTR(
"scale not in [0.5, 1.0]", procName, NULL);
836 return (
PIX *)ERROR_PTR(
"invalid width ratio", procName, NULL);
838 return (
PIX *)ERROR_PTR(
"invalid height ratio", procName, NULL);
843 wpls1 = pixGetWpl(pixs1);
845 wpls2 = pixGetWpl(pixs2);
846 wd = (l_int32)(2. * scale * pixGetWidth(pixs2));
847 hd = (l_int32)(2. * scale * pixGetHeight(pixs2));
848 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
849 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
850 pixCopyInputFormat(pixd, pixs1);
851 pixCopyResolution(pixd, pixs1);
852 pixScaleResolution(pixd, scale, scale);
854 wpld = pixGetWpl(pixd);
856 scaleMipmapLow(datad, wd, hd, wpld, datas1, wpls1, datas2, wpls2, scale);
875 l_int32 w, h, d, wd, hd, wpls, wpld, start, i, j, k;
879 l_uint32 *lines, *datas, *lined, *datad;
882 PROCNAME(
"pixExpandReplicate");
885 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
887 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
888 return (
PIX *)ERROR_PTR(
"depth not in {1,2,4,8,16,32}", procName, NULL);
890 return (
PIX *)ERROR_PTR(
"factor <= 0; invalid", procName, NULL);
899 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
900 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
902 pixCopyInputFormat(pixd, pixs);
903 pixCopyResolution(pixd, pixs);
904 pixScaleResolution(pixd, (l_float32)factor, (l_float32)factor);
906 wpls = pixGetWpl(pixs);
908 wpld = pixGetWpl(pixd);
912 for (i = 0; i < h; i++) {
913 lines = datas + i * wpls;
914 lined = datad + factor * i * wpld;
915 for (j = 0; j < w; j++) {
918 for (k = 0; k < factor; k++)
921 for (k = 1; k < factor; k++)
922 memcpy(lined + k * wpld, lined, 4 * wpld);
926 for (i = 0; i < h; i++) {
927 lines = datas + i * wpls;
928 lined = datad + factor * i * wpld;
929 for (j = 0; j < w; j++) {
932 for (k = 0; k < factor; k++)
935 for (k = 1; k < factor; k++)
936 memcpy(lined + k * wpld, lined, 4 * wpld);
940 for (i = 0; i < h; i++) {
941 lines = datas + i * wpls;
942 lined = datad + factor * i * wpld;
943 for (j = 0; j < w; j++) {
946 for (k = 0; k < factor; k++)
949 for (k = 1; k < factor; k++)
950 memcpy(lined + k * wpld, lined, 4 * wpld);
954 for (i = 0; i < h; i++) {
955 lines = datas + i * wpls;
956 lined = datad + factor * i * wpld;
957 for (j = 0; j < w; j++) {
960 for (k = 0; k < factor; k++)
963 for (k = 1; k < factor; k++)
964 memcpy(lined + k * wpld, lined, 4 * wpld);
968 for (i = 0; i < h; i++) {
969 lines = datas + i * wpls;
970 lined = datad + factor * i * wpld;
971 for (j = 0; j < w; j++) {
972 sval32 = *(lines + j);
974 for (k = 0; k < factor; k++)
975 *(lined + start + k) = sval32;
977 for (k = 1; k < factor; k++)
978 memcpy(lined + k * wpld, lined, 4 * wpld);
985 if (d == 32 && pixGetSpp(pixs) == 4)
1024 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1025 l_int32 minval, maxval, val;
1026 l_uint32 *datas, *datad, *lines, *lined;
1029 PROCNAME(
"pixScaleGrayMinMax");
1031 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1032 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1035 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1036 type != L_CHOOSE_MAXDIFF)
1037 return (
PIX *)ERROR_PTR(
"invalid type", procName, NULL);
1038 if (xfact < 1 || yfact < 1)
1039 return (
PIX *)ERROR_PTR(
"xfact and yfact must be >= 1", procName, NULL);
1041 if (xfact == 2 && yfact == 2)
1054 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1055 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1056 pixCopyInputFormat(pixd, pixs);
1059 wpls = pixGetWpl(pixs);
1060 wpld = pixGetWpl(pixd);
1061 for (i = 0; i < hd; i++) {
1062 lined = datad + i * wpld;
1063 for (j = 0; j < wd; j++) {
1064 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1066 for (k = 0; k < yfact; k++) {
1067 lines = datas + (yfact * i + k) * wpls;
1068 for (m = 0; m < xfact; m++) {
1075 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1077 for (k = 0; k < yfact; k++) {
1078 lines = datas + (yfact * i + k) * wpls;
1079 for (m = 0; m < xfact; m++) {
1086 if (type == L_CHOOSE_MIN)
1088 else if (type == L_CHOOSE_MAX)
1129 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k;
1130 l_int32 minval, maxval;
1132 l_uint32 *datas, *datad, *lines, *lined;
1135 PROCNAME(
"pixScaleGrayMinMax2");
1137 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1138 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1141 if (ws < 2 || hs < 2)
1142 return (
PIX *)ERROR_PTR(
"too small: ws < 2 or hs < 2", procName, NULL);
1143 if (type != L_CHOOSE_MIN && type != L_CHOOSE_MAX &&
1144 type != L_CHOOSE_MAXDIFF)
1145 return (
PIX *)ERROR_PTR(
"invalid type", procName, NULL);
1149 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1150 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1151 pixCopyInputFormat(pixd, pixs);
1154 wpls = pixGetWpl(pixs);
1155 wpld = pixGetWpl(pixd);
1156 for (i = 0; i < hd; i++) {
1157 lines = datas + 2 * i * wpls;
1158 lined = datad + i * wpld;
1159 for (j = 0; j < wd; j++) {
1164 if (type == L_CHOOSE_MIN || type == L_CHOOSE_MAXDIFF) {
1166 for (k = 0; k < 4; k++) {
1167 if (val[k] < minval)
1171 if (type == L_CHOOSE_MAX || type == L_CHOOSE_MAXDIFF) {
1173 for (k = 0; k < 4; k++) {
1174 if (val[k] > maxval)
1178 if (type == L_CHOOSE_MIN)
1180 else if (type == L_CHOOSE_MAX)
1215 PIX *pixt1, *pixt2, *pixt3, *pixt4;
1217 PROCNAME(
"pixScaleGrayRankCascade");
1219 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1220 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1222 if (level1 > 4 || level2 > 4 || level3 > 4 || level4 > 4)
1223 return (
PIX *)ERROR_PTR(
"levels must not exceed 4", procName, NULL);
1226 L_WARNING(
"no reduction because level1 not > 0\n", procName);
1276 l_int32 ws, hs, wd, hd, wpls, wpld, i, j, k, m;
1277 l_int32 minval, maxval, rankval, minindex, maxindex;
1280 l_uint32 *datas, *datad, *lines, *lined;
1283 PROCNAME(
"pixScaleGrayRank2");
1285 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1286 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1288 if (rank < 1 || rank > 4)
1289 return (
PIX *)ERROR_PTR(
"invalid rank", procName, NULL);
1299 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1300 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1301 pixCopyInputFormat(pixd, pixs);
1304 wpls = pixGetWpl(pixs);
1305 wpld = pixGetWpl(pixd);
1306 for (i = 0; i < hd; i++) {
1307 lines = datas + 2 * i * wpls;
1308 lined = datad + i * wpld;
1309 for (j = 0; j < wd; j++) {
1314 minval = maxval = val[0];
1315 minindex = maxindex = 0;
1316 for (k = 1; k < 4; k++) {
1317 if (val[k] < minval) {
1322 if (val[k] > maxval) {
1327 for (k = 0, m = 0; k < 4; k++) {
1328 if (k == minindex || k == maxindex)
1330 midval[m++] = val[k];
1335 rankval = L_MIN(midval[0], midval[1]);
1337 rankval = L_MAX(midval[0], midval[1]);
1371 PROCNAME(
"pixScaleAndTransferAlpha");
1374 return ERROR_INT(
"pixs and pixd not both defined", procName, 1);
1375 if (pixGetDepth(pixs) != 32 || pixGetSpp(pixs) != 4)
1376 return ERROR_INT(
"pixs not 32 bpp and 4 spp", procName, 1);
1377 if (pixGetDepth(pixd) != 32)
1378 return ERROR_INT(
"pixd not 32 bpp", procName, 1);
1380 if (scalex == 1.0 && scaley == 1.0) {
1386 pix2 =
pixScale(pix1, scalex, scaley);
1449 l_int32 ws, hs, d, spp;
1450 PIX *pixd, *pix32, *pixg2, *pixgs;
1452 PROCNAME(
"pixScaleWithAlpha");
1455 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
1457 if (d != 32 && !pixGetColormap(pixs))
1458 return (
PIX *)ERROR_PTR(
"pixs not cmapped or 32 bpp", procName, NULL);
1459 if (scalex <= 0.0 || scaley <= 0.0)
1460 return (
PIX *)ERROR_PTR(
"scale factor <= 0.0", procName, NULL);
1461 if (pixg && pixGetDepth(pixg) != 8) {
1462 L_WARNING(
"pixg not 8 bpp; using 'fract' transparent alpha\n",
1466 if (!pixg && (fract < 0.0 || fract > 1.0)) {
1467 L_WARNING(
"invalid fract; using fully opaque\n", procName);
1470 if (!pixg && fract == 0.0)
1471 L_WARNING(
"transparent alpha; image will not be blended\n", procName);
1478 spp = pixGetSpp(pix32);
1479 pixSetSpp(pix32, 3);
1480 pixd =
pixScale(pix32, scalex, scaley);
1481 pixSetSpp(pix32, spp);
1489 else if (fract > 0.0)
1494 if (ws > 10 && hs > 10) {
1496 (l_int32)(255.0 * fract * AlphaMaskBorderVals[0]));
1498 (l_int32)(255.0 * fract * AlphaMaskBorderVals[1]));
1504 pixCopyInputFormat(pixd, pixs);
1554 l_int32 i, j, l, k, m, wd4, extra;
1555 l_uint32 sbyte1, sbyte2, sum;
1556 l_uint32 *lines, *lined;
1564 wd4 = wd & 0xfffffffc;
1566 for (i = 0, l = 0; i < hd; i++, l += 2) {
1567 lines = datas + l * wpls;
1568 lined = datad + i * wpld;
1569 for (j = 0, k = 0; j < wd4; j += 4, k++) {
1572 sum = sumtab[sbyte1] + sumtab[sbyte2];
1581 sum = sumtab[sbyte1] + sumtab[sbyte2];
1582 for (m = 0; m < extra; m++) {
1584 valtab[((sum >> (24 - 8 * m)) & 0xff)]);
1608 l_int32 sum[] = {0, 1, 1, 2};
1611 PROCNAME(
"makeSumTabSG2");
1614 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1615 for (i = 0; i < 256; i++) {
1616 tab[i] = (sum[i & 0x3] | sum[(i >> 2) & 0x3] << 8 |
1617 sum[(i >> 4) & 0x3] << 16 | sum[(i >> 6) & 0x3] << 24);
1640 PROCNAME(
"makeValTabSG2");
1642 tab = (l_uint8 *)LEPT_CALLOC(5,
sizeof(l_uint8));
1643 for (i = 0; i < 5; i++)
1644 tab[i] = 255 - (i * 255) / 4;
1697 l_uint32 threebytes1, threebytes2, threebytes3, sum;
1698 l_uint32 *lines, *lined;
1707 for (i = 0, l = 0; i < hd; i++, l += 3) {
1708 lines = datas + l * wpls;
1709 lined = datad + i * wpld;
1710 for (j = 0, k = 0; j < wd; j += 8, k += 3) {
1721 sum = sumtab[(threebytes1 >> 18)] +
1722 sumtab[(threebytes2 >> 18)] +
1723 sumtab[(threebytes3 >> 18)];
1727 sum = sumtab[((threebytes1 >> 12) & 0x3f)] +
1728 sumtab[((threebytes2 >> 12) & 0x3f)] +
1729 sumtab[((threebytes3 >> 12) & 0x3f)];
1733 sum = sumtab[((threebytes1 >> 6) & 0x3f)] +
1734 sumtab[((threebytes2 >> 6) & 0x3f)] +
1735 sumtab[((threebytes3 >> 6) & 0x3f)];
1739 sum = sumtab[(threebytes1 & 0x3f)] +
1740 sumtab[(threebytes2 & 0x3f)] +
1741 sumtab[(threebytes3 & 0x3f)];
1767 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3};
1770 PROCNAME(
"makeSumTabSG3");
1773 tab = (l_uint32 *)LEPT_CALLOC(64,
sizeof(l_uint32));
1774 for (i = 0; i < 64; i++) {
1775 tab[i] = (sum[i & 0x07]) | (sum[(i >> 3) & 0x07] << 8);
1798 PROCNAME(
"makeValTabSG3");
1800 tab = (l_uint8 *)LEPT_CALLOC(10,
sizeof(l_uint8));
1801 for (i = 0; i < 10; i++)
1802 tab[i] = 0xff - (i * 255) / 9;
1846 l_uint32 sbyte1, sbyte2, sbyte3, sbyte4, sum;
1847 l_uint32 *lines, *lined;
1855 for (i = 0, l = 0; i < hd; i++, l += 4) {
1856 lines = datas + l * wpls;
1857 lined = datad + i * wpld;
1858 for (j = 0, k = 0; j < wd; j += 2, k++) {
1863 sum = sumtab[sbyte1] + sumtab[sbyte2] +
1864 sumtab[sbyte3] + sumtab[sbyte4];
1888 l_int32 sum[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
1891 PROCNAME(
"makeSumTabSG4");
1894 tab = (l_uint32 *)LEPT_CALLOC(256,
sizeof(l_uint32));
1895 for (i = 0; i < 256; i++) {
1896 tab[i] = (sum[i & 0xf]) | (sum[(i >> 4) & 0xf] << 8);
1919 PROCNAME(
"makeValTabSG4");
1921 tab = (l_uint8 *)LEPT_CALLOC(17,
sizeof(l_uint8));
1922 for (i = 0; i < 17; i++)
1923 tab[i] = 0xff - (i * 255) / 16;
1975 l_uint32 threebytes1, threebytes2, threebytes3;
1976 l_uint32 threebytes4, threebytes5, threebytes6, sum;
1977 l_uint32 *lines, *lined;
1986 for (i = 0, l = 0; i < hd; i++, l += 6) {
1987 lines = datas + l * wpls;
1988 lined = datad + i * wpld;
1989 for (j = 0, k = 0; j < wd; j += 4, k += 3) {
2012 sum = tab8[(threebytes1 >> 18)] +
2013 tab8[(threebytes2 >> 18)] +
2014 tab8[(threebytes3 >> 18)] +
2015 tab8[(threebytes4 >> 18)] +
2016 tab8[(threebytes5 >> 18)] +
2017 tab8[(threebytes6 >> 18)];
2021 sum = tab8[((threebytes1 >> 12) & 0x3f)] +
2022 tab8[((threebytes2 >> 12) & 0x3f)] +
2023 tab8[((threebytes3 >> 12) & 0x3f)] +
2024 tab8[((threebytes4 >> 12) & 0x3f)] +
2025 tab8[((threebytes5 >> 12) & 0x3f)] +
2026 tab8[((threebytes6 >> 12) & 0x3f)];
2029 sum = tab8[((threebytes1 >> 6) & 0x3f)] +
2030 tab8[((threebytes2 >> 6) & 0x3f)] +
2031 tab8[((threebytes3 >> 6) & 0x3f)] +
2032 tab8[((threebytes4 >> 6) & 0x3f)] +
2033 tab8[((threebytes5 >> 6) & 0x3f)] +
2034 tab8[((threebytes6 >> 6) & 0x3f)];
2037 sum = tab8[(threebytes1 & 0x3f)] +
2038 tab8[(threebytes2 & 0x3f)] +
2039 tab8[(threebytes3 & 0x3f)] +
2040 tab8[(threebytes4 & 0x3f)] +
2041 tab8[(threebytes5 & 0x3f)] +
2042 tab8[(threebytes6 & 0x3f)];
2066 PROCNAME(
"makeValTabSG6");
2068 tab = (l_uint8 *)LEPT_CALLOC(37,
sizeof(l_uint8));
2069 for (i = 0; i < 37; i++)
2070 tab[i] = 0xff - (i * 255) / 36;
2113 l_int32 sbyte0, sbyte1, sbyte2, sbyte3, sbyte4, sbyte5, sbyte6, sbyte7, sum;
2114 l_uint32 *lines, *lined;
2121 for (i = 0, k = 0; i < hd; i++, k += 8) {
2122 lines = datas + k * wpls;
2123 lined = datad + i * wpld;
2124 for (j = 0; j < wd; j++) {
2133 sum = tab8[sbyte0] + tab8[sbyte1] +
2134 tab8[sbyte2] + tab8[sbyte3] +
2135 tab8[sbyte4] + tab8[sbyte5] +
2136 tab8[sbyte6] + tab8[sbyte7];
2160 PROCNAME(
"makeValTabSG8");
2162 tab = (l_uint8 *)LEPT_CALLOC(65,
sizeof(l_uint8));
2163 for (i = 0; i < 65; i++)
2164 tab[i] = 0xff - (i * 255) / 64;
2205 l_uint32 *lines, *lined;
2213 for (i = 0, k = 0; i < hd; i++, k += 16) {
2214 lines = datas + k * wpls;
2215 lined = datad + i * wpld;
2216 for (j = 0; j < wd; j++) {
2250 sum = L_MIN(sum, 255);
2282 l_int32 i, j, val1, val2, val, row2, col2;
2283 l_int32 *srow, *scol;
2284 l_uint32 *lines1, *lines2, *lined;
2285 l_float32 ratio, w1, w2;
2287 PROCNAME(
"scaleMipmapLow");
2290 memset(datad, 0, 4LL * wpld * hd);
2300 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
2301 return ERROR_INT(
"srow not made", procName, 1);
2302 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
2304 return ERROR_INT(
"scol not made", procName, 1);
2306 ratio = 1. / (2. * red);
2307 for (i = 0; i < hd; i++)
2308 srow[i] = (l_int32)(ratio * i);
2309 for (j = 0; j < wd; j++)
2310 scol[j] = (l_int32)(ratio * j);
2319 for (i = 0; i < hd; i++) {
2321 lines1 = datas1 + 2 * row2 * wpls1;
2322 lines2 = datas2 + row2 * wpls2;
2323 lined = datad + i * wpld;
2324 for (j = 0; j < wd; j++) {
2328 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()