115 #include <config_auto.h>
119 #include "allheaders.h"
122 l_int32 wpld, l_uint32 *datas, l_int32 ws,
123 l_int32 hs, l_int32 wpls);
124 static void scaleGrayLILow(l_uint32 *datad, l_int32 wd, l_int32 hd,
125 l_int32 wpld, l_uint32 *datas, l_int32 ws,
126 l_int32 hs, l_int32 wpls);
128 l_int32 ws, l_int32 hs, l_int32 wpls);
130 l_uint32 *lines, l_int32 ws, l_int32 wpls,
131 l_int32 lastlineflag);
132 static void scaleGray2xLILow(l_uint32 *datad, l_int32 wpld, l_uint32 *datas,
133 l_int32 ws, l_int32 hs, l_int32 wpls);
135 l_uint32 *lines, l_int32 ws, l_int32 wpls,
136 l_int32 lastlineflag);
137 static void scaleGray4xLILow(l_uint32 *datad, l_int32 wpld, l_uint32 *datas,
138 l_int32 ws, l_int32 hs, l_int32 wpls);
140 l_uint32 *lines, l_int32 ws, l_int32 wpls,
141 l_int32 lastlineflag);
143 l_int32 wpld, l_uint32 *datas, l_int32 ws,
144 l_int32 hs, l_int32 d, l_int32 wpls);
145 static l_int32
scaleSmoothLow(l_uint32 *datad, l_int32 wd, l_int32 hd,
146 l_int32 wpld, l_uint32 *datas, l_int32 ws,
147 l_int32 hs, l_int32 d, l_int32 wpls,
150 l_int32 wpld, l_uint32 *datas, l_int32 wpls,
151 l_float32 rwt, l_float32 gwt, l_float32 bwt);
153 l_int32 wpld, l_uint32 *datas, l_int32 ws,
154 l_int32 hs, l_int32 wpls);
156 l_int32 wpld, l_uint32 *datas, l_int32 ws,
157 l_int32 hs, l_int32 wpls);
159 l_int32 wpld, l_uint32 *datas, l_int32 d,
161 static l_int32 scaleBinaryLow(l_uint32 *datad, l_int32 wd, l_int32 hd,
162 l_int32 wpld, l_uint32 *datas, l_int32 ws,
163 l_int32 hs, l_int32 wpls);
165 #ifndef NO_CONSOLE_IO
166 #define DEBUG_OVERFLOW 0
167 #define DEBUG_UNROLLING 0
255 l_float32 maxscale, sharpfract;
258 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
261 maxscale = L_MAX(scalex, scaley);
262 sharpfract = (maxscale < 0.7) ? 0.2 : 0.4;
263 sharpwidth = (maxscale < 0.7) ? 1 : 2;
282 l_int32 w, h, wd, hd;
285 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
287 if (delw == 0 && delh == 0)
293 if (wd <= 0 || hd <= 0)
294 return (
PIX *)ERROR_PTR(
"pix dimension reduced to 0", __func__, NULL);
324 l_float32 scalex, scaley;
327 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
328 if (wd <= 0 && hd <= 0)
329 return (
PIX *)ERROR_PTR(
"neither wd nor hd > 0", __func__, NULL);
333 scaley = (l_float32)hd / (l_float32)h;
335 }
else if (hd <= 0) {
336 scalex = (l_float32)wd / (l_float32)w;
339 scalex = (l_float32)wd / (l_float32)w;
340 scaley = (l_float32)hd / (l_float32)h;
343 return pixScale(pixs, scalex, scaley);
360 l_float32 *pscalefact)
365 if (pscalefact) *pscalefact = 1.0;
367 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
369 return (
PIX *)ERROR_PTR(
"target resolution <= 0", __func__, NULL);
371 xres = pixGetXRes(pixs);
377 factor = target / (l_float32)xres;
378 if (pscalefact) *pscalefact = factor;
380 return pixScale(pixs, factor, factor);
418 l_float32 sharpfract,
422 l_float32 maxscale, minscale;
423 PIX *pix1, *pix2, *pixd;
426 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
427 d = pixGetDepth(pixs);
428 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
429 return (
PIX *)ERROR_PTR(
"pixs not {1,2,4,8,16,32} bpp", __func__, NULL);
430 if (scalex <= 0.0 || scaley <= 0.0)
431 return (
PIX *)ERROR_PTR(
"scale factor <= 0", __func__, NULL);
432 if (scalex == 1.0 && scaley == 1.0)
440 return (
PIX *)ERROR_PTR(
"pix1 not made", __func__, NULL);
443 d = pixGetDepth(pix1);
444 maxscale = L_MAX(scalex, scaley);
445 minscale = L_MIN(scalex, scaley);
446 if (maxscale < 0.7) {
447 if (minscale < 0.02) {
452 if (maxscale > 0.2 && sharpfract > 0.0 && sharpwidth > 0) {
463 if (maxscale < 1.4 && sharpfract > 0.0 && sharpwidth > 0) {
472 pixCopyText(pixd, pixs);
473 pixCopyInputFormat(pixd, pixs);
514 if (!pixs || (pixGetDepth(pixs) == 1))
515 return (
PIX *)ERROR_PTR(
"pixs not defined or 1 bpp", __func__, NULL);
516 maxscale = L_MAX(scalex, scaley);
517 if (maxscale < 0.7) {
518 L_WARNING(
"scaling factors < 0.7; do regular scaling\n", __func__);
521 d = pixGetDepth(pixs);
522 if (d != 2 && d != 4 && d != 8 && d != 16 && d != 32)
523 return (
PIX *)ERROR_PTR(
"pixs not {2,4,8,16,32} bpp", __func__, NULL);
527 return (
PIX *)ERROR_PTR(
"pixt not made", __func__, NULL);
529 d = pixGetDepth(pixt);
536 pixCopyInputFormat(pixd, pixs);
567 l_int32 ws, hs, wpls, wd, hd, wpld;
568 l_uint32 *datas, *datad;
572 if (!pixs || (pixGetDepth(pixs) != 32))
573 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
574 maxscale = L_MAX(scalex, scaley);
575 if (maxscale < 0.7) {
576 L_WARNING(
"scaling factors < 0.7; do regular scaling\n", __func__);
581 if (scalex == 1.0 && scaley == 1.0)
583 if (scalex == 2.0 && scaley == 2.0)
585 if (scalex == 4.0 && scaley == 4.0)
591 wpls = pixGetWpl(pixs);
592 wd = (l_int32)(scalex * (l_float32)ws + 0.5);
593 hd = (l_int32)(scaley * (l_float32)hs + 0.5);
594 if ((pixd =
pixCreate(wd, hd, 32)) == NULL)
595 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
596 pixCopyResolution(pixd, pixs);
597 pixScaleResolution(pixd, scalex, scaley);
599 wpld = pixGetWpl(pixd);
601 if (pixGetSpp(pixs) == 4)
604 pixCopyInputFormat(pixd, pixs);
627 l_int32 ws, hs, wpls, wpld;
628 l_uint32 *datas, *datad;
631 if (!pixs || (pixGetDepth(pixs) != 32))
632 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
636 wpls = pixGetWpl(pixs);
637 if ((pixd =
pixCreate(2 * ws, 2 * hs, 32)) == NULL)
638 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
639 pixCopyResolution(pixd, pixs);
640 pixScaleResolution(pixd, 2.0, 2.0);
642 wpld = pixGetWpl(pixd);
644 if (pixGetSpp(pixs) == 4)
647 pixCopyInputFormat(pixd, pixs);
672 PIX *pixr, *pixg, *pixb;
673 PIX *pixrs, *pixgs, *pixbs;
676 if (!pixs || (pixGetDepth(pixs) != 32))
677 return (
PIX *)ERROR_PTR(
"pixs undefined or not 32 bpp", __func__, NULL);
690 L_ERROR(
"pixd not made\n", __func__);
692 if (pixGetSpp(pixs) == 4)
694 pixCopyInputFormat(pixd, pixs);
766 l_int32 ws, hs, wpls, wd, hd, wpld;
767 l_uint32 *datas, *datad;
771 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
772 return (
PIX *)ERROR_PTR(
"pixs undefined, cmapped or not 8 bpp",
774 maxscale = L_MAX(scalex, scaley);
775 if (maxscale < 0.7) {
776 L_WARNING(
"scaling factors < 0.7; do regular scaling\n", __func__);
781 if (scalex == 1.0 && scaley == 1.0)
783 if (scalex == 2.0 && scaley == 2.0)
785 if (scalex == 4.0 && scaley == 4.0)
791 wpls = pixGetWpl(pixs);
792 wd = (l_int32)(scalex * (l_float32)ws + 0.5);
793 hd = (l_int32)(scaley * (l_float32)hs + 0.5);
794 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
795 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
796 pixCopyText(pixd, pixs);
797 pixCopyResolution(pixd, pixs);
798 pixCopyInputFormat(pixd, pixs);
799 pixScaleResolution(pixd, scalex, scaley);
801 wpld = pixGetWpl(pixd);
823 l_int32 ws, hs, wpls, wpld;
824 l_uint32 *datas, *datad;
827 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
828 return (
PIX *)ERROR_PTR(
"pixs undefined, cmapped or not 8 bpp",
833 wpls = pixGetWpl(pixs);
834 if ((pixd =
pixCreate(2 * ws, 2 * hs, 8)) == NULL)
835 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
836 pixCopyResolution(pixd, pixs);
837 pixCopyInputFormat(pixd, pixs);
838 pixScaleResolution(pixd, 2.0, 2.0);
840 wpld = pixGetWpl(pixd);
862 l_int32 ws, hs, wpls, wpld;
863 l_uint32 *datas, *datad;
866 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
867 return (
PIX *)ERROR_PTR(
"pixs undefined, cmapped or not 8 bpp",
872 wpls = pixGetWpl(pixs);
873 if ((pixd =
pixCreate(4 * ws, 4 * hs, 8)) == NULL)
874 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
875 pixCopyResolution(pixd, pixs);
876 pixCopyInputFormat(pixd, pixs);
877 pixScaleResolution(pixd, 4.0, 4.0);
879 wpld = pixGetWpl(pixd);
906 l_int32 i, ws, hs, hsm, wd, hd, wpls, wplb, wpld;
907 l_uint32 *datas, *datad, *lines, *lined, *lineb;
910 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
911 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
913 if (thresh < 0 || thresh > 256)
914 return (
PIX *)ERROR_PTR(
"thresh must be in [0, ... 256]",
922 wpls = pixGetWpl(pixs);
926 if ((lineb = (l_uint32 *)LEPT_CALLOC(2 * wplb,
sizeof(l_uint32))) == NULL)
927 return (
PIX *)ERROR_PTR(
"lineb not made", __func__, NULL);
930 if ((pixd =
pixCreate(wd, hd, 1)) == NULL) {
932 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
934 pixCopyInputFormat(pixd, pixs);
935 pixCopyResolution(pixd, pixs);
936 pixScaleResolution(pixd, 2.0, 2.0);
937 wpld = pixGetWpl(pixd);
941 for (i = 0; i < hsm; i++) {
942 lines = datas + i * wpls;
943 lined = datad + 2 * i * wpld;
945 thresholdToBinaryLineLow(lined, wd, lineb, 8, thresh);
946 thresholdToBinaryLineLow(lined + wpld, wd, lineb + wplb, 8, thresh);
950 lines = datas + hsm * wpls;
951 lined = datad + 2 * hsm * wpld;
953 thresholdToBinaryLineLow(lined, wd, lineb, 8, thresh);
954 thresholdToBinaryLineLow(lined + wpld, wd, lineb + wplb, 8, thresh);
982 l_int32 i, ws, hs, hsm, wd, hd, wpls, wplb, wpld;
983 l_uint32 *datas, *datad;
985 l_uint32 *lineb = NULL;
986 l_uint32 *linebp = NULL;
987 l_uint32 *bufs = NULL;
990 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
991 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
999 wpls = pixGetWpl(pixs);
1002 if ((bufs = (l_uint32 *)LEPT_CALLOC(2 * wpls,
sizeof(l_uint32))) == NULL)
1003 return (
PIX *)ERROR_PTR(
"bufs not made", __func__, NULL);
1006 wplb = (wd + 3) / 4;
1007 if ((lineb = (l_uint32 *)LEPT_CALLOC(2 * wplb,
sizeof(l_uint32))) == NULL) {
1008 L_ERROR(
"lineb not made\n", __func__);
1013 if ((linebp = (l_uint32 *)LEPT_CALLOC(wplb,
sizeof(l_uint32))) == NULL) {
1014 L_ERROR(
"linebp not made\n", __func__);
1019 if ((pixd =
pixCreate(wd, hd, 1)) == NULL) {
1020 L_ERROR(
"pixd not made\n", __func__);
1023 pixCopyInputFormat(pixd, pixs);
1024 pixCopyResolution(pixd, pixs);
1025 pixScaleResolution(pixd, 2.0, 2.0);
1026 wpld = pixGetWpl(pixd);
1030 memcpy(bufs, datas, 4 * wpls);
1031 memcpy(bufs + wpls, datas + wpls, 4 * wpls);
1039 for (i = 1; i < hsm; i++) {
1040 memcpy(bufs, datas + i * wpls, 4 * wpls);
1041 memcpy(bufs + wpls, datas + (i + 1) * wpls, 4 * wpls);
1042 memcpy(linebp, lineb + wplb, 4 * wplb);
1044 lined = datad + 2 * i * wpld;
1054 memcpy(bufs, datas + hsm * wpls, 4 * wpls);
1055 memcpy(linebp, lineb + wplb, 4 * wplb);
1100 l_int32 i, j, ws, hs, hsm, wd, hd, wpls, wplb, wpld;
1101 l_uint32 *datas, *datad, *lines, *lined, *lineb;
1104 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1105 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1107 if (thresh < 0 || thresh > 256)
1108 return (
PIX *)ERROR_PTR(
"thresh must be in [0, ... 256]",
1116 wpls = pixGetWpl(pixs);
1119 wplb = (wd + 3) / 4;
1120 if ((lineb = (l_uint32 *)LEPT_CALLOC(4 * wplb,
sizeof(l_uint32))) == NULL)
1121 return (
PIX *)ERROR_PTR(
"lineb not made", __func__, NULL);
1124 if ((pixd =
pixCreate(wd, hd, 1)) == NULL) {
1126 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1128 pixCopyInputFormat(pixd, pixs);
1129 pixCopyResolution(pixd, pixs);
1130 pixScaleResolution(pixd, 4.0, 4.0);
1131 wpld = pixGetWpl(pixd);
1135 for (i = 0; i < hsm; i++) {
1136 lines = datas + i * wpls;
1137 lined = datad + 4 * i * wpld;
1139 for (j = 0; j < 4; j++) {
1140 thresholdToBinaryLineLow(lined + j * wpld, wd,
1141 lineb + j * wplb, 8, thresh);
1146 lines = datas + hsm * wpls;
1147 lined = datad + 4 * hsm * wpld;
1149 for (j = 0; j < 4; j++) {
1150 thresholdToBinaryLineLow(lined + j * wpld, wd,
1151 lineb + j * wplb, 8, thresh);
1185 l_int32 i, j, ws, hs, hsm, wd, hd, wpls, wplb, wpld;
1186 l_uint32 *datas, *datad;
1188 l_uint32 *lineb = NULL;
1189 l_uint32 *linebp = NULL;
1190 l_uint32 *bufs = NULL;
1193 if (!pixs || pixGetDepth(pixs) != 8 || pixGetColormap(pixs))
1194 return (
PIX *)ERROR_PTR(
"pixs undefined, not 8 bpp, or cmapped",
1202 wpls = pixGetWpl(pixs);
1205 if ((bufs = (l_uint32 *)LEPT_CALLOC(2 * wpls,
sizeof(l_uint32))) == NULL)
1206 return (
PIX *)ERROR_PTR(
"bufs not made", __func__, NULL);
1209 wplb = (wd + 3) / 4;
1210 if ((lineb = (l_uint32 *)LEPT_CALLOC(4 * wplb,
sizeof(l_uint32))) == NULL) {
1211 L_ERROR(
"lineb not made\n", __func__);
1216 if ((linebp = (l_uint32 *)LEPT_CALLOC(wplb,
sizeof(l_uint32))) == NULL) {
1217 L_ERROR(
"linebp not made\n", __func__);
1222 if ((pixd =
pixCreate(wd, hd, 1)) == NULL) {
1223 L_ERROR(
"pixd not made\n", __func__);
1226 pixCopyInputFormat(pixd, pixs);
1227 pixCopyResolution(pixd, pixs);
1228 pixScaleResolution(pixd, 4.0, 4.0);
1229 wpld = pixGetWpl(pixd);
1233 memcpy(bufs, datas, 4 * wpls);
1234 memcpy(bufs + wpls, datas + wpls, 4 * wpls);
1237 for (j = 0; j < 3; j++) {
1239 lineb + (j + 1) * wplb,
1244 for (i = 1; i < hsm; i++) {
1245 memcpy(bufs, datas + i * wpls, 4 * wpls);
1246 memcpy(bufs + wpls, datas + (i + 1) * wpls, 4 * wpls);
1247 memcpy(linebp, lineb + 3 * wplb, 4 * wplb);
1249 lined = datad + 4 * i * wpld;
1253 for (j = 0; j < 3; j++) {
1255 lineb + (j + 1) * wplb,
1261 memcpy(bufs, datas + hsm * wpls, 4 * wpls);
1262 memcpy(linebp, lineb + 3 * wplb, 4 * wplb);
1264 lined = datad + 4 * hsm * wpld;
1268 for (j = 0; j < 3; j++) {
1270 lineb + (j + 1) * wplb,
1310 l_int32 ws, hs, d, wpls, wd, hd, wpld;
1311 l_uint32 *datas, *datad;
1315 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1316 if (scalex <= 0.0 || scaley <= 0.0)
1317 return (
PIX *)ERROR_PTR(
"scale factor <= 0", __func__, NULL);
1318 if (scalex == 1.0 && scaley == 1.0)
1320 if ((d = pixGetDepth(pixs)) == 1)
1325 wpls = pixGetWpl(pixs);
1326 wd = (l_int32)(scalex * (l_float32)ws + 0.5);
1327 hd = (l_int32)(scaley * (l_float32)hs + 0.5);
1328 if ((pixd =
pixCreate(wd, hd, d)) == NULL)
1329 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1330 pixCopyResolution(pixd, pixs);
1331 pixScaleResolution(pixd, scalex, scaley);
1333 pixCopyText(pixd, pixs);
1334 pixCopyInputFormat(pixd, pixs);
1337 wpld = pixGetWpl(pixd);
1339 if (d == 32 && pixGetSpp(pixs) == 4)
1371 l_float32 scalex, scaley;
1374 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1375 if (wd <= 0 && hd <= 0)
1376 return (
PIX *)ERROR_PTR(
"neither wd nor hd > 0", __func__, NULL);
1380 scaley = (l_float32)hd / (l_float32)h;
1382 }
else if (hd <= 0) {
1383 scalex = (l_float32)wd / (l_float32)w;
1386 scalex = (l_float32)wd / (l_float32)w;
1387 scaley = (l_float32)hd / (l_float32)h;
1414 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1417 L_ERROR(
"factor must be >= 1; returning a copy\n", __func__);
1421 scale = 1. / (l_float32)factor;
1452 l_int32 byteval, shift;
1453 l_int32 i, j, ws, hs, wd, hd, wpls, wpld;
1454 l_uint32 *datas, *words, *datad, *lined;
1459 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1460 if (pixGetDepth(pixs) != 32)
1461 return (
PIX *)ERROR_PTR(
"depth not 32 bpp", __func__, NULL);
1463 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
1466 shift = L_RED_SHIFT;
1468 shift = L_GREEN_SHIFT;
1470 shift = L_BLUE_SHIFT;
1472 return (
PIX *)ERROR_PTR(
"invalid color", __func__, NULL);
1476 wpls = pixGetWpl(pixs);
1480 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1481 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1482 pixCopyResolution(pixd, pixs);
1483 pixCopyInputFormat(pixd, pixs);
1484 scale = 1. / (l_float32) factor;
1485 pixScaleResolution(pixd, scale, scale);
1487 wpld = pixGetWpl(pixd);
1489 for (i = 0; i < hd; i++) {
1490 words = datas + i * factor * wpls;
1491 lined = datad + i * wpld;
1492 for (j = 0; j < wd; j++, words += factor) {
1493 byteval = ((*words) >> shift) & 0xff;
1526 l_int32 i, j, ws, hs, wd, hd, wpls, wpld;
1527 l_uint32 *datas, *words, *datad, *lined;
1532 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1534 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
1535 if (pixGetDepth(pixs) != 32)
1536 return (
PIX *)ERROR_PTR(
"depth not 32 bpp", __func__, NULL);
1540 wpls = pixGetWpl(pixs);
1544 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
1545 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1546 pixCopyResolution(pixd, pixs);
1547 pixCopyInputFormat(pixd, pixs);
1548 scale = 1. / (l_float32) factor;
1549 pixScaleResolution(pixd, scale, scale);
1551 wpld = pixGetWpl(pixd);
1553 for (i = 0; i < hd; i++) {
1554 words = datas + i * factor * wpls;
1555 lined = datad + i * wpld;
1556 for (j = 0; j < wd; j++, words += factor) {
1557 byteval = ((*words) >> L_GREEN_SHIFT) & 0xff;
1558 if (byteval < thresh)
1590 l_int32 i, j, ws, hs, wd, hd, wpls, wpld, sj;
1591 l_uint32 *datas, *datad, *lines, *lined;
1596 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1598 return (
PIX *)ERROR_PTR(
"factor must be >= 1", __func__, NULL);
1599 if (pixGetDepth(pixs) != 8)
1600 return (
PIX *)ERROR_PTR(
"depth not 8 bpp", __func__, NULL);
1604 wpls = pixGetWpl(pixs);
1608 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
1609 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1610 pixCopyResolution(pixd, pixs);
1611 pixCopyInputFormat(pixd, pixs);
1612 scale = 1. / (l_float32) factor;
1613 pixScaleResolution(pixd, scale, scale);
1615 wpld = pixGetWpl(pixd);
1617 for (i = 0; i < hd; i++) {
1618 lines = datas + i * factor * wpls;
1619 lined = datad + i * wpld;
1620 for (j = 0, sj = 0; j < wd; j++, sj += factor) {
1622 if (byteval < thresh)
1669 l_int32 ws, hs, d, wd, hd, wpls, wpld, isize;
1671 l_uint32 *datas, *datad;
1672 l_float32 minscale, size;
1676 return (
PIX *)ERROR_PTR(
"pix not defined", __func__, NULL);
1677 if (scalex >= 0.7 || scaley >= 0.7) {
1678 L_WARNING(
"scaling factor not < 0.7; do regular scaling\n", __func__);
1681 d = pixGetDepth(pix);
1682 if (d != 2 && d != 4 && d !=8 && d != 32)
1683 return (
PIX *)ERROR_PTR(
"pix not 2, 4, 8 or 32 bpp", __func__, NULL);
1687 return (
PIX *)ERROR_PTR(
"pixs not made", __func__, NULL);
1688 d = pixGetDepth(pixs);
1693 minscale = L_MIN(scalex, scaley);
1694 size = 1.0 / minscale;
1695 isize = L_MIN(10000, L_MAX(2, (l_int32)(size + 0.5)));
1698 if ((ws < isize) || (hs < isize)) {
1702 L_WARNING(
"ridiculously small scaling factor %f\n", __func__, minscale);
1708 wpls = pixGetWpl(pixs);
1709 wd = L_MAX(1, (l_int32)(scalex * (l_float32)ws + 0.5));
1710 hd = L_MAX(1, (l_int32)(scaley * (l_float32)hs + 0.5));
1711 if ((pixd =
pixCreate(wd, hd, d)) == NULL) {
1713 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1715 pixCopyResolution(pixd, pixs);
1716 pixCopyInputFormat(pixd, pixs);
1717 pixScaleResolution(pixd, scalex, scaley);
1719 wpld = pixGetWpl(pixd);
1720 scaleSmoothLow(datad, wd, hd, wpld, datas, ws, hs, d, wpls, isize);
1721 if (d == 32 && pixGetSpp(pixs) == 4)
1754 l_float32 scalex, scaley;
1757 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1758 if (wd <= 0 && hd <= 0)
1759 return (
PIX *)ERROR_PTR(
"neither wd nor hd > 0", __func__, NULL);
1763 scaley = (l_float32)hd / (l_float32)h;
1765 }
else if (hd <= 0) {
1766 scalex = (l_float32)wd / (l_float32)w;
1769 scalex = (l_float32)wd / (l_float32)w;
1770 scaley = (l_float32)hd / (l_float32)h;
1790 l_int32 wd, hd, wpls, wpld;
1791 l_uint32 *datas, *datad;
1795 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
1796 if (pixGetDepth(pixs) != 32)
1797 return (
PIX *)ERROR_PTR(
"pixs not 32 bpp", __func__, NULL);
1798 if (rwt + gwt + bwt < 0.98 || rwt + gwt + bwt > 1.02)
1799 return (
PIX *)ERROR_PTR(
"sum of wts should be 1.0", __func__, NULL);
1801 wd = pixGetWidth(pixs) / 2;
1802 hd = pixGetHeight(pixs) / 2;
1803 wpls = pixGetWpl(pixs);
1805 if ((pixd =
pixCreate(wd, hd, 8)) == NULL)
1806 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1807 pixCopyResolution(pixd, pixs);
1808 pixCopyInputFormat(pixd, pixs);
1809 pixScaleResolution(pixd, 0.5, 0.5);
1810 wpld = pixGetWpl(pixd);
1868 l_int32 ws, hs, d, wd, hd, wpls, wpld;
1869 l_uint32 *datas, *datad;
1870 l_float32 maxscale, minscale;
1871 PIX *pixs, *pixd, *pix1, *pix2, *pix3;
1874 return (
PIX *)ERROR_PTR(
"pix not defined", __func__, NULL);
1875 d = pixGetDepth(pix);
1876 if (d != 2 && d != 4 && d != 8 && d != 32)
1877 return (
PIX *)ERROR_PTR(
"pix not 2, 4, 8 or 32 bpp", __func__, NULL);
1879 minscale = L_MIN(scalex, scaley);
1880 if (minscale < 0.02) {
1881 L_WARNING(
"tiny scaling factor; using pixScaleSmooth()\n", __func__);
1885 maxscale = L_MAX(scalex, scaley);
1886 if (maxscale >= 0.7) {
1887 L_WARNING(
"scaling factor >= 0.7; do regular scaling\n", __func__);
1892 if (scalex == 0.5 && scaley == 0.5)
1894 if (scalex == 0.25 && scaley == 0.25) {
1900 if (scalex == 0.125 && scaley == 0.125) {
1908 if (scalex == 0.0625 && scaley == 0.0625) {
1923 if (scalex > 0.35 && scalex < 0.5) {
1933 if ((d == 2 || d == 4 || d == 8) && pixGetColormap(pix)) {
1934 L_WARNING(
"pix has colormap; removing\n", __func__);
1936 d = pixGetDepth(pixs);
1937 }
else if (d == 2 || d == 4) {
1946 wpls = pixGetWpl(pixs);
1947 wd = (l_int32)(scalex * (l_float32)ws + 0.5);
1948 hd = (l_int32)(scaley * (l_float32)hs + 0.5);
1949 if (wd < 1 || hd < 1) {
1951 return (
PIX *)ERROR_PTR(
"pixd too small", __func__, NULL);
1953 if ((pixd =
pixCreate(wd, hd, d)) == NULL) {
1955 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
1957 pixCopyInputFormat(pixd, pixs);
1958 pixCopyResolution(pixd, pixs);
1959 pixScaleResolution(pixd, scalex, scaley);
1961 wpld = pixGetWpl(pixd);
1966 if (pixGetSpp(pixs) == 4)
1997 l_int32 wd, hd, d, wpls, wpld;
1998 l_uint32 *datas, *datad;
2002 return (
PIX *)ERROR_PTR(
"pix not defined", __func__, NULL);
2003 d = pixGetDepth(pix);
2004 if (d != 2 && d != 4 && d != 8 && d != 32)
2005 return (
PIX *)ERROR_PTR(
"pix not 2, 4, 8 or 32 bpp", __func__, NULL);
2009 if ((d == 2 || d == 4 || d == 8) && pixGetColormap(pix)) {
2010 L_WARNING(
"pix has colormap; removing\n", __func__);
2012 d = pixGetDepth(pixs);
2013 }
else if (d == 2 || d == 4) {
2020 wd = pixGetWidth(pixs) / 2;
2021 hd = pixGetHeight(pixs) / 2;
2023 wpls = pixGetWpl(pixs);
2026 wpld = pixGetWpl(pixd);
2027 pixCopyInputFormat(pixd, pixs);
2028 pixCopyResolution(pixd, pixs);
2029 pixScaleResolution(pixd, 0.5, 0.5);
2031 if (pixGetSpp(pixs) == 4)
2063 l_float32 scalex, scaley;
2066 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2067 if (wd <= 0 && hd <= 0)
2068 return (
PIX *)ERROR_PTR(
"neither wd nor hd > 0", __func__, NULL);
2072 scaley = (l_float32)hd / (l_float32)h;
2074 }
else if (hd <= 0) {
2075 scalex = (l_float32)wd / (l_float32)w;
2078 scalex = (l_float32)wd / (l_float32)w;
2079 scaley = (l_float32)hd / (l_float32)h;
2109 l_int32 ws, hs, wpls, wd, hd, wpld;
2110 l_uint32 *datas, *datad;
2114 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2115 if (pixGetDepth(pixs) != 1)
2116 return (
PIX *)ERROR_PTR(
"pixs must be 1 bpp", __func__, NULL);
2117 if (scalex <= 0.0 || scaley <= 0.0)
2118 return (
PIX *)ERROR_PTR(
"scale factor <= 0", __func__, NULL);
2119 if (scalex == 1.0 && scaley == 1.0)
2124 wpls = pixGetWpl(pixs);
2125 wd = (l_int32)(scalex * (l_float32)ws + 0.5);
2126 hd = (l_int32)(scaley * (l_float32)hs + 0.5);
2127 if ((pixd =
pixCreate(wd, hd, 1)) == NULL)
2128 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2130 pixCopyText(pixd, pixs);
2131 pixCopyInputFormat(pixd, pixs);
2132 pixCopyResolution(pixd, pixs);
2133 pixScaleResolution(pixd, scalex, scaley);
2135 wpld = pixGetWpl(pixd);
2136 scaleBinaryLow(datad, wd, hd, wpld, datas, ws, hs, wpls);
2170 l_int32 i, j, wm2, hm2;
2172 l_int32 xp, yp, xf, yf;
2173 l_uint32 v00r, v01r, v10r, v11r, v00g, v01g, v10g, v11g;
2174 l_uint32 v00b, v01b, v10b, v11b, area00, area01, area10, area11;
2175 l_uint32 pixels1, pixels2, pixels3, pixels4, pixel;
2176 l_uint32 *lines, *lined;
2183 scx = 16. * (l_float32)ws / (l_float32)wd;
2184 scy = 16. * (l_float32)hs / (l_float32)hd;
2189 for (i = 0; i < hd; i++) {
2190 ypm = (l_int32)(scy * (l_float32)i);
2193 lined = datad + i * wpld;
2194 lines = datas + yp * wpls;
2195 for (j = 0; j < wd; j++) {
2196 xpm = (l_int32)(scx * (l_float32)j);
2205 pixels1 = *(lines + xp);
2207 if (xp > wm2 || yp > hm2) {
2208 if (yp > hm2 && xp <= wm2) {
2209 pixels2 = *(lines + xp + 1);
2212 }
else if (xp > wm2 && yp <= hm2) {
2214 pixels3 = *(lines + wpls + xp);
2217 pixels4 = pixels3 = pixels2 = pixels1;
2220 pixels2 = *(lines + xp + 1);
2221 pixels3 = *(lines + wpls + xp);
2222 pixels4 = *(lines + wpls + xp + 1);
2225 area00 = (16 - xf) * (16 - yf);
2226 area10 = xf * (16 - yf);
2227 area01 = (16 - xf) * yf;
2229 v00r = area00 * ((pixels1 >> L_RED_SHIFT) & 0xff);
2230 v00g = area00 * ((pixels1 >> L_GREEN_SHIFT) & 0xff);
2231 v00b = area00 * ((pixels1 >> L_BLUE_SHIFT) & 0xff);
2232 v10r = area10 * ((pixels2 >> L_RED_SHIFT) & 0xff);
2233 v10g = area10 * ((pixels2 >> L_GREEN_SHIFT) & 0xff);
2234 v10b = area10 * ((pixels2 >> L_BLUE_SHIFT) & 0xff);
2235 v01r = area01 * ((pixels3 >> L_RED_SHIFT) & 0xff);
2236 v01g = area01 * ((pixels3 >> L_GREEN_SHIFT) & 0xff);
2237 v01b = area01 * ((pixels3 >> L_BLUE_SHIFT) & 0xff);
2238 v11r = area11 * ((pixels4 >> L_RED_SHIFT) & 0xff);
2239 v11g = area11 * ((pixels4 >> L_GREEN_SHIFT) & 0xff);
2240 v11b = area11 * ((pixels4 >> L_BLUE_SHIFT) & 0xff);
2241 pixel = (((v00r + v10r + v01r + v11r + 128) << 16) & 0xff000000) |
2242 (((v00g + v10g + v01g + v11g + 128) << 8) & 0x00ff0000) |
2243 ((v00b + v10b + v01b + v11b + 128) & 0x0000ff00);
2244 *(lined + j) = pixel;
2275 l_int32 i, j, wm2, hm2;
2277 l_int32 xp, yp, xf, yf;
2278 l_int32 v00, v01, v10, v11, v00_val, v01_val, v10_val, v11_val;
2280 l_uint32 *lines, *lined;
2287 scx = 16. * (l_float32)ws / (l_float32)wd;
2288 scy = 16. * (l_float32)hs / (l_float32)hd;
2293 for (i = 0; i < hd; i++) {
2294 ypm = (l_int32)(scy * (l_float32)i);
2297 lined = datad + i * wpld;
2298 lines = datas + yp * wpls;
2299 for (j = 0; j < wd; j++) {
2300 xpm = (l_int32)(scx * (l_float32)j);
2309 if (xp > wm2 || yp > hm2) {
2310 if (yp > hm2 && xp <= wm2) {
2314 }
else if (xp > wm2 && yp <= hm2) {
2319 v10_val = v01_val = v11_val = v00_val;
2327 v00 = (16 - xf) * (16 - yf) * v00_val;
2328 v10 = xf * (16 - yf) * v10_val;
2329 v01 = (16 - xf) * yf * v01_val;
2330 v11 = xf * yf * v11_val;
2332 val = (l_uint8)((v00 + v01 + v10 + v11 + 128) / 256);
2391 l_uint32 *lines, *lined;
2406 for (i = 0; i < hsm; i++) {
2407 lines = datas + i * wpls;
2408 lined = datad + 2 * i * wpld;
2413 lines = datas + hsm * wpls;
2414 lined = datad + 2 * hsm * wpld;
2436 l_int32 lastlineflag)
2439 l_uint32 rval1, rval2, rval3, rval4, gval1, gval2, gval3, gval4;
2440 l_uint32 bval1, bval2, bval3, bval4;
2441 l_uint32 pixels1, pixels2, pixels3, pixels4, pixel;
2442 l_uint32 *linesp, *linedp;
2446 if (lastlineflag == 0) {
2447 linesp = lines + wpls;
2448 linedp = lined + wpld;
2453 rval2 = pixels1 >> 24;
2454 gval2 = (pixels1 >> 16) & 0xff;
2455 bval2 = (pixels1 >> 8) & 0xff;
2456 rval4 = pixels3 >> 24;
2457 gval4 = (pixels3 >> 16) & 0xff;
2458 bval4 = (pixels3 >> 8) & 0xff;
2460 for (j = 0, jd = 0; j < wsm; j++, jd += 2) {
2469 pixels2 = *(lines + j + 1);
2470 pixels4 = *(linesp + j + 1);
2471 rval2 = pixels2 >> 24;
2472 gval2 = (pixels2 >> 16) & 0xff;
2473 bval2 = (pixels2 >> 8) & 0xff;
2474 rval4 = pixels4 >> 24;
2475 gval4 = (pixels4 >> 16) & 0xff;
2476 bval4 = (pixels4 >> 8) & 0xff;
2478 pixel = (rval1 << 24 | gval1 << 16 | bval1 << 8);
2479 *(lined + jd) = pixel;
2480 pixel = ((((rval1 + rval2) << 23) & 0xff000000) |
2481 (((gval1 + gval2) << 15) & 0x00ff0000) |
2482 (((bval1 + bval2) << 7) & 0x0000ff00));
2483 *(lined + jd + 1) = pixel;
2484 pixel = ((((rval1 + rval3) << 23) & 0xff000000) |
2485 (((gval1 + gval3) << 15) & 0x00ff0000) |
2486 (((bval1 + bval3) << 7) & 0x0000ff00));
2487 *(linedp + jd) = pixel;
2488 pixel = ((((rval1 + rval2 + rval3 + rval4) << 22) & 0xff000000) |
2489 (((gval1 + gval2 + gval3 + gval4) << 14) & 0x00ff0000) |
2490 (((bval1 + bval2 + bval3 + bval4) << 6) & 0x0000ff00));
2491 *(linedp + jd + 1) = pixel;
2500 pixel = (rval1 << 24 | gval1 << 16 | bval1 << 8);
2501 *(lined + 2 * wsm) = pixel;
2502 *(lined + 2 * wsm + 1) = pixel;
2503 pixel = ((((rval1 + rval3) << 23) & 0xff000000) |
2504 (((gval1 + gval3) << 15) & 0x00ff0000) |
2505 (((bval1 + bval3) << 7) & 0x0000ff00));
2506 *(linedp + 2 * wsm) = pixel;
2507 *(linedp + 2 * wsm + 1) = pixel;
2509 linedp = lined + wpld;
2511 rval2 = pixels2 >> 24;
2512 gval2 = (pixels2 >> 16) & 0xff;
2513 bval2 = (pixels2 >> 8) & 0xff;
2514 for (j = 0, jd = 0; j < wsm; j++, jd += 2) {
2518 pixels2 = *(lines + j + 1);
2519 rval2 = pixels2 >> 24;
2520 gval2 = (pixels2 >> 16) & 0xff;
2521 bval2 = (pixels2 >> 8) & 0xff;
2522 pixel = (rval1 << 24 | gval1 << 16 | bval1 << 8);
2523 *(lined + jd) = pixel;
2524 *(linedp + jd) = pixel;
2525 pixel = ((((rval1 + rval2) << 23) & 0xff000000) |
2526 (((gval1 + gval2) << 15) & 0x00ff0000) |
2527 (((bval1 + bval2) << 7) & 0x0000ff00));
2528 *(lined + jd + 1) = pixel;
2529 *(linedp + jd + 1) = pixel;
2534 pixel = (rval1 << 24 | gval1 << 16 | bval1 << 8);
2535 *(lined + 2 * wsm) = pixel;
2536 *(lined + 2 * wsm + 1) = pixel;
2537 *(linedp + 2 * wsm) = pixel;
2538 *(linedp + 2 * wsm + 1) = pixel;
2593 l_uint32 *lines, *lined;
2608 for (i = 0; i < hsm; i++) {
2609 lines = datas + i * wpls;
2610 lined = datad + 2 * i * wpld;
2615 lines = datas + hsm * wpls;
2616 lined = datad + 2 * hsm * wpld;
2638 l_int32 lastlineflag)
2640 l_int32 j, jd, wsm, w;
2641 l_uint32 sval1, sval2, sval3, sval4;
2642 l_uint32 *linesp, *linedp;
2643 l_uint32 words, wordsp, wordd, worddp;
2647 if (lastlineflag == 0) {
2648 linesp = lines + wpls;
2649 linedp = lined + wpld;
2654 sval2 = (words >> 24) & 0xff;
2655 sval4 = (wordsp >> 24) & 0xff;
2656 for (j = 0, jd = 0, w = 0; j + 3 < wsm; j += 4, jd += 8, w++) {
2662 sval2 = (words >> 16) & 0xff;
2664 sval4 = (wordsp >> 16) & 0xff;
2665 wordd = (sval1 << 24) | (((sval1 + sval2) >> 1) << 16);
2666 worddp = (((sval1 + sval3) >> 1) << 24) |
2667 (((sval1 + sval2 + sval3 + sval4) >> 2) << 16);
2670 sval2 = (words >> 8) & 0xff;
2672 sval4 = (wordsp >> 8) & 0xff;
2673 wordd |= (sval1 << 8) | ((sval1 + sval2) >> 1);
2674 worddp |= (((sval1 + sval3) >> 1) << 8) |
2675 ((sval1 + sval2 + sval3 + sval4) >> 2);
2676 lined[w * 2] = wordd;
2677 linedp[w * 2] = worddp;
2680 sval2 = words & 0xff;
2682 sval4 = wordsp & 0xff;
2683 wordd = (sval1 << 24) |
2684 (((sval1 + sval2) >> 1) << 16);
2685 worddp = (((sval1 + sval3) >> 1) << 24) |
2686 (((sval1 + sval2 + sval3 + sval4) >> 2) << 16);
2689 words = lines[w + 1];
2690 wordsp = linesp[w + 1];
2692 sval2 = (words >> 24) & 0xff;
2694 sval4 = (wordsp >> 24) & 0xff;
2695 wordd |= (sval1 << 8) |
2696 ((sval1 + sval2) >> 1);
2697 worddp |= (((sval1 + sval3) >> 1) << 8) |
2698 ((sval1 + sval2 + sval3 + sval4) >> 2);
2699 lined[w * 2 + 1] = wordd;
2700 linedp[w * 2 + 1] = worddp;
2704 for (; j < wsm; j++, jd += 2) {
2713 (sval1 + sval2 + sval3 + sval4) / 4);
2723 #define CHECK_BYTE(a, b, c) if (GET_DATA_BYTE(a, b) != c) {\
2724 lept_stderr("Error: mismatch at %d, %d vs %d\n", \
2725 j, GET_DATA_BYTE(a, b), c); }
2729 for (j = 0, jd = 0; j < wsm; j++, jd += 2) {
2734 CHECK_BYTE(lined, jd, sval1);
2735 CHECK_BYTE(lined, jd + 1, (sval1 + sval2) / 2);
2736 CHECK_BYTE(linedp, jd, (sval1 + sval3) / 2);
2737 CHECK_BYTE(linedp, jd + 1,
2738 (sval1 + sval2 + sval3 + sval4) / 4);
2742 CHECK_BYTE(lined, 2 * wsm, sval1);
2743 CHECK_BYTE(lined, 2 * wsm + 1, sval1);
2744 CHECK_BYTE(linedp, 2 * wsm, (sval1 + sval3) / 2);
2745 CHECK_BYTE(linedp, 2 * wsm + 1, (sval1 + sval3) / 2);
2749 linedp = lined + wpld;
2751 for (j = 0, jd = 0; j < wsm; j++, jd += 2) {
2834 l_uint32 *lines, *lined;
2847 for (i = 0; i < hsm; i++) {
2848 lines = datas + i * wpls;
2849 lined = datad + 4 * i * wpld;
2854 lines = datas + hsm * wpls;
2855 lined = datad + 4 * hsm * wpld;
2877 l_int32 lastlineflag)
2879 l_int32 j, jd, wsm, wsm4;
2880 l_int32 s1, s2, s3, s4, s1t, s2t, s3t, s4t;
2881 l_uint32 *linesp, *linedp1, *linedp2, *linedp3;
2886 if (lastlineflag == 0) {
2887 linesp = lines + wpls;
2888 linedp1 = lined + wpld;
2889 linedp2 = lined + 2 * wpld;
2890 linedp3 = lined + 3 * wpld;
2893 for (j = 0, jd = 0; j < wsm; j++, jd += 4) {
2907 SET_DATA_BYTE(linedp1, jd + 1, (9*s1 + s2t + s3t + s4) / 16);
2909 SET_DATA_BYTE(linedp1, jd + 3, (s1t + 9*s2 + s3 + s4t) / 16);
2915 SET_DATA_BYTE(linedp3, jd + 1, (s1t + s2 + 9*s3 + s4t) / 16);
2917 SET_DATA_BYTE(linedp3, jd + 3, (s1 + s2t + s3t + 9*s4) / 16);
2940 linedp1 = lined + wpld;
2941 linedp2 = lined + 2 * wpld;
2942 linedp3 = lined + 3 * wpld;
2944 for (j = 0, jd = 0; j < wsm; j++, jd += 4) {
3017 l_int32 xs, prevxs, sval;
3018 l_int32 *srow, *scol;
3020 l_uint32 *lines, *prevlines, *lined, *prevlined;
3021 l_float32 wratio, hratio;
3023 if (d != 2 && d != 4 && d !=8 && d != 16 && d != 32)
3024 return ERROR_INT(
"pixel depth not supported", __func__, 1);
3027 memset(datad, 0, 4LL * hd * wpld);
3031 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
3032 return ERROR_INT(
"srow not made", __func__, 1);
3033 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
3035 return ERROR_INT(
"scol not made", __func__, 1);
3038 wratio = (l_float32)ws / (l_float32)wd;
3039 hratio = (l_float32)hs / (l_float32)hd;
3040 for (i = 0; i < hd; i++)
3041 srow[i] = L_MIN((l_int32)(hratio * i + 0.5), hs - 1);
3042 for (j = 0; j < wd; j++)
3043 scol[j] = L_MIN((l_int32)(wratio * j + 0.5), ws - 1);
3046 for (i = 0; i < hd; i++) {
3047 lines = datas + srow[i] * wpls;
3048 lined = datad + i * wpld;
3049 if (lines != prevlines) {
3054 for (j = 0; j < wd; j++) {
3064 }
else if (d == 4) {
3065 for (j = 0; j < wd; j++) {
3075 }
else if (d == 8) {
3076 for (j = 0; j < wd; j++) {
3086 }
else if (d == 16) {
3087 for (j = 0; j < wd; j++) {
3098 for (j = 0; j < wd; j++) {
3110 prevlined = lined - wpld;
3111 memcpy(lined, prevlined, 4 * wpld);
3148 l_int32 i, j, m, n, xstart;
3149 l_int32 val, rval, gval, bval;
3150 l_int32 *srow, *scol;
3151 l_uint32 *lines, *lined, *line, *ppixel;
3153 l_float32 wratio, hratio, norm;
3156 memset(datad, 0, 4LL * wpld * hd);
3163 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
3164 return ERROR_INT(
"srow not made", __func__, 1);
3165 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
3167 return ERROR_INT(
"scol not made", __func__, 1);
3170 norm = 1. / (l_float32)(size * size);
3171 wratio = (l_float32)ws / (l_float32)wd;
3172 hratio = (l_float32)hs / (l_float32)hd;
3173 for (i = 0; i < hd; i++)
3174 srow[i] = L_MIN((l_int32)(hratio * i), hs - size);
3175 for (j = 0; j < wd; j++)
3176 scol[j] = L_MIN((l_int32)(wratio * j), ws - size);
3180 for (i = 0; i < hd; i++) {
3181 lines = datas + srow[i] * wpls;
3182 lined = datad + i * wpld;
3183 for (j = 0; j < wd; j++) {
3186 for (m = 0; m < size; m++) {
3187 line = lines + m * wpls;
3188 for (n = 0; n < size; n++) {
3192 val = (l_int32)((l_float32)val * norm);
3197 for (i = 0; i < hd; i++) {
3198 lines = datas + srow[i] * wpls;
3199 lined = datad + i * wpld;
3200 for (j = 0; j < wd; j++) {
3202 rval = gval = bval = 0;
3203 for (m = 0; m < size; m++) {
3204 ppixel = lines + m * wpls + xstart;
3205 for (n = 0; n < size; n++) {
3206 pixel = *(ppixel + n);
3207 rval += (pixel >> L_RED_SHIFT) & 0xff;
3208 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3209 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3212 rval = (l_int32)((l_float32)rval * norm);
3213 gval = (l_int32)((l_float32)gval * norm);
3214 bval = (l_int32)((l_float32)bval * norm);
3246 l_int32 i, j, val, rval, gval, bval;
3247 l_uint32 *lines, *lined;
3253 for (i = 0; i < hd; i++) {
3254 lines = datas + 2 * i * wpls;
3255 lined = datad + i * wpld;
3256 for (j = 0; j < wd; j++) {
3258 pixel = *(lines + 2 * j);
3259 rval = (pixel >> L_RED_SHIFT) & 0xff;
3260 gval = (pixel >> L_GREEN_SHIFT) & 0xff;
3261 bval = (pixel >> L_BLUE_SHIFT) & 0xff;
3262 pixel = *(lines + 2 * j + 1);
3263 rval += (pixel >> L_RED_SHIFT) & 0xff;
3264 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3265 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3266 pixel = *(lines + wpls + 2 * j);
3267 rval += (pixel >> L_RED_SHIFT) & 0xff;
3268 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3269 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3270 pixel = *(lines + wpls + 2 * j + 1);
3271 rval += (pixel >> L_RED_SHIFT) & 0xff;
3272 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3273 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3275 val = (l_int32)(rwt * rval + gwt * gval + bwt * bval);
3310 l_int32 i, j, k, m, wm2, hm2;
3311 l_int32 area00, area10, area01, area11, areal, arear, areat, areab;
3314 l_int32 xup, yup, xuf, yuf;
3315 l_int32 xlp, ylp, xlf, ylf;
3316 l_int32 delx, dely, area;
3317 l_int32 v00r, v00g, v00b;
3318 l_int32 v01r, v01g, v01b;
3319 l_int32 v10r, v10g, v10b;
3320 l_int32 v11r, v11g, v11b;
3321 l_int32 vinr, ving, vinb;
3322 l_int32 vmidr, vmidg, vmidb;
3323 l_int32 rval, gval, bval;
3324 l_uint32 pixel00, pixel10, pixel01, pixel11, pixel;
3325 l_uint32 *lines, *lined;
3332 scx = 16. * (l_float32)ws / (l_float32)wd;
3333 scy = 16. * (l_float32)hs / (l_float32)hd;
3338 for (i = 0; i < hd; i++) {
3339 yu = (l_int32)(scy * i);
3340 yl = (l_int32)(scy * (i + 1.0));
3346 lined = datad + i * wpld;
3347 lines = datas + yup * wpls;
3348 for (j = 0; j < wd; j++) {
3349 xu = (l_int32)(scx * j);
3350 xl = (l_int32)(scx * (j + 1.0));
3358 if (xlp > wm2 || ylp > hm2) {
3359 *(lined + j) = *(lines + xup);
3366 area = ((16 - xuf) + 16 * (delx - 1) + xlf) *
3367 ((16 - yuf) + 16 * (dely - 1) + ylf);
3370 pixel00 = *(lines + xup);
3371 pixel10 = *(lines + xlp);
3372 pixel01 = *(lines + dely * wpls + xup);
3373 pixel11 = *(lines + dely * wpls + xlp);
3374 area00 = (16 - xuf) * (16 - yuf);
3375 area10 = xlf * (16 - yuf);
3376 area01 = (16 - xuf) * ylf;
3378 v00r = area00 * ((pixel00 >> L_RED_SHIFT) & 0xff);
3379 v00g = area00 * ((pixel00 >> L_GREEN_SHIFT) & 0xff);
3380 v00b = area00 * ((pixel00 >> L_BLUE_SHIFT) & 0xff);
3381 v10r = area10 * ((pixel10 >> L_RED_SHIFT) & 0xff);
3382 v10g = area10 * ((pixel10 >> L_GREEN_SHIFT) & 0xff);
3383 v10b = area10 * ((pixel10 >> L_BLUE_SHIFT) & 0xff);
3384 v01r = area01 * ((pixel01 >> L_RED_SHIFT) & 0xff);
3385 v01g = area01 * ((pixel01 >> L_GREEN_SHIFT) & 0xff);
3386 v01b = area01 * ((pixel01 >> L_BLUE_SHIFT) & 0xff);
3387 v11r = area11 * ((pixel11 >> L_RED_SHIFT) & 0xff);
3388 v11g = area11 * ((pixel11 >> L_GREEN_SHIFT) & 0xff);
3389 v11b = area11 * ((pixel11 >> L_BLUE_SHIFT) & 0xff);
3390 vinr = ving = vinb = 0;
3391 for (k = 1; k < dely; k++) {
3392 for (m = 1; m < delx; m++) {
3393 pixel = *(lines + k * wpls + xup + m);
3394 vinr += 256 * ((pixel >> L_RED_SHIFT) & 0xff);
3395 ving += 256 * ((pixel >> L_GREEN_SHIFT) & 0xff);
3396 vinb += 256 * ((pixel >> L_BLUE_SHIFT) & 0xff);
3399 vmidr = vmidg = vmidb = 0;
3400 areal = (16 - xuf) * 16;
3402 areat = 16 * (16 - yuf);
3404 for (k = 1; k < dely; k++) {
3405 pixel = *(lines + k * wpls + xup);
3406 vmidr += areal * ((pixel >> L_RED_SHIFT) & 0xff);
3407 vmidg += areal * ((pixel >> L_GREEN_SHIFT) & 0xff);
3408 vmidb += areal * ((pixel >> L_BLUE_SHIFT) & 0xff);
3410 for (k = 1; k < dely; k++) {
3411 pixel = *(lines + k * wpls + xlp);
3412 vmidr += arear * ((pixel >> L_RED_SHIFT) & 0xff);
3413 vmidg += arear * ((pixel >> L_GREEN_SHIFT) & 0xff);
3414 vmidb += arear * ((pixel >> L_BLUE_SHIFT) & 0xff);
3416 for (m = 1; m < delx; m++) {
3417 pixel = *(lines + xup + m);
3418 vmidr += areat * ((pixel >> L_RED_SHIFT) & 0xff);
3419 vmidg += areat * ((pixel >> L_GREEN_SHIFT) & 0xff);
3420 vmidb += areat * ((pixel >> L_BLUE_SHIFT) & 0xff);
3422 for (m = 1; m < delx; m++) {
3423 pixel = *(lines + dely * wpls + xup + m);
3424 vmidr += areab * ((pixel >> L_RED_SHIFT) & 0xff);
3425 vmidg += areab * ((pixel >> L_GREEN_SHIFT) & 0xff);
3426 vmidb += areab * ((pixel >> L_BLUE_SHIFT) & 0xff);
3430 rval = (v00r + v01r + v10r + v11r + vinr + vmidr + 128) / area;
3431 gval = (v00g + v01g + v10g + v11g + ving + vmidg + 128) / area;
3432 bval = (v00b + v01b + v10b + v11b + vinb + vmidb + 128) / area;
3434 if (rval > 255)
lept_stderr(
"rval ovfl: %d\n", rval);
3435 if (gval > 255)
lept_stderr(
"gval ovfl: %d\n", gval);
3436 if (bval > 255)
lept_stderr(
"bval ovfl: %d\n", bval);
3468 l_int32 i, j, k, m, wm2, hm2;
3471 l_int32 xup, yup, xuf, yuf;
3472 l_int32 xlp, ylp, xlf, ylf;
3473 l_int32 delx, dely, area;
3481 l_uint32 *lines, *lined;
3488 scx = 16. * (l_float32)ws / (l_float32)wd;
3489 scy = 16. * (l_float32)hs / (l_float32)hd;
3494 for (i = 0; i < hd; i++) {
3495 yu = (l_int32)(scy * i);
3496 yl = (l_int32)(scy * (i + 1.0));
3502 lined = datad + i * wpld;
3503 lines = datas + yup * wpls;
3504 for (j = 0; j < wd; j++) {
3505 xu = (l_int32)(scx * j);
3506 xl = (l_int32)(scx * (j + 1.0));
3514 if (xlp > wm2 || ylp > hm2) {
3522 area = ((16 - xuf) + 16 * (delx - 1) + xlf) *
3523 ((16 - yuf) + 16 * (dely - 1) + ylf);
3528 v01 = (16 - xuf) * ylf *
GET_DATA_BYTE(lines + dely * wpls, xup);
3530 for (vin = 0, k = 1; k < dely; k++) {
3531 for (m = 1; m < delx; m++) {
3535 for (vmid = 0, k = 1; k < dely; k++)
3536 vmid += (16 - xuf) * 16 *
GET_DATA_BYTE(lines + k * wpls, xup);
3537 for (k = 1; k < dely; k++)
3539 for (m = 1; m < delx; m++)
3541 for (m = 1; m < delx; m++)
3542 vmid += 16 * ylf *
GET_DATA_BYTE(lines + dely * wpls, xup + m);
3543 val = (v00 + v01 + v10 + v11 + vin + vmid + 128) / area;
3545 if (val > 255)
lept_stderr(
"val overflow: %d\n", val);
3574 l_int32 i, j, val, rval, gval, bval;
3575 l_uint32 *lines, *lined;
3579 for (i = 0; i < hd; i++) {
3580 lines = datas + 2 * i * wpls;
3581 lined = datad + i * wpld;
3582 for (j = 0; j < wd; j++) {
3593 for (i = 0; i < hd; i++) {
3594 lines = datas + 2 * i * wpls;
3595 lined = datad + i * wpld;
3596 for (j = 0; j < wd; j++) {
3598 pixel = *(lines + 2 * j);
3599 rval = (pixel >> L_RED_SHIFT) & 0xff;
3600 gval = (pixel >> L_GREEN_SHIFT) & 0xff;
3601 bval = (pixel >> L_BLUE_SHIFT) & 0xff;
3602 pixel = *(lines + 2 * j + 1);
3603 rval += (pixel >> L_RED_SHIFT) & 0xff;
3604 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3605 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3606 pixel = *(lines + wpls + 2 * j);
3607 rval += (pixel >> L_RED_SHIFT) & 0xff;
3608 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3609 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3610 pixel = *(lines + wpls + 2 * j + 1);
3611 rval += (pixel >> L_RED_SHIFT) & 0xff;
3612 gval += (pixel >> L_GREEN_SHIFT) & 0xff;
3613 bval += (pixel >> L_BLUE_SHIFT) & 0xff;
3615 *(lined + j) = pixel;
3638 scaleBinaryLow(l_uint32 *datad,
3648 l_int32 xs, prevxs, sval;
3649 l_int32 *srow, *scol;
3650 l_uint32 *lines, *prevlines, *lined, *prevlined;
3651 l_float32 wratio, hratio;
3654 memset(datad, 0, 4LL * hd * wpld);
3658 if ((srow = (l_int32 *)LEPT_CALLOC(hd,
sizeof(l_int32))) == NULL)
3659 return ERROR_INT(
"srow not made", __func__, 1);
3660 if ((scol = (l_int32 *)LEPT_CALLOC(wd,
sizeof(l_int32))) == NULL) {
3662 return ERROR_INT(
"scol not made", __func__, 1);
3665 wratio = (l_float32)ws / (l_float32)wd;
3666 hratio = (l_float32)hs / (l_float32)hd;
3667 for (i = 0; i < hd; i++)
3668 srow[i] = L_MIN((l_int32)(hratio * i + 0.5), hs - 1);
3669 for (j = 0; j < wd; j++)
3670 scol[j] = L_MIN((l_int32)(wratio * j + 0.5), ws - 1);
3675 for (i = 0; i < hd; i++) {
3676 lines = datas + srow[i] * wpls;
3677 lined = datad + i * wpld;
3678 if (lines != prevlines) {
3679 for (j = 0; j < wd; j++) {
3691 prevlined = lined - wpld;
3692 memcpy(lined, prevlined, 4 * wpld);
#define GET_DATA_QBIT(pdata, n)
#define GET_DATA_TWO_BYTES(pdata, n)
#define SET_DATA_BIT(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 GET_DATA_BIT(pdata, n)
#define SET_DATA_QBIT(pdata, n, val)
PIX * pixUnsharpMasking(PIX *pixs, l_int32 halfwidth, l_float32 fract)
pixUnsharpMasking()
void ditherToBinaryLineLow(l_uint32 *lined, l_int32 w, l_uint32 *bufs1, l_uint32 *bufs2, l_int32 lowerclip, l_int32 upperclip, l_int32 lastlineflag)
ditherToBinaryLineLow()
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()
l_ok pixCopySpp(PIX *pixd, const PIX *pixs)
pixCopySpp()
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()
PIX * pixGetRGBComponent(PIX *pixs, l_int32 comp)
pixGetRGBComponent()
l_ok pixSetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 val)
pixSetPixel()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
PIX * pixCreateRGBImage(PIX *pixr, PIX *pixg, PIX *pixb)
pixCreateRGBImage()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
@ REMOVE_CMAP_BASED_ON_SRC
PIX * pixConvertTo8Or32(PIX *pixs, l_int32 copyflag, l_int32 warnflag)
pixConvertTo8Or32()
PIX * pixRemoveColormap(PIX *pixs, l_int32 type)
pixRemoveColormap()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
static l_int32 scaleBySamplingLow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls)
scaleBySamplingLow()
PIX * pixScaleToResolution(PIX *pixs, l_float32 target, l_float32 assumed, l_float32 *pscalefact)
pixScaleToResolution()
PIX * pixScaleRGBToGrayFast(PIX *pixs, l_int32 factor, l_int32 color)
pixScaleRGBToGrayFast()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
static void scaleAreaMapLow2(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls)
scaleAreaMapLow2()
PIX * pixScaleGray4xLIThresh(PIX *pixs, l_int32 thresh)
pixScaleGray4xLIThresh()
static void scaleGray4xLILineLow(l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag)
scaleGray4xLILineLow()
static void scaleGray2xLILineLow(l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag)
scaleGray2xLILineLow()
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 * pixScaleColor2xLI(PIX *pixs)
pixScaleColor2xLI()
PIX * pixScaleRGBToGray2(PIX *pixs, l_float32 rwt, l_float32 gwt, l_float32 bwt)
pixScaleRGBToGray2()
PIX * pixScaleColor4xLI(PIX *pixs)
pixScaleColor4xLI()
static void scaleColorAreaMapLow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleColorAreaMapLow()
static void scaleGrayLILow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleGrayLILow()
PIX * pixScaleAreaMap(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleAreaMap()
PIX * pixScaleRGBToBinaryFast(PIX *pixs, l_int32 factor, l_int32 thresh)
pixScaleRGBToBinaryFast()
PIX * pixScaleToSizeRel(PIX *pixs, l_int32 delw, l_int32 delh)
pixScaleToSizeRel()
PIX * pixScaleToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleToSize()
PIX * pixScaleLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleLI()
static void scaleColorLILow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleColorLILow()
PIX * pixScaleGray2xLI(PIX *pixs)
pixScaleGray2xLI()
PIX * pixScaleBinary(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBinary()
static l_int32 scaleSmoothLow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls, l_int32 size)
scaleSmoothLow()
PIX * pixScaleGrayToBinaryFast(PIX *pixs, l_int32 factor, l_int32 thresh)
pixScaleGrayToBinaryFast()
PIX * pixScaleSmooth(PIX *pix, l_float32 scalex, l_float32 scaley)
pixScaleSmooth()
PIX * pixScaleGray2xLIThresh(PIX *pixs, l_int32 thresh)
pixScaleGray2xLIThresh()
PIX * pixScaleAreaMap2(PIX *pix)
pixScaleAreaMap2()
static void scaleColor2xLILow(l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleColor2xLILow()
static void scaleGray4xLILow(l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleGray4xLILow()
PIX * pixScaleBySamplingToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleBySamplingToSize()
PIX * pixScaleAreaMapToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleAreaMapToSize()
PIX * pixScaleGray4xLI(PIX *pixs)
pixScaleGray4xLI()
PIX * pixScaleByIntSampling(PIX *pixs, l_int32 factor)
pixScaleByIntSampling()
static void scaleRGBToGray2Low(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_float32 rwt, l_float32 gwt, l_float32 bwt)
scaleRGBToGray2Low()
static void scaleGray2xLILow(l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleGray2xLILow()
static void scaleGrayAreaMapLow(l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls)
scaleGrayAreaMapLow()
PIX * pixScaleColorLI(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleColorLI()
PIX * pixScaleSmoothToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleSmoothToSize()
static void scaleColor2xLILineLow(l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag)
scaleColor2xLILineLow()
PIX * pixScaleGray4xLIDither(PIX *pixs)
pixScaleGray4xLIDither()
PIX * pixScaleBySampling(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleBySampling()
PIX * pixScaleGray2xLIDither(PIX *pixs)
pixScaleGray2xLIDither()
l_ok pixScaleAndTransferAlpha(PIX *pixd, PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScaleAndTransferAlpha()
void lept_stderr(const char *fmt,...)
lept_stderr()