157 #include "allheaders.h" 188 l_int32 i, n, d, xb, yb, wb, hb, res;
192 PROCNAME(
"pixaDisplay");
195 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
198 if (n == 0 && w == 0 && h == 0)
199 return (
PIX *)ERROR_PTR(
"no components; no size", procName, NULL);
201 L_WARNING(
"no components; returning empty 1 bpp pix\n", procName);
207 if (w == 0 || h == 0) {
211 if (w == 0 || h == 0)
212 return (
PIX *)ERROR_PTR(
"no associated boxa", procName, NULL);
217 d = pixGetDepth(pix1);
218 res = pixGetXRes(pix1);
222 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
226 for (i = 0; i < n; i++) {
228 L_WARNING(
"no box found!\n", procName);
269 l_int32 i, n, xb, yb, wb, hb, hascmap, maxdepth, same, res;
271 PIX *pix1, *pix2, *pixd;
274 PROCNAME(
"pixaDisplayOnColor");
277 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
279 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
283 if (w == 0 || h == 0) {
293 if (hascmap || !same) {
296 for (i = 0; i < n; i++) {
307 if ((pixd =
pixCreate(w, h, maxdepth)) == NULL) {
309 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
311 if ((maxdepth == 1 && bgcolor > 0) ||
312 (maxdepth == 2 && bgcolor >= 0x3) ||
313 (maxdepth == 4 && bgcolor >= 0xf) ||
314 (maxdepth == 8 && bgcolor >= 0xff) ||
315 (maxdepth == 16 && bgcolor >= 0xffff) ||
316 (maxdepth == 32 && bgcolor >= 0xffffff00)) {
318 }
else if (bgcolor > 0) {
323 for (i = 0; i < n; i++) {
325 L_WARNING(
"no box found!\n", procName);
329 if (i == 0) res = pixGetXRes(pix1);
363 l_int32 i, n, same, maxd, index, xb, yb, wb, hb, res;
365 PIX *pixs, *pix1, *pixd;
368 PROCNAME(
"pixaDisplayRandomCmap");
371 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
374 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
377 return (
PIX *)ERROR_PTR(
"not all components are 1 bpp", procName, NULL);
381 if (w == 0 || h == 0) {
389 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
394 for (i = 0; i < n; i++) {
395 index = 1 + (i % 254);
398 if (i == 0) res = pixGetXRes(pixs);
435 l_float32 scalefactor,
441 l_int32 i, n, x, y, w, h, size, depth, bordval;
443 PIX *pix1, *pix2, *pix3, *pixd;
446 PROCNAME(
"pixaDisplayLinearly");
448 if (pboxa) *pboxa = NULL;
450 return (
PIX *)ERROR_PTR(
"pixas not defined", procName, NULL);
451 if (direction != L_HORIZ && direction != L_VERT)
452 return (
PIX *)ERROR_PTR(
"invalid direction", procName, NULL);
461 bordval = (depth == 1) ? 1 : 0;
462 size = (n - 1) * spacing;
464 for (i = 0; i < n; i++) {
466 L_WARNING(
"missing pix at index %d\n", procName, i);
470 if (scalefactor != 1.0)
471 pix2 =
pixScale(pix1, scalefactor, scalefactor);
481 if (direction == L_HORIZ) {
537 l_int32 n, nw, nh, w, h, d, wt, ht, res, samedepth;
538 l_int32 index, i, j, hascmap;
541 PIX *pix1, *pix2, *pixd;
544 PROCNAME(
"pixaDisplayOnLattice");
546 if (pncols) *pncols = 0;
547 if (pboxa) *pboxa = NULL;
549 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
553 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
556 if (hascmap || !samedepth) {
558 for (i = 0; i < n; i++) {
570 nw = (l_int32)sqrt((l_float64)n);
571 nh = (n + nw - 1) / nw;
577 d = pixGetDepth(pix1);
578 res = pixGetXRes(pix1);
580 if ((pixd =
pixCreate(w, h, d)) == NULL) {
582 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
589 for (i = 0; i < nh; i++) {
590 for (j = 0; j < nw && index < n; j++, index++) {
593 if (wt > cellw || ht > cellh) {
594 L_INFO(
"pix(%d) omitted; size %dx%x\n", procName, index,
603 box =
boxCreate(j * cellw, i * cellh, wt, ht);
610 snprintf(buf,
sizeof(buf),
"n = %d",
boxaGetCount(boxa));
613 if (pncols) *pncols = nw;
651 l_uint32 bordercolor)
653 l_int32 w, h, d, wt, ht;
654 l_int32 i, j, k, x, y, n;
657 PROCNAME(
"pixaDisplayUnsplit");
660 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
661 if (nx <= 0 || ny <= 0)
662 return (
PIX *)ERROR_PTR(
"nx and ny must be > 0", procName, NULL);
664 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
666 return (
PIX *)ERROR_PTR(
"n != nx * ny", procName, NULL);
667 borderwidth = L_MAX(0, borderwidth);
670 w = nx * (wt + 2 * borderwidth);
671 h = ny * (ht + 2 * borderwidth);
674 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
682 for (i = 0, k = 0; i < ny; i++) {
684 for (j = 0; j < nx; j++, k++) {
688 x += wt + 2 * borderwidth;
690 y += ht + 2 * borderwidth;
727 l_int32 wmax, hmax, wd, hd, d, hascmap, res, same;
728 l_int32 i, j, n, ni, ncols, nrows;
729 l_int32 ystart, xstart, wt, ht;
730 PIX *pix1, *pix2, *pixd;
733 PROCNAME(
"pixaDisplayTiled");
736 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
740 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
744 for (i = 0; i < n; i++) {
758 return (
PIX *)ERROR_PTR(
"depths not equal", procName, NULL);
763 spacing = L_MAX(spacing, 0);
764 ncols = (l_int32)((l_float32)(maxwidth - spacing) /
765 (l_float32)(wmax + spacing));
766 ncols = L_MAX(ncols, 1);
767 nrows = (n + ncols - 1) / ncols;
768 wd = wmax * ncols + spacing * (ncols + 1);
769 hd = hmax * nrows + spacing * (nrows + 1);
770 if ((pixd =
pixCreate(wd, hd, d)) == NULL) {
772 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
776 if ((background == 1 && d == 1) || (background == 0 && d != 1))
780 for (i = 0, ni = 0; i < nrows; i++) {
781 ystart = spacing + i * (hmax + spacing);
782 for (j = 0; j < ncols && ni < n; j++, ni++) {
783 xstart = spacing + j * (wmax + spacing);
785 if (ni == 0) res = pixGetXRes(pix1);
839 l_float32 scalefactor,
846 l_int32 bordval, wtry, wt, ht;
850 l_int32 i, j, index, n, x, y, nrows, ninrow, res;
856 PIX *pix, *pixn, *pix1, *pixd;
859 PROCNAME(
"pixaDisplayTiledInRows");
862 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
863 if (outdepth != 1 && outdepth != 8 && outdepth != 32)
864 return (
PIX *)ERROR_PTR(
"outdepth not in {1, 8, 32}", procName, NULL);
867 if (scalefactor <= 0.0) scalefactor = 1.0;
870 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
874 bordval = (outdepth == 1) ? 1 : 0;
875 for (i = 0; i < n; i++) {
881 else if (outdepth == 8)
887 if (scalefactor != 1.0)
888 pix1 =
pixScale(pixn, scalefactor, scalefactor);
902 L_WARNING(
"only got %d components\n", procName, n);
905 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
915 for (i = 0, irow = 0; i < n; i++, irow++) {
917 wtry = w + wt + spacing;
918 if (wtry > maxwidth) {
921 wmaxrow = L_MAX(wmaxrow, w);
924 w = wt + 2 * spacing;
928 maxh = L_MAX(maxh, ht);
935 wmaxrow = L_MAX(wmaxrow, w);
938 if ((pixd =
pixCreate(wmaxrow, h, outdepth)) == NULL) {
942 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
946 if ((background == 1 && outdepth == 1) ||
947 (background == 0 && outdepth != 1))
955 for (i = 0, index = 0; i < nrows; i++) {
959 for (j = 0; j < ninrow; j++, index++) {
962 res = pixGetXRes(pix);
967 wt - 2 * border, ht - 2 *border),
L_INSERT);
1022 l_float32 scalefactor,
1026 l_int32 i, j, index, n, x, y, nrows, wb, hb, w, h, maxd, maxh, bordval, res;
1031 PIX *pix1, *pix2, *pix3, *pixd;
1032 PIXA *pixa1, *pixa2;
1034 PROCNAME(
"pixaDisplayTiledInColumns");
1037 return (
PIX *)ERROR_PTR(
"pixas not defined", procName, NULL);
1040 if (scalefactor <= 0.0) scalefactor = 1.0;
1043 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1051 bordval = (maxd == 1) ? 1 : 0;
1052 for (i = 0; i < n; i++) {
1055 if (scalefactor != 1.0)
1056 pix2 =
pixScale(pix1, scalefactor, scalefactor);
1063 if (i == 0) res = pixGetXRes(pix3);
1071 L_WARNING(
"only got %d components\n", procName, n);
1074 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1080 nrows = (n + nx - 1) / nx;
1082 for (i = 0, index = 0; i < nrows; i++) {
1085 for (j = 0; j < nx && index < n; j++) {
1089 maxh = L_MAX(maxh, hb + spacing);
1099 pixd =
pixaDisplay(pixa2, w + spacing, h + spacing);
1145 l_int32 x, y, w, h, wd, hd, d, res;
1146 l_int32 i, n, nrows, maxht, ninrow, irow, bordval;
1148 l_float32 scalefact;
1149 PIX *pix, *pixn, *pix1, *pixb, *pixd;
1152 PROCNAME(
"pixaDisplayTiledAndScaled");
1155 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
1156 if (outdepth != 1 && outdepth != 8 && outdepth != 32)
1157 return (
PIX *)ERROR_PTR(
"outdepth not in {1, 8, 32}", procName, NULL);
1159 return (
PIX *)ERROR_PTR(
"ncols must be > 0", procName, NULL);
1160 if (border < 0 || border > tilewidth / 5)
1164 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1168 bordval = (outdepth == 1) ? 1 : 0;
1169 for (i = 0; i < n; i++) {
1174 scalefact = (l_float32)(tilewidth - 2 * border) / (l_float32)w;
1175 if (d == 1 && outdepth > 1 && scalefact < 1.0)
1178 pix1 =
pixScale(pix, scalefact, scalefact);
1182 else if (outdepth == 8)
1199 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1203 wd = tilewidth * ncols + spacing * (ncols + 1);
1204 nrows = (n + ncols - 1) / ncols;
1205 if ((rowht = (l_int32 *)LEPT_CALLOC(nrows,
sizeof(l_int32))) == NULL) {
1207 return (
PIX *)ERROR_PTR(
"rowht array not made", procName, NULL);
1212 for (i = 0; i < n; i++) {
1216 maxht = L_MAX(h, maxht);
1217 if (ninrow == ncols) {
1218 rowht[irow] = maxht;
1225 rowht[irow] = maxht;
1229 hd = spacing * (nrows + 1);
1230 for (i = 0; i < nrows; i++)
1234 if ((background == 1 && outdepth == 1) ||
1235 (background == 0 && outdepth != 1))
1241 for (i = 0; i < n; i++) {
1244 res = pixGetXRes(pix);
1248 if (i && ((i % ncols) == 0)) {
1250 y += spacing + rowht[irow];
1254 x += tilewidth + spacing;
1294 l_float32 scalefactor,
1304 PIX *pix1, *pix2, *pix3, *pix4, *pixd;
1307 PROCNAME(
"pixaDisplayTiledWithText");
1310 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
1312 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1314 return (
PIX *)ERROR_PTR(
"invalid maxwidth", procName, NULL);
1317 if (scalefactor <= 0.0) {
1318 L_WARNING(
"invalid scalefactor; setting to 1.0\n", procName);
1321 if (fontsize < 4 || fontsize > 20 || (fontsize & 1)) {
1322 l_int32 fsize = L_MAX(L_MIN(fontsize, 20), 4);
1323 if (fsize & 1) fsize--;
1324 L_WARNING(
"changed fontsize from %d to %d\n", procName,
1331 maxwidth = L_MAX(maxwidth, scalefactor * (maxw + 2 * spacing + 2 * border));
1335 for (i = 0; i < n; i++) {
1339 spacing, 0xffffff00);
1341 if (textstr && strlen(textstr) > 0) {
1342 snprintf(buf,
sizeof(buf),
"%s", textstr);
1401 l_int32 i, n, x, y, w, h, yval, index;
1406 PIX *pix1, *pix2, *pix3, *pix4, *pix5, *pixd;
1409 PROCNAME(
"pixaDisplayTiledByIndex");
1412 return (
PIX *)ERROR_PTR(
"pixa not defined", procName, NULL);
1414 return (
PIX *)ERROR_PTR(
"na not defined", procName, NULL);
1416 return (
PIX *)ERROR_PTR(
"no pixa components", procName, NULL);
1418 return (
PIX *)ERROR_PTR(
"pixa and na counts differ", procName, NULL);
1420 return (
PIX *)ERROR_PTR(
"invalid width", procName, NULL);
1422 L_WARNING(
"very small width: %d\n", procName, width);
1425 if (fontsize < 4 || fontsize > 20 || (fontsize & 1)) {
1426 l_int32 fsize = L_MAX(L_MIN(fontsize, 20), 4);
1427 if (fsize & 1) fsize--;
1428 L_WARNING(
"changed fontsize from %d to %d\n", procName,
1438 for (i = 0; i < n; i++) {
1446 if (textstr && strlen(textstr) > 0) {
1447 snprintf(buf,
sizeof(buf),
"%s", textstr);
1453 x = spacing + border + index * (2 * border + width + spacing);
1456 yval += h + spacing;
1498 l_int32 i, j, n, nbox, na, d, wmax, hmax, x, y, xb, yb, wb, hb;
1504 PROCNAME(
"pixaaDisplay");
1507 return (
PIX *)ERROR_PTR(
"paa not defined", procName, NULL);
1511 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1517 if (w == 0 || h == 0) {
1522 for (i = 0; i < n; i++) {
1526 wmax = L_MAX(wmax, w);
1527 hmax = L_MAX(hmax, h);
1539 d = pixGetDepth(pix1);
1543 if ((pixd =
pixCreate(w, h, d)) == NULL) {
1545 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1549 for (i = 0; i < n; i++) {
1554 for (j = 0; j < na; j++) {
1593 l_int32 i, j, npixa, npix, same, use_maxw, x, y, w, h, hindex;
1594 l_int32 maxwidth, maxd, width, lmaxh, lmaxw;
1597 PIX *pix, *pix1, *pixd;
1600 PROCNAME(
"pixaaDisplayByPixa");
1603 return (
PIX *)ERROR_PTR(
"paa not defined", procName, NULL);
1606 return (
PIX *)ERROR_PTR(
"no components", procName, NULL);
1608 if (!same && maxd < 8)
1609 return (
PIX *)ERROR_PTR(
"depths differ; max < 8", procName, NULL);
1613 if (maxwidth > maxw) {
1614 L_WARNING(
"maxwidth > maxw; using maxwidth\n", procName);
1625 for (i = 0; i < npixa; i++) {
1634 for (j = 0; j < npix; j++) {
1637 if (x + w >= maxw) {
1639 y += lmaxh + yspace;
1645 lmaxh = L_MAX(h, lmaxh);
1646 lmaxw = L_MAX(lmaxw, x);
1649 y += lmaxh + yspace;
1653 width = (use_maxw) ? maxw : lmaxw;
1655 if ((pixd =
pixCreate(width, y, maxd)) == NULL) {
1657 return (
PIX *)ERROR_PTR(
"pixd not made", procName, NULL);
1664 for (i = 0; i < npixa; i++) {
1672 for (j = 0; j < npix; j++) {
1674 if (pixGetDepth(pix) != maxd) {
1683 if (x + w >= maxw) {
1685 y += harray[hindex++] + yspace;
1692 y += harray[hindex++] + yspace;
1737 PROCNAME(
"pixaaDisplayTiledAndScaled");
1740 return (
PIXA *)ERROR_PTR(
"paa not defined", procName, NULL);
1741 if (outdepth != 1 && outdepth != 8 && outdepth != 32)
1742 return (
PIXA *)ERROR_PTR(
"outdepth not in {1, 8, 32}", procName, NULL);
1744 return (
PIXA *)ERROR_PTR(
"ncols must be > 0", procName, NULL);
1745 if (border < 0 || border > tilewidth / 5)
1749 return (
PIXA *)ERROR_PTR(
"no components", procName, NULL);
1752 for (i = 0; i < n; i++) {
1755 background, spacing, border);
1783 PROCNAME(
"pixaConvertTo1");
1786 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
1790 for (i = 0; i < n; i++) {
1824 PROCNAME(
"pixaConvertTo8");
1827 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
1831 for (i = 0; i < n; i++) {
1865 PROCNAME(
"pixaConvertTo8Colormap");
1868 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
1872 for (i = 0; i < n; i++) {
1906 PROCNAME(
"pixaConvertTo32");
1909 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
1913 for (i = 0; i < n; i++) {
1959 l_int32 i, n, nselect, index;
1964 PROCNAME(
"pixaConstrainedSelect");
1967 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
1969 first = L_MAX(0, first);
1970 last = (last < 0) ? n - 1 : L_MIN(n - 1, last);
1972 return (
PIXA *)ERROR_PTR(
"last < first!", procName, NULL);
1974 return (
PIXA *)ERROR_PTR(
"nmax < 1!", procName, NULL);
1979 for (i = 0; i < nselect; i++) {
2024 l_float32 scalefactor,
2029 const char *fileout)
2034 PIXA *pixa1, *pixa2;
2036 PROCNAME(
"pixaSelectToPdf");
2039 return ERROR_INT(
"pixas not defined", procName, 1);
2041 L_WARNING(
"invalid compression type; using default\n", procName);
2045 return ERROR_INT(
"fileout not defined", procName, 1);
2049 first = L_MAX(0, first);
2050 last = (last < 0) ? n - 1 : L_MIN(n - 1, last);
2052 L_ERROR(
"first = %d > last = %d\n", procName, first, last);
2058 bmf = (fontsize <= 0) ? NULL :
bmfCreate(NULL, fontsize);
2107 PIXA *pixad, *pixa1;
2109 PROCNAME(
"pixaMakeFromTiledPixa");
2112 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
2114 return (
PIXA *)ERROR_PTR(
"nsamp too large; typ. 100", procName, NULL);
2118 if (nsamp <= 0) nsamp = 100;
2125 for (i = 0; i < 10; i++) {
2129 L_WARNING(
"requested %d; only %d tiles\n", procName, nsamp, ntiles);
2131 snprintf(buf,
sizeof(buf),
"%d", i);
2187 l_int32 i, j, k, ws, hs, d, nx, ny, n, n_isvalid, ntiles, nmax;
2192 PROCNAME(
"pixaMakeFromTiledPix");
2195 return (
PIXA *)ERROR_PTR(
"pixs not defined", procName, NULL);
2196 if (!boxa && (w <= 0 || h <= 0))
2197 return (
PIXA *)ERROR_PTR(
"w and h must be > 0", procName, NULL);
2206 if (nx < 1 || ny < 1)
2207 return (
PIXA *)ERROR_PTR(
"invalid dimensions", procName, NULL);
2208 if (nx * w != ws || ny * h != hs)
2209 L_WARNING(
"some tiles will be clipped\n", procName);
2215 n_isvalid = (n <= nx * ny && n > nx * (ny - 1)) ? TRUE : FALSE;
2216 ntiles = (n_isvalid) ? n : nx * ny;
2217 nmax = ntiles - start;
2218 num = (num == 0) ? nmax : L_MIN(num, nmax);
2222 return (
PIXA *)ERROR_PTR(
"pixa1 not made", procName, NULL);
2224 cmap = pixGetColormap(pixs);
2225 for (i = 0, k = 0; i < ny; i++) {
2226 for (j = 0; j < nx; j++, k++) {
2227 if (k < start)
continue;
2228 if (k >= start + num)
break;
2261 PROCNAME(
"pixGetTileCount");
2264 return ERROR_INT(
"&n not defined", procName, 1);
2267 return ERROR_INT(
"pix not defined", procName, 1);
2270 if (text && strlen(text) > 4) {
2271 if (sscanf(text,
"n = %d", &n) == 1)
2308 l_float32 scalefactor,
2312 l_int32 n, i, j, ntile, nout, index;
2314 PIXA *pixa1, *pixa2, *pixad;
2316 PROCNAME(
"pixaDisplayMultiTiled");
2319 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
2320 if (nx < 1 || ny < 1 || nx > 50 || ny > 50)
2321 return (
PIXA *)ERROR_PTR(
"invalid tiling factor(s)", procName, NULL);
2323 return (
PIXA *)ERROR_PTR(
"pixas is empty", procName, NULL);
2326 if (maxw == 0 && maxh == 0) {
2329 maxw = (maxw == 0) ? 1000000 : maxw;
2330 maxh = (maxh == 0) ? 1000000 : maxh;
2337 nout = L_MAX(1, (n + ntile - 1) / ntile);
2339 for (i = 0, index = 0; i < nout; i++) {
2341 for (j = 0; j < ntile && index < n; j++, index++) {
2391 l_int32 i, j, index, n, nt;
2395 PROCNAME(
"pixaSplitIntoFiles");
2398 return ERROR_INT(
"pixas not defined", procName, 1);
2400 return ERROR_INT(
"nsplit must be >= 2", procName, 1);
2402 return ERROR_INT(
"pixas is empty", procName, 1);
2403 if (!write_pixa && !write_pix && !write_pdf)
2404 return ERROR_INT(
"no output is requested", procName, 1);
2407 n = (nt + nsplit - 1) / nsplit;
2408 fprintf(stderr,
"nt = %d, n = %d, nsplit = %d\n", nt, n, nsplit);
2409 for (i = 0, index = 0; i < nsplit; i++) {
2411 for (j = 0; j < n && index < nt; j++, index++) {
2413 pix2 =
pixScale(pix1, scale, scale);
2418 snprintf(buf,
sizeof(buf),
"/tmp/lept/split/split%d.pa", i + 1);
2422 snprintf(buf,
sizeof(buf),
"/tmp/lept/split/split%d.tif", i + 1);
2424 pixWriteDebug(buf, pix1, IFF_TIFF_G4);
2428 snprintf(buf,
sizeof(buf),
"/tmp/lept/split/split%d.pdf", i + 1);
2485 PROCNAME(
"convertToNUpFiles");
2488 return ERROR_INT(
"dir not defined", procName, 1);
2489 if (nx < 1 || ny < 1 || nx > 50 || ny > 50)
2490 return ERROR_INT(
"invalid tiling N-factor", procName, 1);
2491 if (fontsize < 0 || fontsize > 20 || fontsize & 1 || fontsize == 2)
2492 return ERROR_INT(
"invalid fontsize", procName, 1);
2494 return ERROR_INT(
"outdir not defined", procName, 1);
2499 return ERROR_INT(
"pixa not made", procName, 1);
2504 format = (d == 1) ? IFF_TIFF_G4 : IFF_JFIF_JPEG;
2507 pixaWriteFiles(rootpath, pixa, format);
2544 PIXA *pixa1, *pixa2;
2547 PROCNAME(
"convertToNUpPixa");
2550 return (
PIXA *)ERROR_PTR(
"dir not defined", procName, NULL);
2551 if (nx < 1 || ny < 1 || nx > 50 || ny > 50)
2552 return (
PIXA *)ERROR_PTR(
"invalid tiling N-factor", procName, NULL);
2554 return (
PIXA *)ERROR_PTR(
"tw must be >= 20", procName, NULL);
2555 if (fontsize < 0 || fontsize > 20 || fontsize & 1 || fontsize == 2)
2556 return (
PIXA *)ERROR_PTR(
"invalid fontsize", procName, NULL);
2562 for (i = 0; i < n; i++) {
2608 l_int32 i, j, k, nt, n2, nout, d;
2611 PIX *pix1, *pix2, *pix3, *pix4;
2612 PIXA *pixa1, *pixad;
2614 PROCNAME(
"pixaConvertToNUpPixa");
2617 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
2618 if (nx < 1 || ny < 1 || nx > 50 || ny > 50)
2619 return (
PIXA *)ERROR_PTR(
"invalid tiling N-factor", procName, NULL);
2621 return (
PIXA *)ERROR_PTR(
"tw must be >= 20", procName, NULL);
2622 if (fontsize < 0 || fontsize > 20 || fontsize & 1 || fontsize == 2)
2623 return (
PIXA *)ERROR_PTR(
"invalid fontsize", procName, NULL);
2627 L_WARNING(
"pixa size %d not equal to sarray size %d\n", procName,
2632 nout = (nt + n2 - 1) / n2;
2634 bmf = (fontsize == 0) ? NULL :
bmfCreate(NULL, fontsize);
2635 for (i = 0, j = 0; i < nout; i++) {
2637 for (k = 0; k < n2 && j < nt; j++, k++) {
2720 const char *fileout)
2722 l_int32 n1, n2, npairs;
2723 PIXA *pixa3, *pixa4, *pixa5;
2726 PROCNAME(
"pixaCompareInPdf");
2728 if (!pixa1 || !pixa2)
2729 return ERROR_INT(
"pixa1 and pixa2 not both defined", procName, 1);
2730 if (nx < 1 || ny < 1 || nx > 20 || ny > 20)
2731 return ERROR_INT(
"invalid tiling factors", procName, 1);
2733 return ERROR_INT(
"invalid tw; tw must be >= 20", procName, 1);
2734 if (fontsize < 0 || fontsize > 20 || fontsize & 1 || fontsize == 2)
2735 return ERROR_INT(
"invalid fontsize", procName, 1);
2737 return ERROR_INT(
"fileout not defined", procName, 1);
2740 if (n1 == 0 || n2 == 0)
2741 return ERROR_INT(
"at least one pixa is empty", procName, 1);
2743 L_WARNING(
"sizes (%d, %d) differ; using the minimum in interleave\n",
2748 return ERROR_INT(
"pixa3 not made", procName, 1);
2758 2 * tw + 4 * border + spacing,
2759 spacing, border, fontsize);
PIX * pixaaDisplay(PIXAA *paa, l_int32 w, l_int32 h)
pixaaDisplay()
PIXA * pixaInterleave(PIXA *pixa1, PIXA *pixa2, l_int32 copyflag)
pixaInterleave()
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
PIX * pixConvertTo1(PIX *pixs, l_int32 threshold)
pixConvertTo1()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
PIX * pixScaleToGray(PIX *pixs, l_float32 scalefactor)
pixScaleToGray()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
l_int32 lept_roundftoi(l_float32 fval)
lept_roundftoi()
l_ok pixaSetText(PIXA *pixa, const char *text, SARRAY *sa)
pixaSetText()
l_ok pixaaSizeRange(PIXAA *paa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
pixaaSizeRange()
SARRAY * sarrayGenerateIntegers(l_int32 n)
sarrayGenerateIntegers()
l_ok pixaWriteDebug(const char *fname, PIXA *pixa)
pixaWriteDebug()
l_ok pixaVerifyDepth(PIXA *pixa, l_int32 *psame, l_int32 *pmaxd)
pixaVerifyDepth()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
PIXA * pixaaDisplayTiledAndScaled(PIXAA *paa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
pixaaDisplayTiledAndScaled()
l_ok pixaSetBoxa(PIXA *pixa, BOXA *boxa, l_int32 accesstype)
pixaSetBoxa()
l_ok pixaJoin(PIXA *pixad, PIXA *pixas, l_int32 istart, l_int32 iend)
pixaJoin()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
PIXA * pixaaGetPixa(PIXAA *paa, l_int32 index, l_int32 accesstype)
pixaaGetPixa()
PIX * pixaDisplayLinearly(PIXA *pixas, l_int32 direction, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border, BOXA **pboxa)
pixaDisplayLinearly()
PIX * pixaDisplayUnsplit(PIXA *pixa, l_int32 nx, l_int32 ny, l_int32 borderwidth, l_uint32 bordercolor)
pixaDisplayUnsplit()
PIXA * pixaDisplayMultiTiled(PIXA *pixas, l_int32 nx, l_int32 ny, l_int32 maxw, l_int32 maxh, l_float32 scalefactor, l_int32 spacing, l_int32 border)
pixaDisplayMultiTiled()
PIX * pixConvertTo8(PIX *pixs, l_int32 cmapflag)
pixConvertTo8()
l_int32 pixaaGetCount(PIXAA *paa, NUMA **pna)
pixaaGetCount()
NUMA * numaMakeConstant(l_float32 val, l_int32 size)
numaMakeConstant()
PIX * pixaDisplayOnLattice(PIXA *pixa, l_int32 cellw, l_int32 cellh, l_int32 *pncols, BOXA **pboxa)
pixaDisplayOnLattice()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
l_ok pixSetAll(PIX *pix)
pixSetAll()
PIXA * pixaConvertToSameDepth(PIXA *pixas)
pixaConvertToSameDepth()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_ok pixaGetDepthInfo(PIXA *pixa, l_int32 *pmaxdepth, l_int32 *psame)
pixaGetDepthInfo()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
PIXA * pixaCreateFromBoxa(PIX *pixs, BOXA *boxa, l_int32 start, l_int32 num, l_int32 *pcropwarn)
pixaCreateFromBoxa()
PIX * pixaDisplay(PIXA *pixa, l_int32 w, l_int32 h)
pixaDisplay()
PIX * pixaDisplayTiledInColumns(PIXA *pixas, l_int32 nx, l_float32 scalefactor, l_int32 spacing, l_int32 border)
pixaDisplayTiledInColumns()
l_ok numaSetValue(NUMA *na, l_int32 index, l_float32 val)
numaSetValue()
l_ok pixSetColormap(PIX *pix, PIXCMAP *colormap)
pixSetColormap()
l_ok modifyTrailingSlash(char *path, size_t nbytes, l_int32 flag)
modifyTrailingSlash()
l_ok pixaSelectToPdf(PIXA *pixas, l_int32 first, l_int32 last, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, l_uint32 color, l_int32 fontsize, const char *fileout)
pixaSelectToPdf()
l_ok pixaSplitIntoFiles(PIXA *pixas, l_int32 nsplit, l_float32 scale, l_int32 outwidth, l_int32 write_pixa, l_int32 write_pix, l_int32 write_pdf)
pixaSplitIntoFiles()
PIX * pixAddBorder(PIX *pixs, l_int32 npix, l_uint32 val)
pixAddBorder()
PIXA * pixaConvertTo8(PIXA *pixas, l_int32 cmapflag)
pixaConvertTo8()
l_ok pixSetText(PIX *pix, const char *textstring)
pixSetText()
l_ok pixSetAllArbitrary(PIX *pix, l_uint32 val)
pixSetAllArbitrary()
PIXA * pixaCopy(PIXA *pixa, l_int32 copyflag)
pixaCopy()
l_int32 * numaGetIArray(NUMA *na)
numaGetIArray()
PIXA * pixaConstrainedSelect(PIXA *pixas, l_int32 first, l_int32 last, l_int32 nmax, l_int32 use_pairs, l_int32 copyflag)
pixaConstrainedSelect()
NUMA * genConstrainedNumaInRange(l_int32 first, l_int32 last, l_int32 nmax, l_int32 use_pairs)
genConstrainedNumaInRange()
PIX * pixaDisplayRandomCmap(PIXA *pixa, l_int32 w, l_int32 h)
pixaDisplayRandomCmap()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIX * pixaDisplayTiledByIndex(PIXA *pixa, NUMA *na, l_int32 width, l_int32 spacing, l_int32 border, l_int32 fontsize, l_uint32 textcolor)
pixaDisplayTiledByIndex()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
PIX * pixaDisplayTiledInRows(PIXA *pixa, l_int32 outdepth, l_int32 maxwidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledInRows()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
PIXA * pixaSelectBySize(PIXA *pixas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
pixaSelectBySize()
PIX * pixConvertTo8Colormap(PIX *pixs, l_int32 dither)
pixConvertTo8Colormap()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixGetTileCount(PIX *pix, l_int32 *pn)
pixGetTileCount()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
PIX * pixaDisplayOnColor(PIXA *pixa, l_int32 w, l_int32 h, l_uint32 bgcolor)
pixaDisplayOnColor()
l_ok pixaGetBoxGeometry(PIXA *pixa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
pixaGetBoxGeometry()
PIX * pixClone(PIX *pixs)
pixClone()
PIX * pixaDisplayTiledAndScaled(PIXA *pixa, l_int32 outdepth, l_int32 tilewidth, l_int32 ncols, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledAndScaled()
PIX * pixScaleToSize(PIX *pixs, l_int32 wd, l_int32 hd)
pixScaleToSize()
void pixDestroy(PIX **ppix)
pixDestroy()
NUMA * numaMakeSequence(l_float32 startval, l_float32 increment, l_int32 size)
numaMakeSequence()
l_ok pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
l_ok pixaCompareInPdf(PIXA *pixa1, PIXA *pixa2, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize, const char *fileout)
pixaCompareInPdf()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
l_ok boxaWriteMem(l_uint8 **pdata, size_t *psize, BOXA *boxa)
boxaWriteMem()
PIX * pixaaDisplayByPixa(PIXAA *paa, l_int32 xspace, l_int32 yspace, l_int32 maxw)
pixaaDisplayByPixa()
l_ok boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
l_ok convertToNUpFiles(const char *dir, const char *substr, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize, const char *outdir)
convertToNUpFiles()
PIXA * pixaReadFilesSA(SARRAY *sa)
pixaReadFilesSA()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIXA * pixaMakeFromTiledPixa(PIXA *pixas, l_int32 w, l_int32 h, l_int32 nsamp)
pixaMakeFromTiledPixa()
l_ok pixaSizeRange(PIXA *pixa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
pixaSizeRange()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
char * pixGetText(PIX *pix)
pixGetText()
l_ok pixaGetRenderingDepth(PIXA *pixa, l_int32 *pdepth)
pixaGetRenderingDepth()
l_ok pixaConvertToPdf(PIXA *pixa, l_int32 res, l_float32 scalefactor, l_int32 type, l_int32 quality, const char *title, const char *fileout)
pixaConvertToPdf()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIXA * pixaMakeFromTiledPix(PIX *pixs, l_int32 w, l_int32 h, l_int32 start, l_int32 num, BOXA *boxa)
pixaMakeFromTiledPix()
l_ok makeTempDirname(char *result, size_t nbytes, const char *subdir)
makeTempDirname()
PIXA * convertToNUpPixa(const char *dir, const char *substr, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize)
convertToNUpPixa()
l_ok pixaGetPixDimensions(PIXA *pixa, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixaGetPixDimensions()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
PIXA * pixaConvertTo32(PIXA *pixas)
pixaConvertTo32()
PIX * pixConvert1To8(PIX *pixd, PIX *pixs, l_uint8 val0, l_uint8 val1)
pixConvert1To8()
l_ok pixaaVerifyDepth(PIXAA *paa, l_int32 *psame, l_int32 *pmaxd)
pixaaVerifyDepth()
PIXA * pixaConvertTo8Colormap(PIXA *pixas, l_int32 dither)
pixaConvertTo8Colormap()
PIX * pixAddTextlines(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixAddTextlines()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
PIXA * pixaConvertToNUpPixa(PIXA *pixas, SARRAY *sa, l_int32 nx, l_int32 ny, l_int32 tw, l_int32 spacing, l_int32 border, l_int32 fontsize)
pixaConvertToNUpPixa()
BOXA * pixaaGetBoxa(PIXAA *paa, l_int32 accesstype)
pixaaGetBoxa()
l_ok pixSetResolution(PIX *pix, l_int32 xres, l_int32 yres)
pixSetResolution()
PIXCMAP * pixcmapCopy(PIXCMAP *cmaps)
pixcmapCopy()
PIXA * pixaConvertTo1(PIXA *pixas, l_int32 thresh)
pixaConvertTo1()
l_ok numaGetMax(NUMA *na, l_float32 *pmaxval, l_int32 *pimaxloc)
numaGetMax()
PIXA * pixaSelectRange(PIXA *pixas, l_int32 first, l_int32 last, l_int32 copyflag)
pixaSelectRange()
l_int32 lept_rmdir(const char *subdir)
lept_rmdir()
PIX * pixaDisplayTiledWithText(PIXA *pixa, l_int32 maxwidth, l_float32 scalefactor, l_int32 spacing, l_int32 border, l_int32 fontsize, l_uint32 textcolor)
pixaDisplayTiledWithText()
l_ok pixaAddBox(PIXA *pixa, BOX *box, l_int32 copyflag)
pixaAddBox()
PIX * pixScale(PIX *pixs, l_float32 scalex, l_float32 scaley)
pixScale()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixAddBorderGeneral(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixAddBorderGeneral()
PIXA * pixaAddTextNumber(PIXA *pixas, L_BMF *bmf, NUMA *na, l_uint32 val, l_int32 location)
pixaAddTextNumber()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
PIX * pixaDisplayTiled(PIXA *pixa, l_int32 maxwidth, l_int32 background, l_int32 spacing)
pixaDisplayTiled()
l_ok pixaAnyColormaps(PIXA *pixa, l_int32 *phascmap)
pixaAnyColormaps()
PIXCMAP * pixcmapCreateRandom(l_int32 depth, l_int32 hasblack, l_int32 haswhite)
pixcmapCreateRandom()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()
BOXA * pixaGetBoxa(PIXA *pixa, l_int32 accesstype)
pixaGetBoxa()