118#include <config_auto.h>
123#include "allheaders.h"
146l_int32 npts, diff, getyofx, sign, i, x, y;
151 if (x1 == x2 && y1 == y2) {
154 }
else if (L_ABS(x2 - x1) >= L_ABS(y2 - y1)) {
156 npts = L_ABS(x2 - x1) + 1;
158 sign = L_SIGN(x2 - x1);
159 slope = (l_float32)(sign * (y2 - y1)) / (l_float32)diff;
162 npts = L_ABS(y2 - y1) + 1;
164 sign = L_SIGN(y2 - y1);
165 slope = (l_float32)(sign * (x2 - x1)) / (l_float32)diff;
168 if ((pta = ptaCreate(npts)) == NULL)
169 return (
PTA *)ERROR_PTR(
"pta not made", __func__, NULL);
172 ptaAddPt(pta, x1, y1);
178 for (i = 0; i < npts; i++) {
180 y = (l_int32)(y1 + (l_float32)i * slope + 0.5);
184 for (i = 0; i < npts; i++) {
185 x = (l_int32)(x1 + (l_float32)i * slope + 0.5);
210l_int32 i, x1a, x2a, y1a, y2a;
214 L_WARNING(
"width < 1; setting to 1\n", __func__);
219 return (
PTA *)ERROR_PTR(
"ptaj not made", __func__, NULL);
224 if (L_ABS(x1 - x2) > L_ABS(y1 - y2)) {
225 for (i = 1; i < width; i++) {
227 y1a = y1 - (i + 1) / 2;
228 y2a = y2 - (i + 1) / 2;
230 y1a = y1 + (i + 1) / 2;
231 y2a = y2 + (i + 1) / 2;
234 ptaJoin(ptaj, pta, 0, -1);
239 for (i = 1; i < width; i++) {
241 x1a = x1 - (i + 1) / 2;
242 x2a = x2 - (i + 1) / 2;
244 x1a = x1 + (i + 1) / 2;
245 x2a = x2 + (i + 1) / 2;
248 ptaJoin(ptaj, pta, 0, -1);
279 return (
PTA *)ERROR_PTR(
"box not defined", __func__, NULL);
281 L_WARNING(
"width < 1; setting to 1\n", __func__);
286 boxGetGeometry(box, &x, &y, &w, &h);
287 if (w == 0 || h == 0)
288 return (
PTA *)ERROR_PTR(
"box has w = 0 or h = 0", __func__, NULL);
290 if ((width & 1) == 1) {
292 x + w - 1 + width / 2, y, width);
293 ptaJoin(ptad, pta, 0, -1);
296 x + w - 1, y + h - 2 - width / 2, width);
297 ptaJoin(ptad, pta, 0, -1);
300 x - width / 2, y + h - 1, width);
301 ptaJoin(ptad, pta, 0, -1);
304 x, y + 1 + width / 2, width);
305 ptaJoin(ptad, pta, 0, -1);
309 x + w - 2 + width / 2, y, width);
310 ptaJoin(ptad, pta, 0, -1);
313 x + w - 1, y + h - 2 - width / 2, width);
314 ptaJoin(ptad, pta, 0, -1);
317 x - width / 2, y + h - 1, width);
318 ptaJoin(ptad, pta, 0, -1);
321 x, y + 0 + width / 2, width);
322 ptaJoin(ptad, pta, 0, -1);
353PTA *ptad, *ptat, *pta;
356 return (
PTA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
358 L_WARNING(
"width < 1; setting to 1\n", __func__);
362 n = boxaGetCount(boxa);
364 for (i = 0; i < n; i++) {
365 box = boxaGetBox(boxa, i,
L_CLONE);
367 ptaJoin(ptat, pta, 0, -1);
373 ptaRemoveDupsByAset(ptat, &ptad);
375 ptad = ptaClone(ptat);
408l_int32 bx, by, bh, bw, x, y, x1, y1, x2, y2, i, n, npts;
412 return (
PTA *)ERROR_PTR(
"box not defined", __func__, NULL);
414 return (
PTA *)ERROR_PTR(
"spacing not > 1", __func__, NULL);
417 return (
PTA *)ERROR_PTR(
"invalid line orientation", __func__, NULL);
418 boxGetGeometry(box, &bx, &by, &bw, &bh);
419 if (bw == 0 || bh == 0)
420 return (
PTA *)ERROR_PTR(
"box has bw = 0 or bh = 0", __func__, NULL);
422 L_WARNING(
"width < 1; setting to 1\n", __func__);
430 ptaJoin(ptad, pta, 0, -1);
434 n = 1 + bh / spacing;
435 for (i = 0; i < n; i++) {
436 y = by + (i * (bh - 1)) / (n - 1);
438 ptaJoin(ptad, pta, 0, -1);
442 n = 1 + bw / spacing;
443 for (i = 0; i < n; i++) {
444 x = bx + (i * (bw - 1)) / (n - 1);
446 ptaJoin(ptad, pta, 0, -1);
450 n = 2 + (l_int32)((bw + bh) / (1.4 * spacing));
451 for (i = 0; i < n; i++) {
452 x = (l_int32)(bx + (i + 0.5) * 1.4 * spacing);
453 boxIntersectByLine(box, x, by - 1, 1.0, &x1, &y1, &x2, &y2, &npts);
456 ptaJoin(ptad, pta, 0, -1);
461 n = 2 + (l_int32)((bw + bh) / (1.4 * spacing));
462 for (i = 0; i < n; i++) {
463 x = (l_int32)(bx - bh + (i + 0.5) * 1.4 * spacing);
464 boxIntersectByLine(box, x, by - 1, -1.0, &x1, &y1, &x2, &y2, &npts);
467 ptaJoin(ptad, pta, 0, -1);
512PTA *ptad, *ptat, *pta;
515 return (
PTA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
517 return (
PTA *)ERROR_PTR(
"spacing not > 1", __func__, NULL);
519 L_WARNING(
"width < 1; setting to 1\n", __func__);
524 return (
PTA *)ERROR_PTR(
"invalid line orientation", __func__, NULL);
526 n = boxaGetCount(boxa);
528 for (i = 0; i < n; i++) {
529 box = boxaGetBox(boxa, i,
L_CLONE);
531 ptaJoin(ptat, pta, 0, -1);
537 ptaRemoveDupsByAset(ptat, &ptad);
539 ptad = ptaClone(ptat);
563l_int32 i, n, x, y, w, h;
569 return (
PTAA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
571 n = boxaGetCount(boxa);
572 ptaa = ptaaCreate(n);
573 for (i = 0; i < n; i++) {
574 box = boxaGetBox(boxa, i,
L_CLONE);
575 boxGetGeometry(box, &x, &y, &w, &h);
578 ptaAddPt(pta, x + w - 1, y);
579 ptaAddPt(pta, x + w - 1, y + h - 1);
580 ptaAddPt(pta, x, y + h - 1);
624 return (
PTAA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
626 return (
PTAA *)ERROR_PTR(
"spacing not > 1", __func__, NULL);
628 L_WARNING(
"width < 1; setting to 1\n", __func__);
633 return (
PTAA *)ERROR_PTR(
"invalid line orientation", __func__, NULL);
635 n = boxaGetCount(boxa);
636 ptaa = ptaaCreate(n);
637 for (i = 0; i < n; i++) {
638 box = boxaGetBox(boxa, i,
L_CLONE);
663l_int32 i, n, x1, y1, x2, y2;
664PTA *ptad, *ptat, *pta;
667 return (
PTA *)ERROR_PTR(
"ptas not defined", __func__, NULL);
669 L_WARNING(
"width < 1; setting to 1\n", __func__);
673 n = ptaGetCount(ptas);
678 ptaGetIPt(ptas, 0, &x1, &y1);
679 for (i = 1; i < n; i++) {
680 ptaGetIPt(ptas, i, &x2, &y2);
682 ptaJoin(ptat, pta, 0, -1);
689 ptaGetIPt(ptas, 0, &x2, &y2);
691 ptaJoin(ptat, pta, 0, -1);
696 ptaRemoveDupsByAset(ptat, &ptad);
698 ptad = ptaClone(ptat);
720l_int32 i, j, bx, by, x1, x2, y1, y2;
725 if (nx < 1 || ny < 1)
726 return (
PTA *)ERROR_PTR(
"nx and ny must be > 0", __func__, NULL);
727 if (w < 2 * nx || h < 2 * ny)
728 return (
PTA *)ERROR_PTR(
"w and/or h too small", __func__, NULL);
730 L_WARNING(
"width < 1; setting to 1\n", __func__);
734 boxa = boxaCreate(nx * ny);
735 bx = (w + nx - 1) / nx;
736 by = (h + ny - 1) / ny;
737 for (i = 0; i < ny; i++) {
739 y2 = L_MIN(y1 + by, h - 1);
740 for (j = 0; j < nx; j++) {
742 x2 = L_MIN(x1 + bx, w - 1);
743 box = boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
772l_int32 i, n, x, y, xp, yp;
776 return (
PTA *)ERROR_PTR(
"ptas not defined", __func__, NULL);
778 n = ptaGetCount(ptas);
780 ptaGetIPt(ptas, 0, &xp, &yp);
781 ptaAddPt(ptad, xp, yp);
782 for (i = 1; i < n; i++) {
783 ptaGetIPt(ptas, i, &x, &y);
784 if (x != xp && y != yp)
785 ptaAddPt(ptad, x, yp);
786 ptaAddPt(ptad, x, y);
814l_float32 radthresh, sqdist;
818 return (
PTA *)ERROR_PTR(
"radius must be >= 1", __func__, NULL);
821 radthresh = (radius + 0.5) * (radius + 0.5);
822 for (y = 0; y <= 2 * radius; y++) {
823 for (x = 0; x <= 2 * radius; x++) {
824 sqdist = (l_float32)((y - radius) * (y - radius) +
825 (x - radius) * (x - radius));
826 if (sqdist <= radthresh)
855 return (
PTA *)ERROR_PTR(
"side must be > 0", __func__, NULL);
858 for (y = 0; y < side; y++)
859 for (x = 0; x < side; x++)
889 x2 = x + (l_int32)((length - 1.0) * cos(radang));
890 y2 = y + (l_int32)((length - 1.0) * sin(radang));
914 return ERROR_INT(
"&x and &y not both defined", __func__, 1);
916 *px = xr + dist * cos(radang);
917 *py = yr + dist * sin(radang);
953l_int32 w, h, size, rval, gval, bval;
958 return ERROR_INT(
"&pix not defined", __func__, 1);
960 return ERROR_INT(
"pix not defined", __func__, 1);
962 pixGetDimensions(*ppix, &w, &h, NULL);
967 return ERROR_INT(
"pta not made", __func__, 1);
969 if (pixGetDepth(*ppix) != 32) {
970 pix1 = pixConvertTo32(*ppix);
974 extractRGBValues(color, &rval, &gval, &bval);
1009l_int32 orient, refpos;
1012 return (
PTA *)ERROR_PTR(
"na not defined", __func__, NULL);
1020 return (
PTA *)ERROR_PTR(
"invalid plotloc", __func__, NULL);
1028 refpos = size - max - 1;
1067l_int32 rval, gval, bval;
1072 return ERROR_INT(
"&pix not defined", __func__, 1);
1074 return ERROR_INT(
"pix not defined", __func__, 1);
1078 return ERROR_INT(
"pta not made", __func__, 1);
1080 if (pixGetDepth(*ppix) != 32) {
1081 pix1 = pixConvertTo32(*ppix);
1085 extractRGBValues(color, &rval, &gval, &bval);
1129l_int32 i, n, maxw, maxh;
1130l_float32 minval, maxval, absval, val, scale, start, del;
1131PTA *pta1, *pta2, *ptad;
1134 return (
PTA *)ERROR_PTR(
"na not defined", __func__, NULL);
1136 return (
PTA *)ERROR_PTR(
"invalid orient", __func__, NULL);
1137 if (linewidth < 1) {
1138 L_WARNING(
"linewidth < 1; setting to 1\n", __func__);
1141 if (linewidth > 7) {
1142 L_WARNING(
"linewidth > 7; setting to 7\n", __func__);
1146 numaGetMin(na, &minval, NULL);
1147 numaGetMax(na, &maxval, NULL);
1148 absval = L_MAX(L_ABS(minval), L_ABS(maxval));
1149 scale = (l_float32)max / (l_float32)absval;
1150 n = numaGetCount(na);
1151 numaGetParameters(na, &start, &del);
1154 pta1 = ptaCreate(n);
1155 for (i = 0; i < n; i++) {
1156 numaGetFValue(na, i, &val);
1158 ptaAddPt(pta1, start + i * del, refpos + scale * val);
1159 maxw = (del >= 0) ? start + n * del + linewidth
1160 : start + linewidth;
1161 maxh = refpos + max + linewidth;
1163 ptaAddPt(pta1, refpos + scale * val, start + i * del);
1164 maxw = refpos + max + linewidth;
1165 maxh = (del >= 0) ? start + n * del + linewidth
1166 : start + linewidth;
1171 if (linewidth > 1) {
1172 if (linewidth % 2 == 0)
1176 ptad = ptaReplicatePattern(pta1, NULL, pta2, linewidth / 2,
1177 linewidth / 2, maxw, maxh);
1180 ptad = ptaClone(pta1);
1188 ptaJoin(ptad, pta1, 0, -1);
1191 start, refpos + max);
1192 ptaJoin(ptad, pta1, 0, -1);
1195 ptaJoin(ptad, pta1, 0, -1);
1198 refpos + max, start);
1199 ptaJoin(ptad, pta1, 0, -1);
1236l_int32 i, n, x, y, w, h, d, maxval;
1239 return ERROR_INT(
"pix not defined", __func__, 1);
1240 if (pixGetColormap(pix))
1241 return ERROR_INT(
"pix is colormapped", __func__, 1);
1243 return ERROR_INT(
"pta not defined", __func__, 1);
1245 return ERROR_INT(
"invalid op", __func__, 1);
1247 pixGetDimensions(pix, &w, &h, &d);
1265 maxval = 0xffffffff;
1270 n = ptaGetCount(pta);
1271 for (i = 0; i < n; i++) {
1272 ptaGetIPt(pta, i, &x, &y);
1273 if (x < 0 || x >= w)
1275 if (y < 0 || y >= h)
1280 pixSetPixel(pix, x, y, maxval);
1283 pixClearPixel(pix, x, y);
1286 pixFlipPixel(pix, x, y);
1325l_int32 i, n, x, y, w, h, d, index;
1331 return ERROR_INT(
"pix not defined", __func__, 1);
1333 return ERROR_INT(
"pta not defined", __func__, 1);
1334 d = pixGetDepth(pix);
1335 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
1336 return ERROR_INT(
"depth not in {1,2,4,8,32}", __func__, 1);
1343 cmap = pixGetColormap(pix);
1344 pixGetDimensions(pix, &w, &h, &d);
1346 pixcmapAddNearestColor(cmap, rval, gval, bval, &index);
1349 val = (rval + gval + bval) / (3 * 64);
1351 val = (rval + gval + bval) / (3 * 16);
1353 val = (rval + gval + bval) / 3;
1355 composeRGBPixel(rval, gval, bval, &val32);
1358 n = ptaGetCount(pta);
1359 for (i = 0; i < n; i++) {
1360 ptaGetIPt(pta, i, &x, &y);
1361 if (x < 0 || x >= w)
1363 if (y < 0 || y >= h)
1366 pixSetPixel(pix, x, y, index);
1368 pixSetPixel(pix, x, y, val32);
1370 pixSetPixel(pix, x, y, val);
1399l_int32 i, n, x, y, w, h;
1400l_uint8 nrval, ngval, nbval;
1402l_float32 frval, fgval, fbval;
1405 return ERROR_INT(
"pix not defined", __func__, 1);
1407 return ERROR_INT(
"pta not defined", __func__, 1);
1408 if (pixGetDepth(pix) != 32)
1409 return ERROR_INT(
"depth not 32 bpp", __func__, 1);
1410 if (fract < 0.0 || fract > 1.0) {
1411 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
1415 pixGetDimensions(pix, &w, &h, NULL);
1416 n = ptaGetCount(pta);
1417 frval = fract * rval;
1418 fgval = fract * gval;
1419 fbval = fract * bval;
1420 for (i = 0; i < n; i++) {
1421 ptaGetIPt(pta, i, &x, &y);
1422 if (x < 0 || x >= w)
1424 if (y < 0 || y >= h)
1426 pixGetPixel(pix, x, y, &val32);
1428 nrval = (l_uint8)((1. - fract) * nrval + frval);
1430 ngval = (l_uint8)((1. - fract) * ngval + fgval);
1432 nbval = (l_uint8)((1. - fract) * nbval + fbval);
1433 composeRGBPixel(nrval, ngval, nbval, &val32);
1434 pixSetPixel(pix, x, y, val32);
1466 return ERROR_INT(
"pix not defined", __func__, 1);
1468 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1472 return ERROR_INT(
"invalid op", __func__, 1);
1475 return ERROR_INT(
"pta not made", __func__, 1);
1506 return ERROR_INT(
"pix not defined", __func__, 1);
1508 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1513 return ERROR_INT(
"pta not made", __func__, 1);
1546 return ERROR_INT(
"pix not defined", __func__, 1);
1548 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1553 return ERROR_INT(
"pta not made", __func__, 1);
1578 return ERROR_INT(
"pix not defined", __func__, 1);
1580 return ERROR_INT(
"box not defined", __func__, 1);
1582 L_WARNING(
"width < 1; setting to 1\n", __func__);
1586 return ERROR_INT(
"invalid op", __func__, 1);
1589 return ERROR_INT(
"pta not made", __func__, 1);
1616 return ERROR_INT(
"pix not defined", __func__, 1);
1618 return ERROR_INT(
"box not defined", __func__, 1);
1620 L_WARNING(
"width < 1; setting to 1\n", __func__);
1625 return ERROR_INT(
"pta not made", __func__, 1);
1655 return ERROR_INT(
"pix not defined", __func__, 1);
1657 return ERROR_INT(
"box not defined", __func__, 1);
1659 L_WARNING(
"width < 1; setting to 1\n", __func__);
1664 return ERROR_INT(
"pta not made", __func__, 1);
1689 return ERROR_INT(
"pix not defined", __func__, 1);
1691 return ERROR_INT(
"boxa not defined", __func__, 1);
1693 L_WARNING(
"width < 1; setting to 1\n", __func__);
1697 return ERROR_INT(
"invalid op", __func__, 1);
1700 return ERROR_INT(
"pta not made", __func__, 1);
1727 return ERROR_INT(
"pix not defined", __func__, 1);
1729 return ERROR_INT(
"boxa not defined", __func__, 1);
1731 L_WARNING(
"width < 1; setting to 1\n", __func__);
1736 return ERROR_INT(
"pta not made", __func__, 1);
1768 return ERROR_INT(
"pix not defined", __func__, 1);
1770 return ERROR_INT(
"boxa not defined", __func__, 1);
1772 L_WARNING(
"width < 1; setting to 1\n", __func__);
1777 return ERROR_INT(
"pta not made", __func__, 1);
1808 return ERROR_INT(
"pix not defined", __func__, 1);
1810 return ERROR_INT(
"box not defined", __func__, 1);
1812 return ERROR_INT(
"spacing not > 1", __func__, 1);
1814 L_WARNING(
"width < 1; setting to 1\n", __func__);
1819 return ERROR_INT(
"invalid line orientation", __func__, 1);
1821 return ERROR_INT(
"invalid op", __func__, 1);
1825 return ERROR_INT(
"pta not made", __func__, 1);
1858 return ERROR_INT(
"pix not defined", __func__, 1);
1860 return ERROR_INT(
"box not defined", __func__, 1);
1862 return ERROR_INT(
"spacing not > 1", __func__, 1);
1864 L_WARNING(
"width < 1; setting to 1\n", __func__);
1869 return ERROR_INT(
"invalid line orientation", __func__, 1);
1873 return ERROR_INT(
"pta not made", __func__, 1);
1909 return ERROR_INT(
"pix not defined", __func__, 1);
1911 return ERROR_INT(
"box not defined", __func__, 1);
1913 return ERROR_INT(
"spacing not > 1", __func__, 1);
1915 L_WARNING(
"width < 1; setting to 1\n", __func__);
1920 return ERROR_INT(
"invalid line orientation", __func__, 1);
1924 return ERROR_INT(
"pta not made", __func__, 1);
1971 return ERROR_INT(
"pix not defined", __func__, 1);
1972 if (!pixm || pixGetDepth(pixm) != 1)
1973 return ERROR_INT(
"pixm not defined or not 1 bpp", __func__, 1);
1975 return ERROR_INT(
"spacing not > 1", __func__, 1);
1977 L_WARNING(
"width < 1; setting to 1\n", __func__);
1982 return ERROR_INT(
"invalid line orientation", __func__, 1);
1985 pixGetDimensions(pixm, &w, &h, NULL);
1986 box1 = boxCreate(0, 0, w, h);
1988 pta2 = ptaCropToMask(pta1, pixm);
1993 box2 = boxCreate(x, y, w, h);
1994 pix1 = pixClipRectangle(pix, box2, NULL);
2000 pixRasterop(pix, x, y, w, h,
PIX_SRC, pix1, 0, 0);
2032 return ERROR_INT(
"pix not defined", __func__, 1);
2034 return ERROR_INT(
"boxa not defined", __func__, 1);
2036 return ERROR_INT(
"spacing not > 1", __func__, 1);
2038 L_WARNING(
"width < 1; setting to 1\n", __func__);
2043 return ERROR_INT(
"invalid line orientation", __func__, 1);
2045 return ERROR_INT(
"invalid op", __func__, 1);
2049 return ERROR_INT(
"pta not made", __func__, 1);
2084 return ERROR_INT(
"pix not defined", __func__, 1);
2086 return ERROR_INT(
"boxa not defined", __func__, 1);
2088 return ERROR_INT(
"spacing not > 1", __func__, 1);
2090 L_WARNING(
"width < 1; setting to 1\n", __func__);
2095 return ERROR_INT(
"invalid line orientation", __func__, 1);
2099 return ERROR_INT(
"pta not made", __func__, 1);
2137 return ERROR_INT(
"pix not defined", __func__, 1);
2139 return ERROR_INT(
"boxa not defined", __func__, 1);
2141 return ERROR_INT(
"spacing not > 1", __func__, 1);
2143 L_WARNING(
"width < 1; setting to 1\n", __func__);
2148 return ERROR_INT(
"invalid line orientation", __func__, 1);
2152 return ERROR_INT(
"pta not made", __func__, 1);
2184 return ERROR_INT(
"pix not defined", __func__, 1);
2186 return ERROR_INT(
"ptas not defined", __func__, 1);
2188 L_WARNING(
"width < 1; setting to 1\n", __func__);
2192 return ERROR_INT(
"invalid op", __func__, 1);
2195 return ERROR_INT(
"pta not made", __func__, 1);
2229 return ERROR_INT(
"pix not defined", __func__, 1);
2231 return ERROR_INT(
"ptas not defined", __func__, 1);
2233 L_WARNING(
"width < 1; setting to 1\n", __func__);
2238 return ERROR_INT(
"pta not made", __func__, 1);
2272 return ERROR_INT(
"pix not defined", __func__, 1);
2274 return ERROR_INT(
"ptas not defined", __func__, 1);
2276 L_WARNING(
"width < 1; setting to 1\n", __func__);
2281 return ERROR_INT(
"pta not made", __func__, 1);
2310 return ERROR_INT(
"pix not defined", __func__, 1);
2311 if (nx < 1 || ny < 1)
2312 return ERROR_INT(
"nx, ny must be > 0", __func__, 1);
2314 L_WARNING(
"width < 1; setting to 1\n", __func__);
2318 pixGetDimensions(pix, &w, &h, NULL);
2320 return ERROR_INT(
"pta not made", __func__, 1);
2362l_int32 i, n, index, rval, gval, bval;
2368 return (
PIX *)ERROR_PTR(
"pix not defined", __func__, NULL);
2370 return (
PIX *)ERROR_PTR(
"ptaa not defined", __func__, NULL);
2371 if (polyflag != 0 && width < 1) {
2372 L_WARNING(
"width < 1; setting to 1\n", __func__);
2376 pixd = pixConvertTo8(pix, FALSE);
2377 cmap = pixcmapCreateRandom(8, 1, 1);
2378 pixSetColormap(pixd, cmap);
2380 if ((n = ptaaGetCount(ptaa)) == 0)
2383 for (i = 0; i < n; i++) {
2384 index = 1 + (i % 254);
2385 pixcmapGetColor(cmap, index, &rval, &gval, &bval);
2386 pta = ptaaGetPta(ptaa, i,
L_CLONE);
2390 ptat = ptaClone(pta);
2428l_float32 fxmin, fxmax, fymin, fymax;
2432 if (pxmin) *pxmin = 0;
2433 if (pymin) *pymin = 0;
2435 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
2439 return (
PIX *)ERROR_PTR(
"pta1 not made", __func__, NULL);
2443 pta2 = ptaClone(pta1);
2446 ptaGetRange(pta2, &fxmin, &fxmax, &fymin, &fymax);
2447 if (pxmin) *pxmin = (l_int32)(fxmin + 0.5);
2448 if (pymin) *pymin = (l_int32)(fymin + 0.5);
2449 pixd = pixCreate((l_int32)(fxmax + 0.5) + 1, (l_int32)(fymax + 0.5) + 1, 1);
2481l_int32 w, h, i, n, inside, found;
2482l_int32 *xstart, *xend;
2485 if (!pixs || (pixGetDepth(pixs) != 1))
2486 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
2488 return (
PIX *)ERROR_PTR(
"pta not defined", __func__, NULL);
2489 if (ptaGetCount(pta) < 2)
2490 return (
PIX *)ERROR_PTR(
"pta has < 2 pts", __func__, NULL);
2492 pixGetDimensions(pixs, &w, &h, NULL);
2493 xstart = (l_int32 *)LEPT_CALLOC(L_MAX(1, w / 2),
sizeof(l_int32));
2494 xend = (l_int32 *)LEPT_CALLOC(L_MAX(1, w / 2),
sizeof(l_int32));
2495 if (!xstart || !xend) {
2498 return (
PIX *)ERROR_PTR(
"xstart and xend not made", __func__, NULL);
2505 for (i = ymin + 1; i < h; i++) {
2506 pixFindHorizontalRuns(pixs, i, xstart, xend, &n);
2508 ptaPtInsidePolygon(pta, xend[0] + 1, i, &inside);
2516 L_WARNING(
"nothing found to fill\n", __func__);
2523 pixd = pixCreateTemplate(pixs);
2524 pixSetPixel(pixd, xend[0] + 1, i, 1);
2527 pixi = pixInvert(NULL, pixs);
2528 pixSeedfillBinary(pixd, pixd, pixi, 4);
2531 pixOr(pixd, pixd, pixs);
2565l_int32 w, h, d, maxval, wpls, wpld, i, j, val, test;
2566l_uint32 *datas, *datad, *lines, *lined;
2570 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2571 if (pixGetColormap(pixs))
2572 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
2573 pixGetDimensions(pixs, &w, &h, &d);
2574 if (d != 8 && d != 16)
2575 return (
PIX *)ERROR_PTR(
"pixs not 8 or 16 bpp", __func__, NULL);
2576 if (outdepth != 1 && outdepth != d) {
2577 L_WARNING(
"invalid outdepth; setting to 1\n", __func__);
2580 maxval = (1 << d) - 1;
2581 if (startval < 0 || startval > maxval)
2582 return (
PIX *)ERROR_PTR(
"startval not in [0 ... maxval]",
2585 return (
PIX *)ERROR_PTR(
"incr < 1", __func__, NULL);
2588 pixd = pixCopy(NULL, pixs);
2590 pixd = pixCreate(w, h, 1);
2592 pixCopyResolution(pixd, pixs);
2593 datad = pixGetData(pixd);
2594 wpld = pixGetWpl(pixd);
2595 datas = pixGetData(pixs);
2596 wpls = pixGetWpl(pixs);
2601 if (outdepth == 1) {
2602 for (i = 0; i < h; i++) {
2603 lines = datas + i * wpls;
2604 lined = datad + i * wpld;
2605 for (j = 0; j < w; j++) {
2609 test = (val - startval) % incr;
2615 for (i = 0; i < h; i++) {
2616 lines = datas + i * wpls;
2617 lined = datad + i * wpld;
2618 for (j = 0; j < w; j++) {
2622 test = (val - startval) % incr;
2631 if (outdepth == 1) {
2632 for (i = 0; i < h; i++) {
2633 lines = datas + i * wpls;
2634 lined = datad + i * wpld;
2635 for (j = 0; j < w; j++) {
2639 test = (val - startval) % incr;
2645 for (i = 0; i < h; i++) {
2646 lines = datas + i * wpls;
2647 lined = datad + i * wpld;
2648 for (j = 0; j < w; j++) {
2652 test = (val - startval) % incr;
2661 return (
PIX *)ERROR_PTR(
"pixs not 8 or 16 bpp", __func__, NULL);
2687l_float32 minval, maxval, incr;
2690 return (
PIX *)ERROR_PTR(
"fpix not defined", __func__, NULL);
2691 if (ncontours < 2 || ncontours > 500)
2692 return (
PIX *)ERROR_PTR(
"ncontours < 2 or > 500", __func__, NULL);
2694 fpixGetMin(fpix, &minval, NULL, NULL);
2695 fpixGetMax(fpix, &maxval, NULL, NULL);
2696 if (minval == maxval)
2697 return (
PIX *)ERROR_PTR(
"all values in fpix are equal", __func__, NULL);
2698 incr = (maxval - minval) / ((l_float32)ncontours - 1);
2724l_int32 i, j, w, h, wpls, wpld;
2725l_float32 val, invincr, finter, above, below, diff;
2726l_uint32 *datad, *lined;
2727l_float32 *datas, *lines;
2732 return (
PIX *)ERROR_PTR(
"fpixs not defined", __func__, NULL);
2734 return (
PIX *)ERROR_PTR(
"incr <= 0.0", __func__, NULL);
2738 fpixGetDimensions(fpixs, &w, &h);
2739 if ((pixd = pixCreate(w, h, 8)) == NULL)
2740 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2741 cmap = pixcmapCreate(8);
2742 pixSetColormap(pixd, cmap);
2743 pixcmapAddColor(cmap, 255, 255, 255);
2744 pixcmapAddColor(cmap, 0, 0, 0);
2745 pixcmapAddColor(cmap, 255, 0, 0);
2747 datas = fpixGetData(fpixs);
2748 wpls = fpixGetWpl(fpixs);
2749 datad = pixGetData(pixd);
2750 wpld = pixGetWpl(pixd);
2751 invincr = 1.0 / incr;
2752 for (i = 0; i < h; i++) {
2753 lines = datas + i * wpls;
2754 lined = datad + i * wpld;
2755 for (j = 0; j < w; j++) {
2757 finter = invincr * val;
2758 above = finter - floorf(finter);
2759 below = ceilf(finter) - finter;
2760 diff = L_MIN(above, below);
2761 if (diff <= proxim) {
2803 if (!pixs || pixGetDepth(pixs) != 1)
2804 return (
PTA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
2806 L_WARNING(
"width < 1; setting to 1\n", __func__);
2810 pix1 = pixErodeBrick(NULL, pixs, 2 * width + 1, 2 * width + 1);
2811 pixXor(pix1, pix1, pixs);
2812 pta = ptaGetPixelsFromPix(pix1, NULL);
#define GET_DATA_TWO_BYTES(pdata, n)
#define SET_DATA_BIT(pdata, n)
#define SET_DATA_TWO_BYTES(pdata, n, val)
#define GET_DATA_BYTE(pdata, n)
#define SET_DATA_BYTE(pdata, n, val)
l_ok pixRenderPolyline(PIX *pix, PTA *ptas, l_int32 width, l_int32 op, l_int32 closeflag)
pixRenderPolyline()
l_ok pixRenderHashBoxaBlend(PIX *pix, BOXA *boxa, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 rval, l_int32 gval, l_int32 bval, l_float32 fract)
pixRenderHashBoxaBlend()
l_ok pixRenderGridArb(PIX *pix, l_int32 nx, l_int32 ny, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderGridArb()
l_ok pixRenderHashBoxBlend(PIX *pix, BOX *box, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 rval, l_int32 gval, l_int32 bval, l_float32 fract)
pixRenderHashBoxBlend()
PTA * generatePtaHashBoxa(BOXA *boxa, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 removedups)
generatePtaHashBoxa()
l_ok pixRenderHashBox(PIX *pix, BOX *box, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 op)
pixRenderHashBox()
l_ok pixRenderPtaArb(PIX *pix, PTA *pta, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderPtaArb()
PTA * generatePtaLineFromPt(l_int32 x, l_int32 y, l_float64 length, l_float64 radang)
generatePtaLineFromPt()
l_ok locatePtRadially(l_int32 xr, l_int32 yr, l_float64 dist, l_float64 radang, l_float64 *px, l_float64 *py)
locatePtRadially()
l_ok pixRenderBoxBlend(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_float32 fract)
pixRenderBoxBlend()
l_ok pixRenderPtaBlend(PIX *pix, PTA *pta, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_float32 fract)
pixRenderPtaBlend()
l_ok pixRenderLine(PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width, l_int32 op)
pixRenderLine()
PTA * generatePtaLine(l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2)
generatePtaLine()
PTA * makePlotPtaFromNumaGen(NUMA *na, l_int32 orient, l_int32 linewidth, l_int32 refpos, l_int32 max, l_int32 drawref)
makePlotPtaFromNumaGen()
PIX * fpixRenderContours(FPIX *fpixs, l_float32 incr, l_float32 proxim)
fpixRenderContours()
l_ok pixRenderHashBoxa(PIX *pix, BOXA *boxa, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 op)
pixRenderHashBoxa()
l_ok pixRenderHashBoxaArb(PIX *pix, BOXA *boxa, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 rval, l_int32 gval, l_int32 bval)
pixRenderHashBoxaArb()
PIX * pixFillPolygon(PIX *pixs, PTA *pta, l_int32 xmin, l_int32 ymin)
pixFillPolygon()
l_ok pixRenderBox(PIX *pix, BOX *box, l_int32 width, l_int32 op)
pixRenderBox()
PTA * generatePtaPolyline(PTA *ptas, l_int32 width, l_int32 closeflag, l_int32 removedups)
generatePtaPolyline()
l_ok pixRenderPolylineArb(PIX *pix, PTA *ptas, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_int32 closeflag)
pixRenderPolylineArb()
PTA * generatePtaBoxa(BOXA *boxa, l_int32 width, l_int32 removedups)
generatePtaBoxa()
l_ok pixRenderPolylineBlend(PIX *pix, PTA *ptas, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_float32 fract, l_int32 closeflag, l_int32 removedups)
pixRenderPolylineBlend()
l_ok pixRenderPlotFromNuma(PIX **ppix, NUMA *na, l_int32 plotloc, l_int32 linewidth, l_int32 max, l_uint32 color)
pixRenderPlotFromNuma()
PTA * generatePtaFilledCircle(l_int32 radius)
generatePtaFilledCircle()
PTA * pixGeneratePtaBoundary(PIX *pixs, l_int32 width)
pixGeneratePtaBoundary()
PIX * fpixAutoRenderContours(FPIX *fpix, l_int32 ncontours)
fpixAutoRenderContours()
PTAA * generatePtaaBoxa(BOXA *boxa)
generatePtaaBoxa()
PTA * generatePtaGrid(l_int32 w, l_int32 h, l_int32 nx, l_int32 ny, l_int32 width)
generatePtaGrid()
l_ok pixRenderPlotFromNumaGen(PIX **ppix, NUMA *na, l_int32 orient, l_int32 linewidth, l_int32 refpos, l_int32 max, l_int32 drawref, l_uint32 color)
pixRenderPlotFromNumaGen()
l_ok pixRenderHashBoxArb(PIX *pix, BOX *box, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 rval, l_int32 gval, l_int32 bval)
pixRenderHashBoxArb()
PTAA * generatePtaaHashBoxa(BOXA *boxa, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline)
generatePtaaHashBoxa()
PTA * convertPtaLineTo4cc(PTA *ptas)
convertPtaLineTo4cc()
l_ok pixRenderHashMaskArb(PIX *pix, PIX *pixm, l_int32 x, l_int32 y, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline, l_int32 rval, l_int32 gval, l_int32 bval)
pixRenderHashMaskArb()
l_ok pixRenderLineArb(PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderLineArb()
l_ok pixRenderLineBlend(PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_float32 fract)
pixRenderLineBlend()
l_ok pixRenderBoxaBlend(PIX *pix, BOXA *boxa, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval, l_float32 fract, l_int32 removedups)
pixRenderBoxaBlend()
l_ok pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
PIX * pixRenderContours(PIX *pixs, l_int32 startval, l_int32 incr, l_int32 outdepth)
pixRenderContours()
l_ok pixRenderBoxa(PIX *pix, BOXA *boxa, l_int32 width, l_int32 op)
pixRenderBoxa()
PIX * pixRenderPolygon(PTA *ptas, l_int32 width, l_int32 *pxmin, l_int32 *pymin)
pixRenderPolygon()
PTA * generatePtaHashBox(BOX *box, l_int32 spacing, l_int32 width, l_int32 orient, l_int32 outline)
generatePtaHashBox()
PTA * generatePtaFilledSquare(l_int32 side)
generatePtaFilledSquare()
l_ok pixRenderBoxaArb(PIX *pix, BOXA *boxa, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxaArb()
PIX * pixRenderRandomCmapPtaa(PIX *pix, PTAA *ptaa, l_int32 polyflag, l_int32 width, l_int32 closeflag)
pixRenderRandomCmapPtaa()
PTA * generatePtaWideLine(l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width)
generatePtaWideLine()
PTA * generatePtaBox(BOX *box, l_int32 width)
generatePtaBox()
PTA * makePlotPtaFromNuma(NUMA *na, l_int32 size, l_int32 plotloc, l_int32 linewidth, l_int32 max)
makePlotPtaFromNuma()
l_ok pixRenderPta(PIX *pix, PTA *pta, l_int32 op)
pixRenderPta()
struct PixColormap PIXCMAP