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);
1156 for (i = 0; i < n; i++) {
1157 numaGetFValue(na, i, &val);
1159 ptaAddPt(pta1, start + i * del, refpos + scale * val);
1160 maxw = (del >= 0) ? start + n * del + linewidth
1161 : start + linewidth;
1162 maxh = refpos + max + linewidth;
1164 ptaAddPt(pta1, refpos + scale * val, start + i * del);
1165 maxw = refpos + max + linewidth;
1166 maxh = (del >= 0) ? start + n * del + linewidth
1167 : start + linewidth;
1172 if (linewidth > 1) {
1173 if (linewidth % 2 == 0)
1177 ptad = ptaReplicatePattern(pta1, NULL, pta2, linewidth / 2,
1178 linewidth / 2, maxw, maxh);
1181 ptad = ptaClone(pta1);
1189 ptaJoin(ptad, pta1, 0, -1);
1192 start, refpos + max);
1193 ptaJoin(ptad, pta1, 0, -1);
1196 ptaJoin(ptad, pta1, 0, -1);
1199 refpos + max, start);
1200 ptaJoin(ptad, pta1, 0, -1);
1237l_int32 i, n, x, y, w, h, d, maxval;
1240 return ERROR_INT(
"pix not defined", __func__, 1);
1241 if (pixGetColormap(pix))
1242 return ERROR_INT(
"pix is colormapped", __func__, 1);
1244 return ERROR_INT(
"pta not defined", __func__, 1);
1246 return ERROR_INT(
"invalid op", __func__, 1);
1248 pixGetDimensions(pix, &w, &h, &d);
1266 maxval = 0xffffffff;
1271 n = ptaGetCount(pta);
1272 for (i = 0; i < n; i++) {
1273 ptaGetIPt(pta, i, &x, &y);
1274 if (x < 0 || x >= w)
1276 if (y < 0 || y >= h)
1281 pixSetPixel(pix, x, y, maxval);
1284 pixClearPixel(pix, x, y);
1287 pixFlipPixel(pix, x, y);
1326l_int32 i, n, x, y, w, h, d, index;
1332 return ERROR_INT(
"pix not defined", __func__, 1);
1334 return ERROR_INT(
"pta not defined", __func__, 1);
1335 d = pixGetDepth(pix);
1336 if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
1337 return ERROR_INT(
"depth not in {1,2,4,8,32}", __func__, 1);
1344 cmap = pixGetColormap(pix);
1345 pixGetDimensions(pix, &w, &h, &d);
1347 pixcmapAddNearestColor(cmap, rval, gval, bval, &index);
1350 val = (rval + gval + bval) / (3 * 64);
1352 val = (rval + gval + bval) / (3 * 16);
1354 val = (rval + gval + bval) / 3;
1356 composeRGBPixel(rval, gval, bval, &val32);
1359 n = ptaGetCount(pta);
1360 for (i = 0; i < n; i++) {
1361 ptaGetIPt(pta, i, &x, &y);
1362 if (x < 0 || x >= w)
1364 if (y < 0 || y >= h)
1367 pixSetPixel(pix, x, y, index);
1369 pixSetPixel(pix, x, y, val32);
1371 pixSetPixel(pix, x, y, val);
1400l_int32 i, n, x, y, w, h;
1401l_uint8 nrval, ngval, nbval;
1403l_float32 frval, fgval, fbval;
1406 return ERROR_INT(
"pix not defined", __func__, 1);
1408 return ERROR_INT(
"pta not defined", __func__, 1);
1409 if (pixGetDepth(pix) != 32)
1410 return ERROR_INT(
"depth not 32 bpp", __func__, 1);
1411 if (fract < 0.0 || fract > 1.0) {
1412 L_WARNING(
"fract must be in [0.0, 1.0]; setting to 0.5\n", __func__);
1416 pixGetDimensions(pix, &w, &h, NULL);
1417 n = ptaGetCount(pta);
1418 frval = fract * rval;
1419 fgval = fract * gval;
1420 fbval = fract * bval;
1421 for (i = 0; i < n; i++) {
1422 ptaGetIPt(pta, i, &x, &y);
1423 if (x < 0 || x >= w)
1425 if (y < 0 || y >= h)
1427 pixGetPixel(pix, x, y, &val32);
1429 nrval = (l_uint8)((1. - fract) * nrval + frval);
1431 ngval = (l_uint8)((1. - fract) * ngval + fgval);
1433 nbval = (l_uint8)((1. - fract) * nbval + fbval);
1434 composeRGBPixel(nrval, ngval, nbval, &val32);
1435 pixSetPixel(pix, x, y, val32);
1467 return ERROR_INT(
"pix not defined", __func__, 1);
1469 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1473 return ERROR_INT(
"invalid op", __func__, 1);
1476 return ERROR_INT(
"pta not made", __func__, 1);
1507 return ERROR_INT(
"pix not defined", __func__, 1);
1509 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1514 return ERROR_INT(
"pta not made", __func__, 1);
1547 return ERROR_INT(
"pix not defined", __func__, 1);
1549 L_WARNING(
"width must be > 0; setting to 1\n", __func__);
1554 return ERROR_INT(
"pta not made", __func__, 1);
1579 return ERROR_INT(
"pix not defined", __func__, 1);
1581 return ERROR_INT(
"box not defined", __func__, 1);
1583 L_WARNING(
"width < 1; setting to 1\n", __func__);
1587 return ERROR_INT(
"invalid op", __func__, 1);
1590 return ERROR_INT(
"pta not made", __func__, 1);
1617 return ERROR_INT(
"pix not defined", __func__, 1);
1619 return ERROR_INT(
"box not defined", __func__, 1);
1621 L_WARNING(
"width < 1; setting to 1\n", __func__);
1626 return ERROR_INT(
"pta not made", __func__, 1);
1656 return ERROR_INT(
"pix not defined", __func__, 1);
1658 return ERROR_INT(
"box not defined", __func__, 1);
1660 L_WARNING(
"width < 1; setting to 1\n", __func__);
1665 return ERROR_INT(
"pta not made", __func__, 1);
1690 return ERROR_INT(
"pix not defined", __func__, 1);
1692 return ERROR_INT(
"boxa not defined", __func__, 1);
1694 L_WARNING(
"width < 1; setting to 1\n", __func__);
1698 return ERROR_INT(
"invalid op", __func__, 1);
1701 return ERROR_INT(
"pta not made", __func__, 1);
1728 return ERROR_INT(
"pix not defined", __func__, 1);
1730 return ERROR_INT(
"boxa not defined", __func__, 1);
1732 L_WARNING(
"width < 1; setting to 1\n", __func__);
1737 return ERROR_INT(
"pta not made", __func__, 1);
1769 return ERROR_INT(
"pix not defined", __func__, 1);
1771 return ERROR_INT(
"boxa not defined", __func__, 1);
1773 L_WARNING(
"width < 1; setting to 1\n", __func__);
1778 return ERROR_INT(
"pta not made", __func__, 1);
1809 return ERROR_INT(
"pix not defined", __func__, 1);
1811 return ERROR_INT(
"box not defined", __func__, 1);
1813 return ERROR_INT(
"spacing not > 1", __func__, 1);
1815 L_WARNING(
"width < 1; setting to 1\n", __func__);
1820 return ERROR_INT(
"invalid line orientation", __func__, 1);
1822 return ERROR_INT(
"invalid op", __func__, 1);
1826 return ERROR_INT(
"pta not made", __func__, 1);
1859 return ERROR_INT(
"pix not defined", __func__, 1);
1861 return ERROR_INT(
"box not defined", __func__, 1);
1863 return ERROR_INT(
"spacing not > 1", __func__, 1);
1865 L_WARNING(
"width < 1; setting to 1\n", __func__);
1870 return ERROR_INT(
"invalid line orientation", __func__, 1);
1874 return ERROR_INT(
"pta not made", __func__, 1);
1910 return ERROR_INT(
"pix not defined", __func__, 1);
1912 return ERROR_INT(
"box not defined", __func__, 1);
1914 return ERROR_INT(
"spacing not > 1", __func__, 1);
1916 L_WARNING(
"width < 1; setting to 1\n", __func__);
1921 return ERROR_INT(
"invalid line orientation", __func__, 1);
1925 return ERROR_INT(
"pta not made", __func__, 1);
1972 return ERROR_INT(
"pix not defined", __func__, 1);
1973 if (!pixm || pixGetDepth(pixm) != 1)
1974 return ERROR_INT(
"pixm not defined or not 1 bpp", __func__, 1);
1976 return ERROR_INT(
"spacing not > 1", __func__, 1);
1978 L_WARNING(
"width < 1; setting to 1\n", __func__);
1983 return ERROR_INT(
"invalid line orientation", __func__, 1);
1986 pixGetDimensions(pixm, &w, &h, NULL);
1987 box1 = boxCreate(0, 0, w, h);
1989 pta2 = ptaCropToMask(pta1, pixm);
1994 box2 = boxCreate(x, y, w, h);
1995 pix1 = pixClipRectangle(pix, box2, NULL);
2001 pixRasterop(pix, x, y, w, h,
PIX_SRC, pix1, 0, 0);
2033 return ERROR_INT(
"pix not defined", __func__, 1);
2035 return ERROR_INT(
"boxa not defined", __func__, 1);
2037 return ERROR_INT(
"spacing not > 1", __func__, 1);
2039 L_WARNING(
"width < 1; setting to 1\n", __func__);
2044 return ERROR_INT(
"invalid line orientation", __func__, 1);
2046 return ERROR_INT(
"invalid op", __func__, 1);
2050 return ERROR_INT(
"pta not made", __func__, 1);
2085 return ERROR_INT(
"pix not defined", __func__, 1);
2087 return ERROR_INT(
"boxa not defined", __func__, 1);
2089 return ERROR_INT(
"spacing not > 1", __func__, 1);
2091 L_WARNING(
"width < 1; setting to 1\n", __func__);
2096 return ERROR_INT(
"invalid line orientation", __func__, 1);
2100 return ERROR_INT(
"pta not made", __func__, 1);
2138 return ERROR_INT(
"pix not defined", __func__, 1);
2140 return ERROR_INT(
"boxa not defined", __func__, 1);
2142 return ERROR_INT(
"spacing not > 1", __func__, 1);
2144 L_WARNING(
"width < 1; setting to 1\n", __func__);
2149 return ERROR_INT(
"invalid line orientation", __func__, 1);
2153 return ERROR_INT(
"pta not made", __func__, 1);
2185 return ERROR_INT(
"pix not defined", __func__, 1);
2187 return ERROR_INT(
"ptas not defined", __func__, 1);
2189 L_WARNING(
"width < 1; setting to 1\n", __func__);
2193 return ERROR_INT(
"invalid op", __func__, 1);
2196 return ERROR_INT(
"pta not made", __func__, 1);
2230 return ERROR_INT(
"pix not defined", __func__, 1);
2232 return ERROR_INT(
"ptas not defined", __func__, 1);
2234 L_WARNING(
"width < 1; setting to 1\n", __func__);
2239 return ERROR_INT(
"pta not made", __func__, 1);
2273 return ERROR_INT(
"pix not defined", __func__, 1);
2275 return ERROR_INT(
"ptas not defined", __func__, 1);
2277 L_WARNING(
"width < 1; setting to 1\n", __func__);
2282 return ERROR_INT(
"pta not made", __func__, 1);
2311 return ERROR_INT(
"pix not defined", __func__, 1);
2312 if (nx < 1 || ny < 1)
2313 return ERROR_INT(
"nx, ny must be > 0", __func__, 1);
2315 L_WARNING(
"width < 1; setting to 1\n", __func__);
2319 pixGetDimensions(pix, &w, &h, NULL);
2321 return ERROR_INT(
"pta not made", __func__, 1);
2363l_int32 i, n, index, rval, gval, bval;
2369 return (
PIX *)ERROR_PTR(
"pix not defined", __func__, NULL);
2371 return (
PIX *)ERROR_PTR(
"ptaa not defined", __func__, NULL);
2372 if (polyflag != 0 && width < 1) {
2373 L_WARNING(
"width < 1; setting to 1\n", __func__);
2377 pixd = pixConvertTo8(pix, FALSE);
2378 cmap = pixcmapCreateRandom(8, 1, 1);
2379 pixSetColormap(pixd, cmap);
2381 if ((n = ptaaGetCount(ptaa)) == 0)
2384 for (i = 0; i < n; i++) {
2385 index = 1 + (i % 254);
2386 pixcmapGetColor(cmap, index, &rval, &gval, &bval);
2387 pta = ptaaGetPta(ptaa, i,
L_CLONE);
2391 ptat = ptaClone(pta);
2429l_float32 fxmin, fxmax, fymin, fymax;
2433 if (pxmin) *pxmin = 0;
2434 if (pymin) *pymin = 0;
2436 return (
PIX *)ERROR_PTR(
"ptas not defined", __func__, NULL);
2440 return (
PIX *)ERROR_PTR(
"pta1 not made", __func__, NULL);
2444 pta2 = ptaClone(pta1);
2447 ptaGetRange(pta2, &fxmin, &fxmax, &fymin, &fymax);
2448 if (pxmin) *pxmin = (l_int32)(fxmin + 0.5);
2449 if (pymin) *pymin = (l_int32)(fymin + 0.5);
2450 pixd = pixCreate((l_int32)(fxmax + 0.5) + 1, (l_int32)(fymax + 0.5) + 1, 1);
2482l_int32 w, h, i, n, inside, found;
2483l_int32 *xstart, *xend;
2486 if (!pixs || (pixGetDepth(pixs) != 1))
2487 return (
PIX *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
2489 return (
PIX *)ERROR_PTR(
"pta not defined", __func__, NULL);
2490 if (ptaGetCount(pta) < 2)
2491 return (
PIX *)ERROR_PTR(
"pta has < 2 pts", __func__, NULL);
2493 pixGetDimensions(pixs, &w, &h, NULL);
2494 xstart = (l_int32 *)LEPT_CALLOC(L_MAX(1, w / 2),
sizeof(l_int32));
2495 xend = (l_int32 *)LEPT_CALLOC(L_MAX(1, w / 2),
sizeof(l_int32));
2496 if (!xstart || !xend) {
2499 return (
PIX *)ERROR_PTR(
"xstart and xend not made", __func__, NULL);
2506 for (i = ymin + 1; i < h; i++) {
2507 pixFindHorizontalRuns(pixs, i, xstart, xend, &n);
2509 ptaPtInsidePolygon(pta, xend[0] + 1, i, &inside);
2517 L_WARNING(
"nothing found to fill\n", __func__);
2524 pixd = pixCreateTemplate(pixs);
2525 pixSetPixel(pixd, xend[0] + 1, i, 1);
2528 pixi = pixInvert(NULL, pixs);
2529 pixSeedfillBinary(pixd, pixd, pixi, 4);
2532 pixOr(pixd, pixd, pixs);
2566l_int32 w, h, d, maxval, wpls, wpld, i, j, val, test;
2567l_uint32 *datas, *datad, *lines, *lined;
2571 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2572 if (pixGetColormap(pixs))
2573 return (
PIX *)ERROR_PTR(
"pixs has colormap", __func__, NULL);
2574 pixGetDimensions(pixs, &w, &h, &d);
2575 if (d != 8 && d != 16)
2576 return (
PIX *)ERROR_PTR(
"pixs not 8 or 16 bpp", __func__, NULL);
2577 if (outdepth != 1 && outdepth != d) {
2578 L_WARNING(
"invalid outdepth; setting to 1\n", __func__);
2581 maxval = (1 << d) - 1;
2582 if (startval < 0 || startval > maxval)
2583 return (
PIX *)ERROR_PTR(
"startval not in [0 ... maxval]",
2586 return (
PIX *)ERROR_PTR(
"incr < 1", __func__, NULL);
2589 pixd = pixCopy(NULL, pixs);
2591 pixd = pixCreate(w, h, 1);
2593 pixCopyResolution(pixd, pixs);
2594 datad = pixGetData(pixd);
2595 wpld = pixGetWpl(pixd);
2596 datas = pixGetData(pixs);
2597 wpls = pixGetWpl(pixs);
2602 if (outdepth == 1) {
2603 for (i = 0; i < h; i++) {
2604 lines = datas + i * wpls;
2605 lined = datad + i * wpld;
2606 for (j = 0; j < w; j++) {
2610 test = (val - startval) % incr;
2616 for (i = 0; i < h; i++) {
2617 lines = datas + i * wpls;
2618 lined = datad + i * wpld;
2619 for (j = 0; j < w; j++) {
2623 test = (val - startval) % incr;
2632 if (outdepth == 1) {
2633 for (i = 0; i < h; i++) {
2634 lines = datas + i * wpls;
2635 lined = datad + i * wpld;
2636 for (j = 0; j < w; j++) {
2640 test = (val - startval) % incr;
2646 for (i = 0; i < h; i++) {
2647 lines = datas + i * wpls;
2648 lined = datad + i * wpld;
2649 for (j = 0; j < w; j++) {
2653 test = (val - startval) % incr;
2662 return (
PIX *)ERROR_PTR(
"pixs not 8 or 16 bpp", __func__, NULL);
2688l_float32 minval, maxval, incr;
2691 return (
PIX *)ERROR_PTR(
"fpix not defined", __func__, NULL);
2692 if (ncontours < 2 || ncontours > 500)
2693 return (
PIX *)ERROR_PTR(
"ncontours < 2 or > 500", __func__, NULL);
2695 fpixGetMin(fpix, &minval, NULL, NULL);
2696 fpixGetMax(fpix, &maxval, NULL, NULL);
2697 if (minval == maxval)
2698 return (
PIX *)ERROR_PTR(
"all values in fpix are equal", __func__, NULL);
2699 incr = (maxval - minval) / ((l_float32)ncontours - 1);
2725l_int32 i, j, w, h, wpls, wpld;
2726l_float32 val, invincr, finter, above, below, diff;
2727l_uint32 *datad, *lined;
2728l_float32 *datas, *lines;
2733 return (
PIX *)ERROR_PTR(
"fpixs not defined", __func__, NULL);
2735 return (
PIX *)ERROR_PTR(
"incr <= 0.0", __func__, NULL);
2739 fpixGetDimensions(fpixs, &w, &h);
2740 if ((pixd = pixCreate(w, h, 8)) == NULL)
2741 return (
PIX *)ERROR_PTR(
"pixd not made", __func__, NULL);
2742 cmap = pixcmapCreate(8);
2743 pixSetColormap(pixd, cmap);
2744 pixcmapAddColor(cmap, 255, 255, 255);
2745 pixcmapAddColor(cmap, 0, 0, 0);
2746 pixcmapAddColor(cmap, 255, 0, 0);
2748 datas = fpixGetData(fpixs);
2749 wpls = fpixGetWpl(fpixs);
2750 datad = pixGetData(pixd);
2751 wpld = pixGetWpl(pixd);
2752 invincr = 1.0 / incr;
2753 for (i = 0; i < h; i++) {
2754 lines = datas + i * wpls;
2755 lined = datad + i * wpld;
2756 for (j = 0; j < w; j++) {
2758 finter = invincr * val;
2759 above = finter - floorf(finter);
2760 below = ceilf(finter) - finter;
2761 diff = L_MIN(above, below);
2762 if (diff <= proxim) {
2804 if (!pixs || pixGetDepth(pixs) != 1)
2805 return (
PTA *)ERROR_PTR(
"pixs undefined or not 1 bpp", __func__, NULL);
2807 L_WARNING(
"width < 1; setting to 1\n", __func__);
2811 pix1 = pixErodeBrick(NULL, pixs, 2 * width + 1, 2 * width + 1);
2812 pixXor(pix1, pix1, pixs);
2813 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()