68 #include <config_auto.h> 72 #include "allheaders.h" 103 PROCNAME(
"boxaSelectRange");
106 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
108 return (
BOXA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
110 L_WARNING(
"boxas is empty\n", procName);
113 first = L_MAX(0, first);
114 if (last < 0) last = n - 1;
116 return (
BOXA *)ERROR_PTR(
"invalid first", procName, NULL);
118 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
119 procName, last, n - 1);
123 return (
BOXA *)ERROR_PTR(
"first > last", procName, NULL);
125 nbox = last - first + 1;
127 for (i = first; i <= last; i++) {
161 PROCNAME(
"boxaaSelectRange");
164 return (
BOXAA *)ERROR_PTR(
"baas not defined", procName, NULL);
166 return (
BOXAA *)ERROR_PTR(
"invalid copyflag", procName, NULL);
168 return (
BOXAA *)ERROR_PTR(
"empty baas", procName, NULL);
169 first = L_MAX(0, first);
170 if (last < 0) last = n - 1;
172 return (
BOXAA *)ERROR_PTR(
"invalid first", procName, NULL);
174 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
175 procName, last, n - 1);
179 return (
BOXAA *)ERROR_PTR(
"first > last", procName, NULL);
181 nboxa = last - first + 1;
183 for (i = first; i <= last; i++) {
230 PROCNAME(
"boxaSelectBySize");
232 if (pchanged) *pchanged = FALSE;
234 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
236 L_WARNING(
"boxas is empty\n", procName);
241 return (
BOXA *)ERROR_PTR(
"invalid type", procName, NULL);
244 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
249 return (
BOXA *)ERROR_PTR(
"na not made", procName, NULL);
289 l_int32 i, n, w, h, ival;
292 PROCNAME(
"boxaMakeSizeIndicator");
295 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
297 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
300 return (
NUMA *)ERROR_PTR(
"invalid type", procName, NULL);
303 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
306 for (i = 0; i < n; i++) {
326 if (((relation ==
L_SELECT_IF_LT) && (w < width || h < height)) ||
333 if (((relation ==
L_SELECT_IF_LT) && (w < width && h < height)) ||
340 L_WARNING(
"can't get here!\n", procName);
378 PROCNAME(
"boxaSelectByArea");
380 if (pchanged) *pchanged = FALSE;
382 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
384 L_WARNING(
"boxas is empty\n", procName);
389 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
424 l_int32 i, n, w, h, ival;
427 PROCNAME(
"boxaMakeAreaIndicator");
430 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
432 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
435 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
438 for (i = 0; i < n; i++) {
482 PROCNAME(
"boxaSelectByWHRatio");
484 if (pchanged) *pchanged = FALSE;
486 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
488 L_WARNING(
"boxas is empty\n", procName);
493 return (
BOXA *)ERROR_PTR(
"invalid relation", procName, NULL);
528 l_int32 i, n, w, h, ival;
532 PROCNAME(
"boxaMakeWHRatioIndicator");
535 return (
NUMA *)ERROR_PTR(
"boxa not defined", procName, NULL);
537 return (
NUMA *)ERROR_PTR(
"boxa is empty", procName, NULL);
540 return (
NUMA *)ERROR_PTR(
"invalid relation", procName, NULL);
543 for (i = 0; i < n; i++) {
546 whratio = (l_float32)w / (l_float32)h;
581 l_int32 i, n, ival, nsave;
585 PROCNAME(
"boxaSelectWithIndicator");
587 if (pchanged) *pchanged = FALSE;
589 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
591 return (
BOXA *)ERROR_PTR(
"na not defined", procName, NULL);
595 for (i = 0; i < n; i++) {
597 if (ival == 1) nsave++;
601 if (pchanged) *pchanged = FALSE;
604 if (pchanged) *pchanged = TRUE;
606 for (i = 0; i < n; i++) {
608 if (ival == 0)
continue;
641 PROCNAME(
"boxaPermutePseudorandom");
644 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
681 PROCNAME(
"boxaPermuteRandom");
684 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
685 if (boxad && (boxad != boxas))
686 return (
BOXA *)ERROR_PTR(
"boxad defined but in-place", procName, NULL);
692 index = (l_uint32)rand() % n;
693 index = L_MAX(1, index);
695 for (i = 1; i < n; i++) {
696 index = (l_uint32)rand() % n;
697 if (index == i) index--;
720 PROCNAME(
"boxaSwapBoxes");
723 return ERROR_INT(
"boxa not defined", procName, 1);
726 return ERROR_INT(
"i invalid", procName, 1);
728 return ERROR_INT(
"j invalid", procName, 1);
730 return ERROR_INT(
"i == j", procName, 1);
733 boxa->
box[i] = boxa->
box[j];
768 PROCNAME(
"boxaConvertToPta");
771 return (
PTA *)ERROR_PTR(
"boxa not defined", procName, NULL);
772 if (ncorners != 2 && ncorners != 4)
773 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
777 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
778 for (i = 0; i < n; i++) {
809 l_int32 i, n, nbox, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
813 PROCNAME(
"ptaConvertToBoxa");
816 return (
BOXA *)ERROR_PTR(
"pta not defined", procName, NULL);
817 if (ncorners != 2 && ncorners != 4)
818 return (
BOXA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
820 if (n % ncorners != 0)
821 return (
BOXA *)ERROR_PTR(
"size % ncorners != 0", procName, NULL);
824 return (
BOXA *)ERROR_PTR(
"boxa not made", procName, NULL);
825 for (i = 0; i < n; i += ncorners) {
829 box =
boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
837 xmax = L_MAX(x2, x4);
838 ymax = L_MAX(y3, y4);
839 box =
boxCreate(x, y, xmax - x + 1, ymax - y + 1);
867 PROCNAME(
"boxConvertToPta");
870 return (
PTA *)ERROR_PTR(
"box not defined", procName, NULL);
871 if (ncorners != 2 && ncorners != 4)
872 return (
PTA *)ERROR_PTR(
"ncorners not 2 or 4", procName, NULL);
875 return (
PTA *)ERROR_PTR(
"pta not made", procName, NULL);
879 ptaAddPt(pta, x + w - 1, y + h - 1);
883 ptaAddPt(pta, x + w - 1, y + h - 1);
905 l_int32 n, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax;
907 PROCNAME(
"ptaConvertToBox");
910 return (
BOX *)ERROR_PTR(
"pta not defined", procName, NULL);
915 return boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
922 xmax = L_MAX(x2, x4);
923 ymax = L_MAX(y3, y4);
924 return boxCreate(x, y, xmax - x + 1, ymax - y + 1);
958 l_int32 i, n, x, y, w, h, xmax, ymax, xmin, ymin, found;
960 PROCNAME(
"boxaGetExtent");
962 if (!pw && !ph && !pbox)
963 return ERROR_INT(
"no ptrs defined", procName, 1);
966 if (pbox) *pbox = NULL;
968 return ERROR_INT(
"boxa not defined", procName, 1);
972 xmin = ymin = 100000000;
974 for (i = 0; i < n; i++) {
976 if (w <= 0 || h <= 0)
979 xmin = L_MIN(xmin, x);
980 ymin = L_MIN(ymin, y);
981 xmax = L_MAX(xmax, x + w);
982 ymax = L_MAX(ymax, y + h);
989 *pbox =
boxCreate(xmin, ymin, xmax - xmin, ymax - ymin);
1025 l_int32 i, n, x, y, w, h, sum;
1029 PROCNAME(
"boxaGetCoverage");
1032 return ERROR_INT(
"&fract not defined", procName, 1);
1035 return ERROR_INT(
"boxa not defined", procName, 1);
1039 return ERROR_INT(
"no boxes in boxa", procName, 1);
1041 if (exactflag == 0) {
1043 for (i = 0; i < n; i++) {
1054 for (i = 0; i < n; i++) {
1064 *pfract = (l_float32)sum / (l_float32)(wc * hc);
1086 l_int32 minw, minh, maxw, maxh, minbw, minbh, maxbw, maxbh, i, n;
1089 PROCNAME(
"boxaaSizeRange");
1091 if (!pminw && !pmaxw && !pminh && !pmaxh)
1092 return ERROR_INT(
"no data can be returned", procName, 1);
1093 if (pminw) *pminw = 0;
1094 if (pminh) *pminh = 0;
1095 if (pmaxw) *pmaxw = 0;
1096 if (pmaxh) *pmaxh = 0;
1098 return ERROR_INT(
"baa not defined", procName, 1);
1100 minw = minh = 100000000;
1103 for (i = 0; i < n; i++) {
1117 if (pminw) *pminw = minw;
1118 if (pminh) *pminh = minh;
1119 if (pmaxw) *pmaxw = maxw;
1120 if (pmaxh) *pmaxh = maxh;
1142 l_int32 minw, minh, maxw, maxh, i, n, w, h;
1144 PROCNAME(
"boxaSizeRange");
1146 if (!pminw && !pmaxw && !pminh && !pmaxh)
1147 return ERROR_INT(
"no data can be returned", procName, 1);
1148 if (pminw) *pminw = 0;
1149 if (pminh) *pminh = 0;
1150 if (pmaxw) *pmaxw = 0;
1151 if (pmaxh) *pmaxh = 0;
1153 return ERROR_INT(
"boxa not defined", procName, 1);
1155 minw = minh = 100000000;
1158 for (i = 0; i < n; i++) {
1170 if (pminw) *pminw = minw;
1171 if (pminh) *pminh = minh;
1172 if (pmaxw) *pmaxw = maxw;
1173 if (pmaxh) *pmaxh = maxh;
1195 l_int32 minx, miny, maxx, maxy, i, n, x, y;
1197 PROCNAME(
"boxaLocationRange");
1199 if (!pminx && !pminy && !pmaxx && !pmaxy)
1200 return ERROR_INT(
"no data can be returned", procName, 1);
1201 if (pminx) *pminx = 0;
1202 if (pminy) *pminy = 0;
1203 if (pmaxx) *pmaxx = 0;
1204 if (pmaxy) *pmaxy = 0;
1206 return ERROR_INT(
"boxa not defined", procName, 1);
1208 minx = miny = 100000000;
1211 for (i = 0; i < n; i++) {
1223 if (pminx) *pminx = minx;
1224 if (pminy) *pminy = miny;
1225 if (pmaxx) *pmaxx = maxx;
1226 if (pmaxy) *pmaxy = maxy;
1248 PROCNAME(
"boxaGetSizes");
1250 if (pnaw) *pnaw = NULL;
1251 if (pnah) *pnah = NULL;
1253 return ERROR_INT(
"no output requested", procName, 1);
1255 return ERROR_INT(
"boxa not defined", procName, 1);
1260 for (i = 0; i < n; i++) {
1292 PROCNAME(
"boxaGetArea");
1295 return ERROR_INT(
"&area not defined", procName, 1);
1298 return ERROR_INT(
"boxa not defined", procName, 1);
1301 for (i = 0; i < n; i++) {
1343 l_float32 scalefactor,
1349 l_int32 i, n, npix, w, h, fontsize;
1353 PIX *pix1, *pix2, *pixd;
1356 PROCNAME(
"boxaDisplayTiled");
1359 return (
PIX *)ERROR_PTR(
"boxas not defined", procName, NULL);
1367 return (
PIX *)ERROR_PTR(
"boxa and pixa counts differ",
1371 first = L_MAX(0, first);
1372 if (last < 0) last = n - 1;
1375 return (
PIX *)ERROR_PTR(
"invalid first", procName, NULL);
1378 L_WARNING(
"last = %d is beyond max index = %d; adjusting\n",
1379 procName, last, n - 1);
1384 return (
PIX *)ERROR_PTR(
"first > last", procName, NULL);
1389 if (scalefactor > 0.8)
1391 else if (scalefactor > 0.6)
1393 else if (scalefactor > 0.4)
1395 else if (scalefactor > 0.3)
1402 for (i = first; i <= last; i++) {
1411 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()