68 #include <config_auto.h>
72 #include "allheaders.h"
105 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
107 return (
BOXA *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
109 L_WARNING(
"boxas is empty\n", __func__);
112 first = L_MAX(0, first);
113 if (last < 0) last = n - 1;
115 return (
BOXA *)ERROR_PTR(
"invalid first", __func__, NULL);
117 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
118 __func__, last, n - 1);
122 return (
BOXA *)ERROR_PTR(
"first > last", __func__, NULL);
124 nbox = last - first + 1;
126 for (i = first; i <= last; i++) {
161 return (
BOXAA *)ERROR_PTR(
"baas not defined", __func__, NULL);
163 return (
BOXAA *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
165 return (
BOXAA *)ERROR_PTR(
"empty baas", __func__, NULL);
166 first = L_MAX(0, first);
167 if (last < 0) last = n - 1;
169 return (
BOXAA *)ERROR_PTR(
"invalid first", __func__, NULL);
171 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
172 __func__, last, n - 1);
176 return (
BOXAA *)ERROR_PTR(
"first > last", __func__, NULL);
178 nboxa = last - first + 1;
180 for (i = first; i <= last; i++) {
227 if (pchanged) *pchanged = FALSE;
229 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
231 L_WARNING(
"boxas is empty\n", __func__);
236 return (
BOXA *)ERROR_PTR(
"invalid type", __func__, NULL);
239 return (
BOXA *)ERROR_PTR(
"invalid relation", __func__, NULL);
244 return (
BOXA *)ERROR_PTR(
"na not made", __func__, NULL);
284 l_int32 i, n, w, h, ival;
288 return (
NUMA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
290 return (
NUMA *)ERROR_PTR(
"boxa is empty", __func__, NULL);
293 return (
NUMA *)ERROR_PTR(
"invalid type", __func__, NULL);
296 return (
NUMA *)ERROR_PTR(
"invalid relation", __func__, NULL);
299 for (i = 0; i < n; i++) {
319 if (((relation ==
L_SELECT_IF_LT) && (w < width || h < height)) ||
326 if (((relation ==
L_SELECT_IF_LT) && (w < width && h < height)) ||
333 L_WARNING(
"can't get here!\n", __func__);
371 if (pchanged) *pchanged = FALSE;
373 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
375 L_WARNING(
"boxas is empty\n", __func__);
380 return (
BOXA *)ERROR_PTR(
"invalid relation", __func__, NULL);
415 l_int32 i, n, w, h, ival;
419 return (
NUMA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
421 return (
NUMA *)ERROR_PTR(
"boxa is empty", __func__, NULL);
424 return (
NUMA *)ERROR_PTR(
"invalid relation", __func__, NULL);
427 for (i = 0; i < n; i++) {
471 if (pchanged) *pchanged = FALSE;
473 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
475 L_WARNING(
"boxas is empty\n", __func__);
480 return (
BOXA *)ERROR_PTR(
"invalid relation", __func__, NULL);
515 l_int32 i, n, w, h, ival;
520 return (
NUMA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
522 return (
NUMA *)ERROR_PTR(
"boxa is empty", __func__, NULL);
525 return (
NUMA *)ERROR_PTR(
"invalid relation", __func__, NULL);
528 for (i = 0; i < n; i++) {
531 whratio = (l_float32)w / (l_float32)h;
566 l_int32 i, n, ival, nsave;
570 if (pchanged) *pchanged = FALSE;
572 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
574 return (
BOXA *)ERROR_PTR(
"na not defined", __func__, NULL);
578 for (i = 0; i < n; i++) {
580 if (ival == 1) nsave++;
584 if (pchanged) *pchanged = FALSE;
587 if (pchanged) *pchanged = TRUE;
589 for (i = 0; i < n; i++) {
591 if (ival == 0)
continue;
625 return (
BOXA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
663 return (
BOXA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
664 if (boxad && (boxad != boxas))
665 return (
BOXA *)ERROR_PTR(
"boxad defined but in-place", __func__, NULL);
671 index = (l_uint32)rand() % n;
672 index = L_MAX(1, index);
674 for (i = 1; i < n; i++) {
675 index = (l_uint32)rand() % n;
676 if (index == i) index--;
700 return ERROR_INT(
"boxa not defined", __func__, 1);
703 return ERROR_INT(
"i invalid", __func__, 1);
705 return ERROR_INT(
"j invalid", __func__, 1);
707 return ERROR_INT(
"i == j", __func__, 1);
710 boxa->
box[i] = boxa->
box[j];
746 return (
PTA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
747 if (ncorners != 2 && ncorners != 4)
748 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", __func__, NULL);
752 return (
PTA *)ERROR_PTR(
"pta not made", __func__, NULL);
753 for (i = 0; i < n; i++) {
784 l_int32 i, n, nbox, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
789 return (
BOXA *)ERROR_PTR(
"pta not defined", __func__, NULL);
790 if (ncorners != 2 && ncorners != 4)
791 return (
BOXA *)ERROR_PTR(
"ncorners not 2 or 4", __func__, NULL);
793 if (n % ncorners != 0)
794 return (
BOXA *)ERROR_PTR(
"size % ncorners != 0", __func__, NULL);
797 return (
BOXA *)ERROR_PTR(
"boxa not made", __func__, NULL);
798 for (i = 0; i < n; i += ncorners) {
802 box =
boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
810 xmax = L_MAX(x2, x4);
811 ymax = L_MAX(y3, y4);
812 box =
boxCreate(x, y, xmax - x + 1, ymax - y + 1);
841 return (
PTA *)ERROR_PTR(
"box not defined", __func__, NULL);
842 if (ncorners != 2 && ncorners != 4)
843 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", __func__, NULL);
846 return (
PTA *)ERROR_PTR(
"pta not made", __func__, NULL);
850 ptaAddPt(pta, x + w - 1, y + h - 1);
854 ptaAddPt(pta, x + w - 1, y + h - 1);
876 l_int32 n, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
879 return (
BOX *)ERROR_PTR(
"pta not defined", __func__, NULL);
884 return boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
891 xmax = L_MAX(x2, x4);
892 ymax = L_MAX(y3, y4);
893 return boxCreate(x, y, xmax - x + 1, ymax - y + 1);
927 l_int32 i, n, x, y, w, h, xmax, ymax, xmin, ymin, found;
929 if (!pw && !ph && !pbox)
930 return ERROR_INT(
"no ptrs defined", __func__, 1);
933 if (pbox) *pbox = NULL;
935 return ERROR_INT(
"boxa not defined", __func__, 1);
939 xmin = ymin = 100000000;
941 for (i = 0; i < n; i++) {
943 if (w <= 0 || h <= 0)
946 xmin = L_MIN(xmin, x);
947 ymin = L_MIN(ymin, y);
948 xmax = L_MAX(xmax, x + w);
949 ymax = L_MAX(ymax, y + h);
956 *pbox =
boxCreate(xmin, ymin, xmax - xmin, ymax - ymin);
992 l_int32 i, n, x, y, w, h, sum;
997 return ERROR_INT(
"&fract not defined", __func__, 1);
1000 return ERROR_INT(
"boxa not defined", __func__, 1);
1004 return ERROR_INT(
"no boxes in boxa", __func__, 1);
1006 if (exactflag == 0) {
1008 for (i = 0; i < n; i++) {
1019 for (i = 0; i < n; i++) {
1029 *pfract = (l_float32)sum / (l_float32)(wc * hc);
1051 l_int32 minw, minh, maxw, maxh, minbw, minbh, maxbw, maxbh, i, n;
1054 if (!pminw && !pmaxw && !pminh && !pmaxh)
1055 return ERROR_INT(
"no data can be returned", __func__, 1);
1056 if (pminw) *pminw = 0;
1057 if (pminh) *pminh = 0;
1058 if (pmaxw) *pmaxw = 0;
1059 if (pmaxh) *pmaxh = 0;
1061 return ERROR_INT(
"baa not defined", __func__, 1);
1063 minw = minh = 100000000;
1066 for (i = 0; i < n; i++) {
1080 if (pminw) *pminw = minw;
1081 if (pminh) *pminh = minh;
1082 if (pmaxw) *pmaxw = maxw;
1083 if (pmaxh) *pmaxh = maxh;
1105 l_int32 minw, minh, maxw, maxh, i, n, w, h;
1107 if (!pminw && !pmaxw && !pminh && !pmaxh)
1108 return ERROR_INT(
"no data can be returned", __func__, 1);
1109 if (pminw) *pminw = 0;
1110 if (pminh) *pminh = 0;
1111 if (pmaxw) *pmaxw = 0;
1112 if (pmaxh) *pmaxh = 0;
1114 return ERROR_INT(
"boxa not defined", __func__, 1);
1116 minw = minh = 100000000;
1119 for (i = 0; i < n; i++) {
1131 if (pminw) *pminw = minw;
1132 if (pminh) *pminh = minh;
1133 if (pmaxw) *pmaxw = maxw;
1134 if (pmaxh) *pmaxh = maxh;
1156 l_int32 minx, miny, maxx, maxy, i, n, x, y;
1158 if (!pminx && !pminy && !pmaxx && !pmaxy)
1159 return ERROR_INT(
"no data can be returned", __func__, 1);
1160 if (pminx) *pminx = 0;
1161 if (pminy) *pminy = 0;
1162 if (pmaxx) *pmaxx = 0;
1163 if (pmaxy) *pmaxy = 0;
1165 return ERROR_INT(
"boxa not defined", __func__, 1);
1167 minx = miny = 100000000;
1170 for (i = 0; i < n; i++) {
1182 if (pminx) *pminx = minx;
1183 if (pminy) *pminy = miny;
1184 if (pmaxx) *pmaxx = maxx;
1185 if (pmaxy) *pmaxy = maxy;
1207 if (pnaw) *pnaw = NULL;
1208 if (pnah) *pnah = NULL;
1210 return ERROR_INT(
"no output requested", __func__, 1);
1212 return ERROR_INT(
"boxa not defined", __func__, 1);
1217 for (i = 0; i < n; i++) {
1250 return ERROR_INT(
"&area not defined", __func__, 1);
1253 return ERROR_INT(
"boxa not defined", __func__, 1);
1256 for (i = 0; i < n; i++) {
1298 l_float32 scalefactor,
1304 l_int32 i, n, npix, w, h, fontsize;
1308 PIX *pix1, *pix2, *pixd;
1312 return (
PIX *)ERROR_PTR(
"boxas not defined", __func__, NULL);
1320 return (
PIX *)ERROR_PTR(
"boxa and pixa counts differ",
1324 first = L_MAX(0, first);
1325 if (last < 0) last = n - 1;
1328 return (
PIX *)ERROR_PTR(
"invalid first", __func__, NULL);
1331 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
1332 __func__, last, n - 1);
1337 return (
PIX *)ERROR_PTR(
"first > last", __func__, NULL);
1342 if (scalefactor > 0.8)
1344 else if (scalefactor > 0.6)
1346 else if (scalefactor > 0.4)
1348 else if (scalefactor > 0.3)
1355 for (i = first; i <= last; i++) {
1364 snprintf(buf,
sizeof(buf),
"%d", i);
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()
l_int32 boxaGetValidCount(BOXA *boxa)
boxaGetValidCount()
BOXA * boxaSaveValid(BOXA *boxas, l_int32 copyflag)
boxaSaveValid()
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
void boxDestroy(BOX **pbox)
boxDestroy()
BOXAA * boxaaCreate(l_int32 n)
boxaaCreate()
l_int32 boxaaGetCount(BOXAA *baa)
boxaaGetCount()
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
l_ok boxaaAddBoxa(BOXAA *baa, BOXA *ba, l_int32 copyflag)
boxaaAddBoxa()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_int32 boxaGetCount(const BOXA *boxa)
boxaGetCount()
BOX * boxaGetValidBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetValidBox()
BOXA * boxaaGetBoxa(BOXAA *baa, l_int32 index, l_int32 accessflag)
boxaaGetBoxa()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
BOXA * boxaSortByIndex(BOXA *boxas, NUMA *naindex)
boxaSortByIndex()
l_ok boxaSwapBoxes(BOXA *boxa, l_int32 i, l_int32 j)
boxaSwapBoxes()
l_ok boxaaSizeRange(BOXAA *baa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaaSizeRange()
BOXAA * boxaaSelectRange(BOXAA *baas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaaSelectRange()
BOXA * boxaSelectByWHRatio(BOXA *boxas, l_float32 ratio, l_int32 relation, l_int32 *pchanged)
boxaSelectByWHRatio()
l_ok boxaGetSizes(BOXA *boxa, NUMA **pnaw, NUMA **pnah)
boxaGetSizes()
BOXA * boxaSelectBySize(BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
boxaSelectBySize()
BOXA * ptaConvertToBoxa(PTA *pta, l_int32 ncorners)
ptaConvertToBoxa()
BOXA * boxaSelectByArea(BOXA *boxas, l_int32 area, l_int32 relation, l_int32 *pchanged)
boxaSelectByArea()
l_ok boxaGetArea(BOXA *boxa, l_int32 *parea)
boxaGetArea()
NUMA * boxaMakeAreaIndicator(BOXA *boxa, l_int32 area, l_int32 relation)
boxaMakeAreaIndicator()
NUMA * boxaMakeWHRatioIndicator(BOXA *boxa, l_float32 ratio, l_int32 relation)
boxaMakeWHRatioIndicator()
PIX * boxaDisplayTiled(BOXA *boxas, PIXA *pixa, l_int32 first, l_int32 last, l_int32 maxwidth, l_int32 linewidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
boxaDisplayTiled()
PTA * boxConvertToPta(BOX *box, l_int32 ncorners)
boxConvertToPta()
BOX * ptaConvertToBox(PTA *pta)
ptaConvertToBox()
l_ok boxaSizeRange(BOXA *boxa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaSizeRange()
l_ok boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
NUMA * boxaMakeSizeIndicator(BOXA *boxa, l_int32 width, l_int32 height, l_int32 type, l_int32 relation)
boxaMakeSizeIndicator()
PTA * boxaConvertToPta(BOXA *boxa, l_int32 ncorners)
boxaConvertToPta()
BOXA * boxaSelectRange(BOXA *boxas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaSelectRange()
BOXA * boxaPermuteRandom(BOXA *boxad, BOXA *boxas)
boxaPermuteRandom()
BOXA * boxaPermutePseudorandom(BOXA *boxas)
boxaPermutePseudorandom()
l_ok boxaGetCoverage(BOXA *boxa, l_int32 wc, l_int32 hc, l_int32 exactflag, l_float32 *pfract)
boxaGetCoverage()
BOXA * boxaSelectWithIndicator(BOXA *boxas, NUMA *na, l_int32 *pchanged)
boxaSelectWithIndicator()
l_ok boxaLocationRange(BOXA *boxa, l_int32 *pminx, l_int32 *pminy, l_int32 *pmaxx, l_int32 *pmaxy)
boxaLocationRange()
l_ok pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaCreate(l_int32 n)
numaCreate()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
NUMA * numaPseudorandomSequence(l_int32 size, l_int32 seed)
numaPseudorandomSequence()
void pixDestroy(PIX **ppix)
pixDestroy()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_ok pixSetBorderVal(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixSetBorderVal()
l_ok pixSetAll(PIX *pix)
pixSetAll()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
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 ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
PTA * ptaCreate(l_int32 n)
ptaCreate()
void ptaDestroy(PTA **ppta)
ptaDestroy()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
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()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()