68 #include "allheaders.h" 100 PROCNAME(
"boxaSelectRange");
103 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
105 return (
BOXA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
107 L_WARNING(
"boxas is empty\n", procName);
110 first = L_MAX(0, first);
111 if (last < 0) last = n - 1;
113 return (
BOXA *)ERROR_PTR(
"invalid first", procName, NULL);
115 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
116 procName, last, n - 1);
120 return (
BOXA *)ERROR_PTR(
"first > last", procName, NULL);
122 nbox = last - first + 1;
124 for (i = first; i <= last; i++) {
158 PROCNAME(
"boxaaSelectRange");
161 return (
BOXAA *)ERROR_PTR(
"baas not defined", procName, NULL);
163 return (
BOXAA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
165 return (
BOXAA *)ERROR_PTR(
"empty baas", procName, NULL);
166 first = L_MAX(0, first);
167 if (last < 0) last = n - 1;
169 return (
BOXAA *)ERROR_PTR(
"invalid first", procName, NULL);
171 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
172 procName, last, n - 1);
176 return (
BOXAA *)ERROR_PTR(
"first > last", procName, NULL);
178 nboxa = last - first + 1;
180 for (i = first; i <= last; i++) {
227 PROCNAME(
"boxaSelectBySize");
229 if (pchanged) *pchanged = FALSE;
231 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
233 L_WARNING(
"boxas is empty\n", procName);
238 return (
BOXA *)ERROR_PTR(
"invalid type", procName, NULL);
241 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
246 return (
BOXA *)ERROR_PTR(
"na not made", procName, NULL);
286 l_int32 i, n, w, h, ival;
289 PROCNAME(
"boxaMakeSizeIndicator");
292 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
294 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
297 return (
NUMA *)ERROR_PTR(
"invalid type", procName, NULL);
300 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
303 for (i = 0; i < n; i++) {
323 if (((relation ==
L_SELECT_IF_LT) && (w < width || h < height)) ||
330 if (((relation ==
L_SELECT_IF_LT) && (w < width && h < height)) ||
337 L_WARNING(
"can't get here!\n", procName);
375 PROCNAME(
"boxaSelectByArea");
377 if (pchanged) *pchanged = FALSE;
379 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
381 L_WARNING(
"boxas is empty\n", procName);
386 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
421 l_int32 i, n, w, h, ival;
424 PROCNAME(
"boxaMakeAreaIndicator");
427 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
429 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
432 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
435 for (i = 0; i < n; i++) {
479 PROCNAME(
"boxaSelectByWHRatio");
481 if (pchanged) *pchanged = FALSE;
483 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
485 L_WARNING(
"boxas is empty\n", procName);
490 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
525 l_int32 i, n, w, h, ival;
529 PROCNAME(
"boxaMakeWHRatioIndicator");
532 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
534 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
537 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
540 for (i = 0; i < n; i++) {
543 whratio = (l_float32)w / (l_float32)h;
577 l_int32 i, n, ival, nsave;
581 PROCNAME(
"boxaSelectWithIndicator");
583 if (pchanged) *pchanged = FALSE;
585 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
587 return (
BOXA *)ERROR_PTR(
"na not defined", procName, NULL);
591 for (i = 0; i < n; i++) {
593 if (ival == 1) nsave++;
597 if (pchanged) *pchanged = FALSE;
600 if (pchanged) *pchanged = TRUE;
602 for (i = 0; i < n; i++) {
604 if (ival == 0)
continue;
637 PROCNAME(
"boxaPermutePseudorandom");
640 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
677 PROCNAME(
"boxaPermuteRandom");
680 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
681 if (boxad && (boxad != boxas))
682 return (
BOXA *)ERROR_PTR(
"boxad defined but in-place", procName, NULL);
688 index = (l_uint32)rand() % n;
689 index = L_MAX(1, index);
691 for (i = 1; i < n; i++) {
692 index = (l_uint32)rand() % n;
693 if (index == i) index--;
716 PROCNAME(
"boxaSwapBoxes");
719 return ERROR_INT(
"boxa not defined", procName, 1);
722 return ERROR_INT(
"i invalid", procName, 1);
724 return ERROR_INT(
"j invalid", procName, 1);
726 return ERROR_INT(
"i == j", procName, 1);
729 boxa->
box[i] = boxa->
box[j];
760 PROCNAME(
"boxaConvertToPta");
763 return (
PTA *)ERROR_PTR(
"boxa not defined", procName, NULL);
764 if (ncorners != 2 && ncorners != 4)
765 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
769 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
770 for (i = 0; i < n; i++) {
801 l_int32 i, n, nbox, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
805 PROCNAME(
"ptaConvertToBoxa");
808 return (
BOXA *)ERROR_PTR(
"pta not defined", procName, NULL);
809 if (ncorners != 2 && ncorners != 4)
810 return (
BOXA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
812 if (n % ncorners != 0)
813 return (
BOXA *)ERROR_PTR(
"size % ncorners != 0", procName, NULL);
816 return (
BOXA *)ERROR_PTR(
"boxa not made", procName, NULL);
817 for (i = 0; i < n; i += ncorners) {
821 box =
boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
829 xmax = L_MAX(x2, x4);
830 ymax = L_MAX(y3, y4);
831 box =
boxCreate(x, y, xmax - x + 1, ymax - y + 1);
859 PROCNAME(
"boxConvertToPta");
862 return (
PTA *)ERROR_PTR(
"box not defined", procName, NULL);
863 if (ncorners != 2 && ncorners != 4)
864 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
867 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
871 ptaAddPt(pta, x + w - 1, y + h - 1);
875 ptaAddPt(pta, x + w - 1, y + h - 1);
897 l_int32 n, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
899 PROCNAME(
"ptaConvertToBox");
902 return (
BOX *)ERROR_PTR(
"pta not defined", procName, NULL);
907 return boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
914 xmax = L_MAX(x2, x4);
915 ymax = L_MAX(y3, y4);
916 return boxCreate(x, y, xmax - x + 1, ymax - y + 1);
948 l_int32 i, n, x, y, w, h, xmax, ymax, xmin, ymin, found;
950 PROCNAME(
"boxaGetExtent");
952 if (!pw && !ph && !pbox)
953 return ERROR_INT(
"no ptrs defined", procName, 1);
956 if (pbox) *pbox = NULL;
958 return ERROR_INT(
"boxa not defined", procName, 1);
962 xmin = ymin = 100000000;
964 for (i = 0; i < n; i++) {
966 if (w <= 0 || h <= 0)
969 xmin = L_MIN(xmin, x);
970 ymin = L_MIN(ymin, y);
971 xmax = L_MAX(xmax, x + w);
972 ymax = L_MAX(ymax, y + h);
979 *pbox =
boxCreate(xmin, ymin, xmax - xmin, ymax - ymin);
1015 l_int32 i, n, x, y, w, h, sum;
1019 PROCNAME(
"boxaGetCoverage");
1022 return ERROR_INT(
"&fract not defined", procName, 1);
1025 return ERROR_INT(
"boxa not defined", procName, 1);
1029 return ERROR_INT(
"no boxes in boxa", procName, 1);
1031 if (exactflag == 0) {
1033 for (i = 0; i < n; i++) {
1044 for (i = 0; i < n; i++) {
1054 *pfract = (l_float32)sum / (l_float32)(wc * hc);
1076 l_int32 minw, minh, maxw, maxh, minbw, minbh, maxbw, maxbh, i, n;
1079 PROCNAME(
"boxaaSizeRange");
1081 if (!pminw && !pmaxw && !pminh && !pmaxh)
1082 return ERROR_INT(
"no data can be returned", procName, 1);
1083 if (pminw) *pminw = 0;
1084 if (pminh) *pminh = 0;
1085 if (pmaxw) *pmaxw = 0;
1086 if (pmaxh) *pmaxh = 0;
1088 return ERROR_INT(
"baa not defined", procName, 1);
1090 minw = minh = 100000000;
1093 for (i = 0; i < n; i++) {
1107 if (pminw) *pminw = minw;
1108 if (pminh) *pminh = minh;
1109 if (pmaxw) *pmaxw = maxw;
1110 if (pmaxh) *pmaxh = maxh;
1132 l_int32 minw, minh, maxw, maxh, i, n, w, h;
1134 PROCNAME(
"boxaSizeRange");
1136 if (!pminw && !pmaxw && !pminh && !pmaxh)
1137 return ERROR_INT(
"no data can be returned", procName, 1);
1138 if (pminw) *pminw = 0;
1139 if (pminh) *pminh = 0;
1140 if (pmaxw) *pmaxw = 0;
1141 if (pmaxh) *pmaxh = 0;
1143 return ERROR_INT(
"boxa not defined", procName, 1);
1145 minw = minh = 100000000;
1148 for (i = 0; i < n; i++) {
1160 if (pminw) *pminw = minw;
1161 if (pminh) *pminh = minh;
1162 if (pmaxw) *pmaxw = maxw;
1163 if (pmaxh) *pmaxh = maxh;
1185 l_int32 minx, miny, maxx, maxy, i, n, x, y;
1187 PROCNAME(
"boxaLocationRange");
1189 if (!pminx && !pminy && !pmaxx && !pmaxy)
1190 return ERROR_INT(
"no data can be returned", procName, 1);
1191 if (pminx) *pminx = 0;
1192 if (pminy) *pminy = 0;
1193 if (pmaxx) *pmaxx = 0;
1194 if (pmaxy) *pmaxy = 0;
1196 return ERROR_INT(
"boxa not defined", procName, 1);
1198 minx = miny = 100000000;
1201 for (i = 0; i < n; i++) {
1213 if (pminx) *pminx = minx;
1214 if (pminy) *pminy = miny;
1215 if (pmaxx) *pmaxx = maxx;
1216 if (pmaxy) *pmaxy = maxy;
1238 PROCNAME(
"boxaGetSizes");
1240 if (pnaw) *pnaw = NULL;
1241 if (pnah) *pnah = NULL;
1243 return ERROR_INT(
"no output requested", procName, 1);
1245 return ERROR_INT(
"boxa not defined", procName, 1);
1250 for (i = 0; i < n; i++) {
1282 PROCNAME(
"boxaGetArea");
1285 return ERROR_INT(
"&area not defined", procName, 1);
1288 return ERROR_INT(
"boxa not defined", procName, 1);
1291 for (i = 0; i < n; i++) {
1333 l_float32 scalefactor,
1339 l_int32 i, n, npix, w, h, fontsize;
1343 PIX *pix1, *pix2, *pixd;
1346 PROCNAME(
"boxaDisplayTiled");
1349 return (
PIX *)ERROR_PTR(
"boxas not defined", procName, NULL);
1357 return (
PIX *)ERROR_PTR(
"boxa and pixa counts differ",
1361 first = L_MAX(0, first);
1362 if (last < 0) last = n - 1;
1364 return (
PIX *)ERROR_PTR(
"invalid first", procName, NULL);
1366 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
1367 procName, last, n - 1);
1371 return (
PIX *)ERROR_PTR(
"first > last", procName, NULL);
1375 if (scalefactor > 0.8)
1377 else if (scalefactor > 0.6)
1379 else if (scalefactor > 0.4)
1381 else if (scalefactor > 0.3)
1388 for (i = first; i <= last; i++) {
1397 snprintf(buf,
sizeof(buf),
"%d", i);
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
BOX * boxaGetValidBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetValidBox()
l_ok boxaSwapBoxes(BOXA *boxa, l_int32 i, l_int32 j)
boxaSwapBoxes()
PTA * boxaConvertToPta(BOXA *boxa, l_int32 ncorners)
boxaConvertToPta()
BOXA * boxaSelectRange(BOXA *boxas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaSelectRange()
l_ok boxaSizeRange(BOXA *boxa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaSizeRange()
l_ok ptaAddPt(PTA *pta, l_float32 x, l_float32 y)
ptaAddPt()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_ok boxaGetSizes(BOXA *boxa, NUMA **pnaw, NUMA **pnah)
boxaGetSizes()
l_int32 boxaaGetCount(BOXAA *baa)
boxaaGetCount()
l_ok boxaaSizeRange(BOXAA *baa, l_int32 *pminw, l_int32 *pminh, l_int32 *pmaxw, l_int32 *pmaxh)
boxaaSizeRange()
BOXA * boxaSelectBySize(BOXA *boxas, l_int32 width, l_int32 height, l_int32 type, l_int32 relation, l_int32 *pchanged)
boxaSelectBySize()
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()
PTA * ptaCreate(l_int32 n)
ptaCreate()
NUMA * boxaMakeSizeIndicator(BOXA *boxa, l_int32 width, l_int32 height, l_int32 type, l_int32 relation)
boxaMakeSizeIndicator()
BOX * boxClipToRectangle(BOX *box, l_int32 wi, l_int32 hi)
boxClipToRectangle()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_ok pixSetAll(PIX *pix)
pixSetAll()
BOXA * ptaConvertToBoxa(PTA *pta, l_int32 ncorners)
ptaConvertToBoxa()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_ok ptaJoin(PTA *ptad, PTA *ptas, l_int32 istart, l_int32 iend)
ptaJoin()
l_ok pixSetBorderVal(PIX *pixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot, l_uint32 val)
pixSetBorderVal()
BOXAA * boxaaSelectRange(BOXAA *baas, l_int32 first, l_int32 last, l_int32 copyflag)
boxaaSelectRange()
l_ok boxaaAddBoxa(BOXAA *baa, BOXA *ba, l_int32 copyflag)
boxaaAddBoxa()
NUMA * numaPseudorandomSequence(l_int32 size, l_int32 seed)
numaPseudorandomSequence()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
BOXA * boxaSaveValid(BOXA *boxas, l_int32 copyflag)
boxaSaveValid()
l_ok boxaGetArea(BOXA *boxa, l_int32 *parea)
boxaGetArea()
PIX * pixaDisplayTiledInRows(PIXA *pixa, l_int32 outdepth, l_int32 maxwidth, l_float32 scalefactor, l_int32 background, l_int32 spacing, l_int32 border)
pixaDisplayTiledInRows()
BOXA * boxaPermuteRandom(BOXA *boxad, BOXA *boxas)
boxaPermuteRandom()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
BOXA * boxaSelectByWHRatio(BOXA *boxas, l_float32 ratio, l_int32 relation, l_int32 *pchanged)
boxaSelectByWHRatio()
BOXA * boxaSelectByArea(BOXA *boxas, l_int32 area, l_int32 relation, l_int32 *pchanged)
boxaSelectByArea()
void pixDestroy(PIX **ppix)
pixDestroy()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
l_ok boxaLocationRange(BOXA *boxa, l_int32 *pminx, l_int32 *pminy, l_int32 *pmaxx, l_int32 *pmaxy)
boxaLocationRange()
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()
l_ok boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
void numaDestroy(NUMA **pna)
numaDestroy()
NUMA * boxaMakeAreaIndicator(BOXA *boxa, l_int32 area, l_int32 relation)
boxaMakeAreaIndicator()
BOXAA * boxaaCreate(l_int32 n)
boxaaCreate()
BOXA * boxaSelectWithIndicator(BOXA *boxas, NUMA *na, l_int32 *pchanged)
boxaSelectWithIndicator()
l_int32 boxaGetValidCount(BOXA *boxa)
boxaGetValidCount()
PTA * boxConvertToPta(BOX *box, l_int32 ncorners)
boxConvertToPta()
BOXA * boxaPermutePseudorandom(BOXA *boxas)
boxaPermutePseudorandom()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
l_ok pixRenderBoxArb(PIX *pix, BOX *box, l_int32 width, l_uint8 rval, l_uint8 gval, l_uint8 bval)
pixRenderBoxArb()
l_ok boxaGetCoverage(BOXA *boxa, l_int32 wc, l_int32 hc, l_int32 exactflag, l_float32 *pfract)
boxaGetCoverage()
void ptaDestroy(PTA **ppta)
ptaDestroy()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
void boxDestroy(BOX **pbox)
boxDestroy()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
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()
NUMA * boxaMakeWHRatioIndicator(BOXA *boxa, l_float32 ratio, l_int32 relation)
boxaMakeWHRatioIndicator()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
BOX * ptaConvertToBox(PTA *pta)
ptaConvertToBox()
BOXA * boxaaGetBoxa(BOXAA *baa, l_int32 index, l_int32 accessflag)
boxaaGetBoxa()
BOXA * boxaSortByIndex(BOXA *boxas, NUMA *naindex)
boxaSortByIndex()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()