143 #include <config_auto.h> 147 #include "allheaders.h" 150 static const l_uint32 MaxPtrArraySize = 10000;
154 static const l_uint32 MaxKernelSize = 10000;
157 static const l_uint32 MaxPixTemplateSize = 100;
158 static const l_uint32 MaxPixTemplateHits = 1000;
176 { { 2, 2, 1,
"sel_2h",
"",
"sel_2v",
"" },
177 { 3, 3, 1,
"sel_3h",
"",
"sel_3v",
"" },
178 { 4, 2, 2,
"sel_2h",
"sel_comb_4h",
"sel_2v",
"sel_comb_4v" },
179 { 5, 5, 1,
"sel_5h",
"",
"sel_5v",
"" },
180 { 6, 3, 2,
"sel_3h",
"sel_comb_6h",
"sel_3v",
"sel_comb_6v" },
181 { 7, 7, 1,
"sel_7h",
"",
"sel_7v",
"" },
182 { 8, 4, 2,
"sel_4h",
"sel_comb_8h",
"sel_4v",
"sel_comb_8v" },
183 { 9, 3, 3,
"sel_3h",
"sel_comb_9h",
"sel_3v",
"sel_comb_9v" },
184 { 10, 5, 2,
"sel_5h",
"sel_comb_10h",
"sel_5v",
"sel_comb_10v" },
185 { 11, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
186 { 12, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
187 { 13, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
188 { 14, 7, 2,
"sel_7h",
"sel_comb_14h",
"sel_7v",
"sel_comb_14v" },
189 { 15, 5, 3,
"sel_5h",
"sel_comb_15h",
"sel_5v",
"sel_comb_15v" },
190 { 16, 4, 4,
"sel_4h",
"sel_comb_16h",
"sel_4v",
"sel_comb_16v" },
191 { 17, 4, 4,
"sel_4h",
"sel_comb_16h",
"sel_4v",
"sel_comb_16v" },
192 { 18, 6, 3,
"sel_6h",
"sel_comb_18h",
"sel_6v",
"sel_comb_18v" },
193 { 19, 5, 4,
"sel_5h",
"sel_comb_20h",
"sel_5v",
"sel_comb_20v" },
194 { 20, 5, 4,
"sel_5h",
"sel_comb_20h",
"sel_5v",
"sel_comb_20v" },
195 { 21, 7, 3,
"sel_7h",
"sel_comb_21h",
"sel_7v",
"sel_comb_21v" },
196 { 22, 11, 2,
"sel_11h",
"sel_comb_22h",
"sel_11v",
"sel_comb_22v" },
197 { 23, 6, 4,
"sel_6h",
"sel_comb_24h",
"sel_6v",
"sel_comb_24v" },
198 { 24, 6, 4,
"sel_6h",
"sel_comb_24h",
"sel_6v",
"sel_comb_24v" },
199 { 25, 5, 5,
"sel_5h",
"sel_comb_25h",
"sel_5v",
"sel_comb_25v" },
200 { 26, 5, 5,
"sel_5h",
"sel_comb_25h",
"sel_5v",
"sel_comb_25v" },
201 { 27, 9, 3,
"sel_9h",
"sel_comb_27h",
"sel_9v",
"sel_comb_27v" },
202 { 28, 7, 4,
"sel_7h",
"sel_comb_28h",
"sel_7v",
"sel_comb_28v" },
203 { 29, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
204 { 30, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
205 { 31, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
206 { 32, 8, 4,
"sel_8h",
"sel_comb_32h",
"sel_8v",
"sel_comb_32v" },
207 { 33, 11, 3,
"sel_11h",
"sel_comb_33h",
"sel_11v",
"sel_comb_33v" },
208 { 34, 7, 5,
"sel_7h",
"sel_comb_35h",
"sel_7v",
"sel_comb_35v" },
209 { 35, 7, 5,
"sel_7h",
"sel_comb_35h",
"sel_7v",
"sel_comb_35v" },
210 { 36, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
211 { 37, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
212 { 38, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
213 { 39, 13, 3,
"sel_13h",
"sel_comb_39h",
"sel_13v",
"sel_comb_39v" },
214 { 40, 8, 5,
"sel_8h",
"sel_comb_40h",
"sel_8v",
"sel_comb_40v" },
215 { 41, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
216 { 42, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
217 { 43, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
218 { 44, 11, 4,
"sel_11h",
"sel_comb_44h",
"sel_11v",
"sel_comb_44v" },
219 { 45, 9, 5,
"sel_9h",
"sel_comb_45h",
"sel_9v",
"sel_comb_45v" },
220 { 46, 9, 5,
"sel_9h",
"sel_comb_45h",
"sel_9v",
"sel_comb_45v" },
221 { 47, 8, 6,
"sel_8h",
"sel_comb_48h",
"sel_8v",
"sel_comb_48v" },
222 { 48, 8, 6,
"sel_8h",
"sel_comb_48h",
"sel_8v",
"sel_comb_48v" },
223 { 49, 7, 7,
"sel_7h",
"sel_comb_49h",
"sel_7v",
"sel_comb_49v" },
224 { 50, 10, 5,
"sel_10h",
"sel_comb_50h",
"sel_10v",
"sel_comb_50v" },
225 { 51, 10, 5,
"sel_10h",
"sel_comb_50h",
"sel_10v",
"sel_comb_50v" },
226 { 52, 13, 4,
"sel_13h",
"sel_comb_52h",
"sel_13v",
"sel_comb_52v" },
227 { 53, 9, 6,
"sel_9h",
"sel_comb_54h",
"sel_9v",
"sel_comb_54v" },
228 { 54, 9, 6,
"sel_9h",
"sel_comb_54h",
"sel_9v",
"sel_comb_54v" },
229 { 55, 11, 5,
"sel_11h",
"sel_comb_55h",
"sel_11v",
"sel_comb_55v" },
230 { 56, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
231 { 57, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
232 { 58, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
233 { 59, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
234 { 60, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
235 { 61, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
236 { 62, 9, 7,
"sel_9h",
"sel_comb_63h",
"sel_9v",
"sel_comb_63v" },
237 { 63, 9, 7,
"sel_9h",
"sel_comb_63h",
"sel_9v",
"sel_comb_63v" } };
255 PROCNAME(
"selaCreate");
257 if (n <= 0 || n > MaxPtrArraySize)
261 sela = (
SELA *)LEPT_CALLOC(1,
sizeof(
SELA));
264 sela->
sel = (
SEL **)LEPT_CALLOC(n,
sizeof(
SEL *));
282 if ((sela = *psela) == NULL)
285 for (i = 0; i < sela->
n; i++)
287 LEPT_FREE(sela->
sel);
316 PROCNAME(
"selCreate");
318 sel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL));
324 LEPT_FREE(sel->
name);
326 return (
SEL *)ERROR_PTR(
"data not allocated", procName, NULL);
345 PROCNAME(
"selDestroy");
348 L_WARNING(
"ptr address is NULL!\n", procName);
351 if ((sel = *psel) == NULL)
354 for (i = 0; i < sel->
sy; i++)
355 LEPT_FREE(sel->
data[i]);
356 LEPT_FREE(sel->
data);
358 LEPT_FREE(sel->
name);
373 l_int32 sx, sy, cx, cy, i, j;
379 return (
SEL *)ERROR_PTR(
"sel not defined", procName, NULL);
381 csel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL));
390 return (
SEL *)ERROR_PTR(
"sel data not made", procName, NULL);
393 for (i = 0; i < sy; i++)
394 for (j = 0; j < sx; j++)
427 PROCNAME(
"selCreateBrick");
429 if (h <= 0 || w <= 0)
430 return (
SEL *)ERROR_PTR(
"h and w must both be > 0", procName, NULL);
431 if (type != SEL_HIT && type != SEL_MISS && type != SEL_DONT_CARE)
432 return (
SEL *)ERROR_PTR(
"invalid sel element type", procName, NULL);
434 if ((sel =
selCreate(h, w, NULL)) == NULL)
435 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
437 for (i = 0; i < h; i++)
438 for (j = 0; j < w; j++)
439 sel->
data[i][j] = type;
469 PROCNAME(
"selCreateComb");
471 if (factor1 < 1 || factor2 < 1)
472 return (
SEL *)ERROR_PTR(
"factors must be >= 1", procName, NULL);
473 if (direction != L_HORIZ && direction != L_VERT)
474 return (
SEL *)ERROR_PTR(
"invalid direction", procName, NULL);
476 size = factor1 * factor2;
477 if (direction == L_HORIZ) {
478 if ((sel =
selCreate(1, size, NULL)) == NULL)
479 return (
SEL *)ERROR_PTR(
"horiz sel not made", procName, NULL);
482 if ((sel =
selCreate(size, 1, NULL)) == NULL)
483 return (
SEL *)ERROR_PTR(
"vert sel not made", procName, NULL);
488 for (i = 0; i < factor2; i++) {
489 z = factor1 / 2 + i * factor1;
492 if (direction == L_HORIZ)
523 PROCNAME(
"create2dIntArray");
525 if (sx <= 0 || sx > MaxKernelSize)
526 return (l_int32 **)ERROR_PTR(
"sx out of bounds", procName, NULL);
527 if (sy <= 0 || sy > MaxKernelSize)
528 return (l_int32 **)ERROR_PTR(
"sy out of bounds", procName, NULL);
530 array = (l_int32 **)LEPT_CALLOC(sy,
sizeof(l_int32 *));
531 for (i = 0; i < sy; i++)
532 array[i] = (l_int32 *)LEPT_CALLOC(sx,
sizeof(l_int32));
567 PROCNAME(
"selaAddSel");
570 return ERROR_INT(
"sela not defined", procName, 1);
572 return ERROR_INT(
"sel not defined", procName, 1);
573 if (!sel->
name && !selname)
574 return ERROR_INT(
"added sel must have name", procName, 1);
576 return ERROR_INT(
"invalid copyflag", procName, 1);
579 if ((csel =
selCopy(sel)) == NULL)
580 return ERROR_INT(
"csel not made", procName, 1);
592 return ERROR_INT(
"extension failed", procName, 1);
611 PROCNAME(
"selaExtendArray");
614 return ERROR_INT(
"sela not defined", procName, 1);
617 sizeof(
SEL *) * sela->
nalloc,
618 2 *
sizeof(
SEL *) * sela->
nalloc)) == NULL)
619 return ERROR_INT(
"new ptr array not returned", procName, 1);
639 PROCNAME(
"selaGetCount");
642 return ERROR_INT(
"sela not defined", procName, 0);
665 PROCNAME(
"selaGetSel");
668 return (
SEL *)ERROR_PTR(
"sela not defined", procName, NULL);
670 if (i < 0 || i >= sela->
n)
671 return (
SEL *)ERROR_PTR(
"invalid index", procName, NULL);
685 PROCNAME(
"selGetName");
688 return (
char *)ERROR_PTR(
"sel not defined", procName, NULL);
711 PROCNAME(
"selSetName");
714 return ERROR_INT(
"sel not defined", procName, 1);
739 PROCNAME(
"selaFindSelByName");
741 if (pindex) *pindex = -1;
742 if (psel) *psel = NULL;
745 return ERROR_INT(
"sela not defined", procName, 1);
748 for (i = 0; i < n; i++)
751 L_WARNING(
"missing sel\n", procName);
756 if (sname && (!strcmp(name, sname))) {
784 PROCNAME(
"selGetElement");
787 return ERROR_INT(
"&type not defined", procName, 1);
788 *ptype = SEL_DONT_CARE;
790 return ERROR_INT(
"sel not defined", procName, 1);
791 if (row < 0 || row >= sel->
sy)
792 return ERROR_INT(
"sel row out of bounds", procName, 1);
793 if (col < 0 || col >= sel->
sx)
794 return ERROR_INT(
"sel col out of bounds", procName, 1);
796 *ptype = sel->
data[row][col];
824 PROCNAME(
"selSetElement");
827 return ERROR_INT(
"sel not defined", procName, 1);
828 if (type != SEL_HIT && type != SEL_MISS && type != SEL_DONT_CARE)
829 return ERROR_INT(
"invalid sel element type", procName, 1);
830 if (row < 0 || row >= sel->
sy)
831 return ERROR_INT(
"sel row out of bounds", procName, 1);
832 if (col < 0 || col >= sel->
sx)
833 return ERROR_INT(
"sel col out of bounds", procName, 1);
835 sel->
data[row][col] = type;
854 PROCNAME(
"selGetParameters");
861 return ERROR_INT(
"sel not defined", procName, 1);
862 if (psy) *psy = sel->
sy;
863 if (psx) *psx = sel->
sx;
864 if (pcy) *pcy = sel->
cy;
865 if (pcx) *pcx = sel->
cx;
882 PROCNAME(
"selSetOrigin");
885 return ERROR_INT(
"sel not defined", procName, 1);
903 l_int32 sx, sy, cx, cy, i, j;
905 PROCNAME(
"selGetTypeAtOrigin");
908 return ERROR_INT(
"&type not defined", procName, 1);
909 *ptype = SEL_DONT_CARE;
911 return ERROR_INT(
"sel not defined", procName, 1);
914 for (i = 0; i < sy; i++) {
915 for (j = 0; j < sx; j++) {
916 if (i == cy && j == cx) {
923 return ERROR_INT(
"sel origin not found", procName, 1);
939 l_int32 i, nsels, sx, sy;
942 PROCNAME(
"selaGetBrickName");
945 return (
char *)ERROR_PTR(
"sela not defined", procName, NULL);
948 for (i = 0; i < nsels; i++) {
951 if (hsize == sx && vsize == sy)
955 return (
char *)ERROR_PTR(
"sel not found", procName, NULL);
980 l_int32 i, nsels, sx, sy, found;
983 PROCNAME(
"selaGetCombName");
986 return (
char *)ERROR_PTR(
"sela not defined", procName, NULL);
987 if (direction != L_HORIZ && direction != L_VERT)
988 return (
char *)ERROR_PTR(
"invalid direction", procName, NULL);
991 if (direction == L_HORIZ)
992 snprintf(combname,
sizeof(combname),
"sel_comb_%dh", size);
994 snprintf(combname,
sizeof(combname),
"sel_comb_%dv", size);
998 for (i = 0; i < nsels; i++) {
1001 if (sy != 1 && sx != 1)
1004 if (!strcmp(selname, combname)) {
1013 return (
char *)ERROR_PTR(
"sel not found", procName, NULL);
1019 static void selaComputeCompositeParameters(
const char *fileout);
1039 selaComputeCompositeParameters(
const char *fileout)
1041 char *str, *nameh1, *nameh2, *namev1, *namev2;
1043 l_int32 size, size1, size2, len;
1045 SELA *selabasic, *selacomb;
1050 for (size = 2; size < 64; size++) {
1061 snprintf(buf,
sizeof(buf),
1062 " { %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\" },",
1063 size, size1, size2, nameh1, nameh2, namev1, namev2);
1111 PROCNAME(
"selaGetSelnames");
1113 if (psize1) *psize1 = 0;
1114 if (psize2) *psize2 = 0;
1115 if (pnameh1) *pnameh1 = NULL;
1116 if (pnameh2) *pnameh2 = NULL;
1117 if (pnamev1) *pnamev1 = NULL;
1118 if (pnamev2) *pnamev2 = NULL;
1119 if (size < 2 || size > 63)
1120 return ERROR_INT(
"valid size range is {2 ... 63}", procName, 1);
1123 *psize1 = comp_parameter_map[index].size1;
1125 *psize2 = comp_parameter_map[index].size2;
1127 *pnameh1 =
stringNew(comp_parameter_map[index].selnameh1);
1129 *pnameh2 =
stringNew(comp_parameter_map[index].selnameh2);
1131 *pnamev1 =
stringNew(comp_parameter_map[index].selnamev1);
1133 *pnamev2 =
stringNew(comp_parameter_map[index].selnamev2);
1152 PROCNAME(
"selaGetSelnames");
1155 return (
SARRAY *)ERROR_PTR(
"sela not defined", procName, NULL);
1157 return (
SARRAY *)ERROR_PTR(
"no sels in sela", procName, NULL);
1160 return (
SARRAY *)ERROR_PTR(
"sa not made", procName, NULL);
1161 for (i = 0; i < n; i++) {
1196 l_int32 sx, sy, cx, cy, i, j;
1197 l_int32 maxxp, maxyp, maxxn, maxyn;
1199 PROCNAME(
"selaFindMaxTranslations");
1201 if (!pxp || !pyp || !pxn || !pyn)
1202 return ERROR_INT(
"&xp (etc) defined", procName, 1);
1203 *pxp = *pyp = *pxn = *pyn = 0;
1205 return ERROR_INT(
"sel not defined", procName, 1);
1208 maxxp = maxyp = maxxn = maxyn = 0;
1209 for (i = 0; i < sy; i++) {
1210 for (j = 0; j < sx; j++) {
1211 if (sel->
data[i][j] == 1) {
1212 maxxp = L_MAX(maxxp, cx - j);
1213 maxyp = L_MAX(maxyp, cy - i);
1214 maxxn = L_MAX(maxxn, j - cx);
1215 maxyn = L_MAX(maxyn, i - cy);
1243 l_int32 i, j, ni, nj, sx, sy, cx, cy, nsx, nsy, ncx, ncy, type;
1246 PROCNAME(
"selRotateOrth");
1249 return (
SEL *)ERROR_PTR(
"sel not defined", procName, NULL);
1250 if (quads < 0 || quads > 4)
1251 return (
SEL *)ERROR_PTR(
"quads not in {0,1,2,3,4}", procName, NULL);
1252 if (quads == 0 || quads == 4)
1261 }
else if (quads == 2) {
1276 for (i = 0; i < sy; i++) {
1277 for (j = 0; j < sx; j++) {
1282 }
else if (quads == 2) {
1312 PROCNAME(
"selaRead");
1315 return (
SELA *)ERROR_PTR(
"fname not defined", procName, NULL);
1318 return (
SELA *)ERROR_PTR(
"stream not opened", procName, NULL);
1321 return (
SELA *)ERROR_PTR(
"sela not returned", procName, NULL);
1338 l_int32 i, n, version;
1342 PROCNAME(
"selaReadStream");
1345 return (
SELA *)ERROR_PTR(
"stream not defined", procName, NULL);
1347 if (fscanf(fp,
"\nSela Version %d\n", &version) != 1)
1348 return (
SELA *)ERROR_PTR(
"not a sela file", procName, NULL);
1349 if (version != SEL_VERSION_NUMBER)
1350 return (
SELA *)ERROR_PTR(
"invalid sel version", procName, NULL);
1351 if (fscanf(fp,
"Number of Sels = %d\n\n", &n) != 1)
1352 return (
SELA *)ERROR_PTR(
"not a sela file", procName, NULL);
1355 return (
SELA *)ERROR_PTR(
"sela not made", procName, NULL);
1358 for (i = 0; i < n; i++) {
1361 return (
SELA *)ERROR_PTR(
"sel not read", procName, NULL);
1382 PROCNAME(
"selRead");
1385 return (
SEL *)ERROR_PTR(
"fname not defined", procName, NULL);
1388 return (
SEL *)ERROR_PTR(
"stream not opened", procName, NULL);
1391 return (
SEL *)ERROR_PTR(
"sela not returned", procName, NULL);
1410 l_int32 sy, sx, cy, cx, i, j, version, ignore;
1413 PROCNAME(
"selReadStream");
1416 return (
SEL *)ERROR_PTR(
"stream not defined", procName, NULL);
1418 if (fscanf(fp,
" Sel Version %d\n", &version) != 1)
1419 return (
SEL *)ERROR_PTR(
"not a sel file", procName, NULL);
1420 if (version != SEL_VERSION_NUMBER)
1421 return (
SEL *)ERROR_PTR(
"invalid sel version", procName, NULL);
1423 if (fgets(linebuf,
sizeof(linebuf), fp) == NULL)
1424 return (
SEL *)ERROR_PTR(
"error reading into linebuf", procName, NULL);
1425 sscanf(linebuf,
" ------ %200s ------", selname);
1427 if (fscanf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n",
1428 &sy, &sx, &cy, &cx) != 4)
1429 return (
SEL *)ERROR_PTR(
"dimensions not read", procName, NULL);
1431 if ((sel =
selCreate(sy, sx, selname)) == NULL)
1432 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
1435 for (i = 0; i < sy; i++) {
1436 ignore = fscanf(fp,
" ");
1437 for (j = 0; j < sx; j++)
1438 ignore = fscanf(fp,
"%1d", &sel->
data[i][j]);
1439 ignore = fscanf(fp,
"\n");
1441 ignore = fscanf(fp,
"\n");
1460 PROCNAME(
"selaWrite");
1463 return ERROR_INT(
"fname not defined", procName, 1);
1465 return ERROR_INT(
"sela not defined", procName, 1);
1468 return ERROR_INT(
"stream not opened", procName, 1);
1490 PROCNAME(
"selaWriteStream");
1493 return ERROR_INT(
"stream not defined", procName, 1);
1495 return ERROR_INT(
"sela not defined", procName, 1);
1498 fprintf(fp,
"\nSela Version %d\n", SEL_VERSION_NUMBER);
1499 fprintf(fp,
"Number of Sels = %d\n\n", n);
1500 for (i = 0; i < n; i++) {
1522 PROCNAME(
"selWrite");
1525 return ERROR_INT(
"fname not defined", procName, 1);
1527 return ERROR_INT(
"sel not defined", procName, 1);
1530 return ERROR_INT(
"stream not opened", procName, 1);
1549 l_int32 sx, sy, cx, cy, i, j;
1551 PROCNAME(
"selWriteStream");
1554 return ERROR_INT(
"stream not defined", procName, 1);
1556 return ERROR_INT(
"sel not defined", procName, 1);
1559 fprintf(fp,
" Sel Version %d\n", SEL_VERSION_NUMBER);
1560 fprintf(fp,
" ------ %s ------\n",
selGetName(sel));
1561 fprintf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n", sy, sx, cy, cx);
1562 for (i = 0; i < sy; i++) {
1564 for (j = 0; j < sx; j++)
1565 fprintf(fp,
"%d", sel->
data[i][j]);
1613 l_int32 y, x, norig;
1616 PROCNAME(
"selCreateFromString");
1618 if (!text || text[0] ==
'\0')
1619 return (
SEL *)ERROR_PTR(
"text undefined or empty", procName, NULL);
1621 return (
SEL *)ERROR_PTR(
"height must be > 0", procName, NULL);
1623 return (
SEL *)ERROR_PTR(
"width must be > 0", procName, NULL);
1624 if (strlen(text) != (
size_t)w * h)
1625 return (
SEL *)ERROR_PTR(
"text size != w * h", procName, NULL);
1629 for (y = 0; y < h; ++y) {
1630 for (x = 0; x < w; ++x) {
1664 return (
SEL *)ERROR_PTR(
"unknown char", procName, NULL);
1669 L_ERROR(
"Exactly one origin must be specified; this string has %d\n",
1703 l_int32 sx, sy, cx, cy, x, y;
1705 PROCNAME(
"selPrintToString");
1708 return (
char *)ERROR_PTR(
"sel not defined", procName, NULL);
1711 if ((str = (
char *)LEPT_CALLOC(1, sy * (sx + 1) + 1)) == NULL)
1712 return (
char *)ERROR_PTR(
"calloc fail for str", procName, NULL);
1715 for (y = 0; y < sy; ++y) {
1716 for (x = 0; x < sx; ++x) {
1718 is_center = (x == cx && y == cy);
1721 *(strptr++) = is_center ?
'X' :
'x';
1724 *(strptr++) = is_center ?
'O' :
'o';
1727 *(strptr++) = is_center ?
'C' :
' ';
1775 char *filestr, *line;
1776 l_int32 i, n, first, last, nsel, insel;
1778 NUMA *nafirst, *nalast;
1783 PROCNAME(
"selaCreateFromFile");
1786 return (
SELA *)ERROR_PTR(
"filename not defined", procName, NULL);
1800 for (i = 0; i < n; i++) {
1803 (line[0] !=
'\0' && line[0] !=
' ' &&
1804 line[0] !=
'\t' && line[0] !=
'\n' && line[0] !=
'#')) {
1810 (line[0] ==
'\0' || line[0] ==
' ' ||
1811 line[0] ==
'\t' || line[0] ==
'\n' || line[0] ==
'#')) {
1822 for (i = 0; i < nsel; i++) {
1826 lept_stderr(
"Error reading sel from %d to %d\n", first, last);
1831 return (
SELA *)ERROR_PTR(
"bad sela file", procName, NULL);
1880 l_int32 n, len, i, w, h, y, x;
1883 PROCNAME(
"selCreateFromSArray");
1886 return (
SEL *)ERROR_PTR(
"sa not defined", procName, NULL);
1888 if (first < 0 || first >= n || last <= first || last >= n)
1889 return (
SEL *)ERROR_PTR(
"invalid range", procName, NULL);
1895 if (line[0] !=
'"' || line[len - 1] !=
'"')
1896 return (
SEL *)ERROR_PTR(
"invalid format", procName, NULL);
1898 if ((sel =
selCreate(h, w, name)) == NULL)
1899 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
1900 for (i = first + 1; i <= last; i++) {
1903 for (x = 0; x < w; ++x) {
1930 return (
SEL *)ERROR_PTR(
"unknown char", procName, NULL);
1961 l_int32 i, n, x, y, w, h;
1965 PROCNAME(
"selCreateFromPta");
1968 return (
SEL *)ERROR_PTR(
"pta not defined", procName, NULL);
1969 if (cy < 0 || cx < 0)
1970 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", procName, NULL);
1973 return (
SEL *)ERROR_PTR(
"no pts in pta", procName, NULL);
1979 return (
SEL *)ERROR_PTR(
"not all x and y >= 0", procName, NULL);
1983 for (i = 0; i < n; i++) {
2014 l_int32 i, j, w, h, d, nhits;
2017 PROCNAME(
"selCreateFromPix");
2020 return (
SEL *)ERROR_PTR(
"pix not defined", procName, NULL);
2021 if (cy < 0 || cx < 0)
2022 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", procName, NULL);
2025 return (
SEL *)ERROR_PTR(
"pix not 1 bpp", procName, NULL);
2026 if (w > MaxPixTemplateSize || h > MaxPixTemplateSize) {
2027 L_ERROR(
"pix template too large (w = %d, h = %d)\n", procName, w, h);
2031 if (nhits > MaxPixTemplateHits) {
2032 L_ERROR(
"too many hits (%d) in pix template\n", procName, nhits);
2038 for (i = 0; i < h; i++) {
2039 for (j = 0; j < w; j++) {
2072 char *basename, *selname;
2074 PROCNAME(
"selReadFromColorImage");
2078 LEPT_FREE(basename);
2080 if ((pix =
pixRead(pathname)) == NULL) {
2082 return (
SEL *)ERROR_PTR(
"pix not returned", procName, NULL);
2085 L_ERROR(
"sel not made\n", procName);
2118 const char *selname)
2122 l_int32 hascolor, num_origins, nohits;
2123 l_int32 w, h, d, i, j, red, green, blue;
2126 PROCNAME(
"selCreateFromColorPix");
2129 return (
SEL *)ERROR_PTR(
"pixs not defined", procName, NULL);
2132 cmap = pixGetColormap(pixs);
2136 if (hascolor == FALSE && d != 32)
2137 return (
SEL *)ERROR_PTR(
"pixs has no color", procName, NULL);
2139 if ((sel =
selCreate (h, w, NULL)) == NULL)
2140 return (
SEL *)ERROR_PTR (
"sel not made", procName, NULL);
2146 for (i = 0; i < h; i++) {
2147 for (j = 0; j < w; j++) {
2158 if (red < 255 && green < 255 && blue < 255) {
2160 if (num_origins == 1)
2162 if (num_origins == 2)
2163 L_WARNING(
"multiple origins in sel image\n", procName);
2165 if (!red && green && !blue) {
2168 }
else if (red && !green && !blue) {
2170 }
else if (red && green && blue) {
2174 return (
SEL *)ERROR_PTR(
"invalid color", procName, NULL);
2181 return (
SEL *)ERROR_PTR(
"no hits in sel", procName, NULL);
2212 PROCNAME(
"selaCreateFromColorPixa");
2215 return (
SELA *)ERROR_PTR(
"pixa not defined", procName, NULL);
2217 return (
SELA *)ERROR_PTR(
"sa of sel names not defined", procName, NULL);
2221 return (
SELA *)ERROR_PTR(
"sela not allocated", procName, NULL);
2222 for (i = 0; i < n; i++) {
2259 l_int32 i, j, w, h, sx, sy, cx, cy, type, width;
2260 l_int32 radius1, radius2, shift1, shift2, x0, y0;
2261 PIX *pixd, *pix2, *pixh, *pixm, *pixorig;
2262 PTA *pta1, *pta2, *pta1t, *pta2t;
2264 PROCNAME(
"selDisplayInPix");
2267 return (
PIX *)ERROR_PTR(
"sel not defined", procName, NULL);
2269 L_WARNING(
"size < 13; setting to 13\n", procName);
2275 L_WARNING(
"grid thickness < 2; setting to 2\n", procName);
2279 w = size * sx + gthick * (sx + 1);
2280 h = size * sy + gthick * (sy + 1);
2284 for (i = 0; i <= sy; i++)
2286 w - 1, gthick / 2 + i * (size + gthick),
2288 for (j = 0; j <= sx; j++)
2290 gthick / 2 + j * (size + gthick), h - 1,
2294 radius1 = (l_int32)(0.85 * ((size - 1) / 2.0) + 0.5);
2295 radius2 = (l_int32)(0.65 * ((size - 1) / 2.0) + 0.5);
2298 shift1 = (size - 1) / 2 - radius1;
2299 shift2 = (size - 1) / 2 - radius2;
2310 size / 2, (l_int32)(0.88 * size),
2313 (l_int32)(0.85 * size), size / 2,
2315 pixRasterop(pixorig, size / 2 - width, size / 2 - width,
2320 if (type == SEL_HIT)
2321 pixXor(pixorig, pixorig, pixh);
2322 else if (type == SEL_MISS)
2323 pixXor(pixorig, pixorig, pixm);
2327 for (i = 0; i < sy; i++) {
2329 for (j = 0; j < sx; j++) {
2331 if (i == cy && j == cx)
2333 else if (type == SEL_HIT)
2335 else if (type == SEL_MISS)
2337 x0 += size + gthick;
2339 y0 += size + gthick;
2379 l_int32 nsels, i, w, width;
2384 PROCNAME(
"selaDisplayInPix");
2387 return (
PIX *)ERROR_PTR(
"sela not defined", procName, NULL);
2389 L_WARNING(
"size < 13; setting to 13\n", procName);
2395 L_WARNING(
"grid thickness < 2; setting to 2\n", procName);
2399 L_WARNING(
"spacing < 5; setting to 5\n", procName);
2406 for (i = 0; i < nsels; i++) {
2416 ncols = L_MIN(nsels, ncols);
2417 for (i = 0; i < ncols; i++) {
2423 width += (ncols + 1) * spacing;
l_ok selSetOrigin(SEL *sel, l_int32 cy, l_int32 cx)
selSetOrigin()
l_ok selectComposableSizes(l_int32 size, l_int32 *pfactor1, l_int32 *pfactor2)
selectComposableSizes()
l_ok selWriteStream(FILE *fp, SEL *sel)
selWriteStream()
SELA * selaCreateFromColorPixa(PIXA *pixa, SARRAY *sa)
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok splitPathAtExtension(const char *pathname, char **pbasename, char **pextension)
splitPathAtExtension()
char * selaGetBrickName(SELA *sela, l_int32 hsize, l_int32 vsize)
selaGetBrickName()
PIX * pixGenerateFromPta(PTA *pta, l_int32 w, l_int32 h)
pixGenerateFromPta()
SEL * selCopy(SEL *sel)
selCopy()
SEL * selCreateFromColorPix(PIX *pixs, const char *selname)
char * selaGetCombName(SELA *sela, l_int32 size, l_int32 direction)
selaGetCombName()
l_ok selSetName(SEL *sel, const char *name)
selSetName()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
l_ok selaWrite(const char *fname, SELA *sela)
selaWrite()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
SEL * selRead(const char *fname)
selRead()
char * stringNew(const char *src)
stringNew()
static const l_int32 InitialPtrArraySize
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()
SEL * selReadStream(FILE *fp)
selReadStream()
void lept_stderr(const char *fmt,...)
lept_stderr()
l_int32 selaGetCount(SELA *sela)
selaGetCount()
l_ok selGetParameters(SEL *sel, l_int32 *psy, l_int32 *psx, l_int32 *pcy, l_int32 *pcx)
selGetParameters()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
l_ok selaWriteStream(FILE *fp, SELA *sela)
selaWriteStream()
SELA * selaCreateFromFile(const char *filename)
selaCreateFromFile()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 ptaGetCount(PTA *pta)
ptaGetCount()
l_ok selFindMaxTranslations(SEL *sel, l_int32 *pxp, l_int32 *pyp, l_int32 *pxn, l_int32 *pyn)
selFindMaxTranslations()
SARRAY * selaGetSelnames(SELA *sela)
selaGetSelnames()
void selaDestroy(SELA **psela)
selaDestroy()
SEL * selCreateFromPta(PTA *pta, l_int32 cy, l_int32 cx, const char *name)
selCreateFromPta()
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
l_ok selGetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 *ptype)
selGetElement()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIX * selDisplayInPix(SEL *sel, l_int32 size, l_int32 gthick)
selDisplayInPix()
l_int32 ** create2dIntArray(l_int32 sy, l_int32 sx)
create2dIntArray()
char * selPrintToString(SEL *sel)
selPrintToString()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
SELA * selaAddDwaCombs(SELA *sela)
selaAddDwaCombs()
void selDestroy(SEL **psel)
selDestroy()
l_ok selaFindSelByName(SELA *sela, const char *name, l_int32 *pindex, SEL **psel)
selaFindSelByName()
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 pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
SEL * selCreateComb(l_int32 factor1, l_int32 factor2, l_int32 direction)
selCreateComb()
SEL * selCreate(l_int32 height, l_int32 width, const char *name)
selCreate()
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
selCreateBrick()
#define GET_DATA_BYTE(pdata, n)
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
PIX * pixSubtract(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixSubtract()
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
void pixDestroy(PIX **ppix)
pixDestroy()
static l_int32 selaExtendArray(SELA *sela)
selaExtendArray()
l_ok selWrite(const char *fname, SEL *sel)
selWrite()
SELA * selaRead(const char *fname)
selaRead()
l_ok pixcmapHasColor(PIXCMAP *cmap, l_int32 *pcolor)
pixcmapHasColor()
BOX * ptaGetBoundingRegion(PTA *pta)
ptaGetBoundingRegion()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok pixRenderLine(PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width, l_int32 op)
pixRenderLine()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
PIX * pixRead(const char *filename)
pixRead()
l_ok getCompositeParameters(l_int32 size, l_int32 *psize1, l_int32 *psize2, char **pnameh1, char **pnameh2, char **pnamev1, char **pnamev2)
getCompositeParameters()
char * selGetName(SEL *sel)
selGetName()
SELA * selaCreate(l_int32 n)
selaCreate()
l_ok selaAddSel(SELA *sela, SEL *sel, const char *selname, l_int32 copyflag)
selaAddSel()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
SELA * selaAddBasic(SELA *sela)
selaAddBasic()
void ptaDestroy(PTA **ppta)
ptaDestroy()
void boxDestroy(BOX **pbox)
boxDestroy()
SEL * selRotateOrth(SEL *sel, l_int32 quads)
selRotateOrth()
PTA * ptaTransform(PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
ptaTransform()
l_ok selGetTypeAtOrigin(SEL *sel, l_int32 *ptype)
selGetTypeAtOrigin()
l_ok ptaGetIPt(PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
ptaGetIPt()
SEL * selaGetSel(SELA *sela, l_int32 i)
selaGetSel()
PTA * generatePtaFilledCircle(l_int32 radius)
generatePtaFilledCircle()
SEL * selCreateFromPix(PIX *pix, l_int32 cy, l_int32 cx, const char *name)
selCreateFromPix()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void pixaDestroy(PIXA **ppixa)
pixaDestroy()
static SEL * selCreateFromSArray(SARRAY *sa, l_int32 first, l_int32 last)
selCreateFromSArray()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
SELA * selaReadStream(FILE *fp)
selaReadStream()
PIX * selaDisplayInPix(SELA *sela, l_int32 size, l_int32 gthick, l_int32 spacing, l_int32 ncols)
selaDisplayInPix()
l_ok selSetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 type)
selSetElement()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SEL * selCreateFromString(const char *text, l_int32 h, l_int32 w, const char *name)
selCreateFromString()
SEL * selReadFromColorImage(const char *pathname)