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 if (n <= 0 || n > MaxPtrArraySize)
259 sela = (
SELA *)LEPT_CALLOC(1,
sizeof(
SELA));
262 sela->
sel = (
SEL **)LEPT_CALLOC(n,
sizeof(
SEL *));
280 if ((sela = *psela) == NULL)
283 for (i = 0; i < sela->
n; i++)
285 LEPT_FREE(sela->
sel);
314 sel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL));
320 LEPT_FREE(sel->
name);
322 return (
SEL *)ERROR_PTR(
"data not allocated", __func__, NULL);
342 L_WARNING(
"ptr address is NULL!\n", __func__);
345 if ((sel = *psel) == NULL)
348 for (i = 0; i < sel->
sy; i++)
349 LEPT_FREE(sel->
data[i]);
350 LEPT_FREE(sel->
data);
352 LEPT_FREE(sel->
name);
367 l_int32 sx, sy, cx, cy, i, j;
371 return (
SEL *)ERROR_PTR(
"sel not defined", __func__, NULL);
373 csel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL));
382 return (
SEL *)ERROR_PTR(
"sel data not made", __func__, NULL);
385 for (i = 0; i < sy; i++)
386 for (j = 0; j < sx; j++)
419 if (h <= 0 || w <= 0)
420 return (
SEL *)ERROR_PTR(
"h and w must both be > 0", __func__, NULL);
421 if (type != SEL_HIT && type != SEL_MISS && type != SEL_DONT_CARE)
422 return (
SEL *)ERROR_PTR(
"invalid sel element type", __func__, NULL);
424 if ((sel =
selCreate(h, w, NULL)) == NULL)
425 return (
SEL *)ERROR_PTR(
"sel not made", __func__, NULL);
427 for (i = 0; i < h; i++)
428 for (j = 0; j < w; j++)
429 sel->
data[i][j] = type;
459 if (factor1 < 1 || factor2 < 1)
460 return (
SEL *)ERROR_PTR(
"factors must be >= 1", __func__, NULL);
461 if (direction != L_HORIZ && direction != L_VERT)
462 return (
SEL *)ERROR_PTR(
"invalid direction", __func__, NULL);
464 size = factor1 * factor2;
465 if (direction == L_HORIZ) {
466 if ((sel =
selCreate(1, size, NULL)) == NULL)
467 return (
SEL *)ERROR_PTR(
"horiz sel not made", __func__, NULL);
470 if ((sel =
selCreate(size, 1, NULL)) == NULL)
471 return (
SEL *)ERROR_PTR(
"vert sel not made", __func__, NULL);
476 for (i = 0; i < factor2; i++) {
477 z = factor1 / 2 + i * factor1;
480 if (direction == L_HORIZ)
511 if (sx <= 0 || sx > MaxKernelSize)
512 return (l_int32 **)ERROR_PTR(
"sx out of bounds", __func__, NULL);
513 if (sy <= 0 || sy > MaxKernelSize)
514 return (l_int32 **)ERROR_PTR(
"sy out of bounds", __func__, NULL);
516 array = (l_int32 **)LEPT_CALLOC(sy,
sizeof(l_int32 *));
517 for (i = 0; i < sy; i++)
518 array[i] = (l_int32 *)LEPT_CALLOC(sx,
sizeof(l_int32));
554 return ERROR_INT(
"sela not defined", __func__, 1);
556 return ERROR_INT(
"sel not defined", __func__, 1);
557 if (!sel->
name && !selname)
558 return ERROR_INT(
"added sel must have name", __func__, 1);
560 return ERROR_INT(
"invalid copyflag", __func__, 1);
563 if ((csel =
selCopy(sel)) == NULL)
564 return ERROR_INT(
"csel not made", __func__, 1);
576 return ERROR_INT(
"extension failed", __func__, 1);
596 return ERROR_INT(
"sela not defined", __func__, 1);
599 sizeof(
SEL *) * sela->
nalloc,
600 2 *
sizeof(
SEL *) * sela->
nalloc)) == NULL)
601 return ERROR_INT(
"new ptr array not returned", __func__, 1);
622 return ERROR_INT(
"sela not defined", __func__, 0);
646 return (
SEL *)ERROR_PTR(
"sela not defined", __func__, NULL);
648 if (i < 0 || i >= sela->
n)
649 return (
SEL *)ERROR_PTR(
"invalid index", __func__, NULL);
664 return (
char *)ERROR_PTR(
"sel not defined", __func__, NULL);
688 return ERROR_INT(
"sel not defined", __func__, 1);
713 if (pindex) *pindex = -1;
714 if (psel) *psel = NULL;
717 return ERROR_INT(
"sela not defined", __func__, 1);
720 for (i = 0; i < n; i++)
723 L_WARNING(
"missing sel\n", __func__);
728 if (sname && (!strcmp(name, sname))) {
757 return ERROR_INT(
"&type not defined", __func__, 1);
758 *ptype = SEL_DONT_CARE;
760 return ERROR_INT(
"sel not defined", __func__, 1);
761 if (row < 0 || row >= sel->
sy)
762 return ERROR_INT(
"sel row out of bounds", __func__, 1);
763 if (col < 0 || col >= sel->
sx)
764 return ERROR_INT(
"sel col out of bounds", __func__, 1);
766 *ptype = sel->
data[row][col];
795 return ERROR_INT(
"sel not defined", __func__, 1);
796 if (type != SEL_HIT && type != SEL_MISS && type != SEL_DONT_CARE)
797 return ERROR_INT(
"invalid sel element type", __func__, 1);
798 if (row < 0 || row >= sel->
sy)
799 return ERROR_INT(
"sel row out of bounds", __func__, 1);
800 if (col < 0 || col >= sel->
sx)
801 return ERROR_INT(
"sel col out of bounds", __func__, 1);
803 sel->
data[row][col] = type;
827 return ERROR_INT(
"sel not defined", __func__, 1);
828 if (psy) *psy = sel->
sy;
829 if (psx) *psx = sel->
sx;
830 if (pcy) *pcy = sel->
cy;
831 if (pcx) *pcx = sel->
cx;
849 return ERROR_INT(
"sel not defined", __func__, 1);
867 l_int32 sx, sy, cx, cy, i, j;
870 return ERROR_INT(
"&type not defined", __func__, 1);
871 *ptype = SEL_DONT_CARE;
873 return ERROR_INT(
"sel not defined", __func__, 1);
876 for (i = 0; i < sy; i++) {
877 for (j = 0; j < sx; j++) {
878 if (i == cy && j == cx) {
885 return ERROR_INT(
"sel origin not found", __func__, 1);
901 l_int32 i, nsels, sx, sy;
905 return (
char *)ERROR_PTR(
"sela not defined", __func__, NULL);
908 for (i = 0; i < nsels; i++) {
911 if (hsize == sx && vsize == sy)
915 return (
char *)ERROR_PTR(
"sel not found", __func__, NULL);
940 l_int32 i, nsels, sx, sy, found;
944 return (
char *)ERROR_PTR(
"sela not defined", __func__, NULL);
945 if (direction != L_HORIZ && direction != L_VERT)
946 return (
char *)ERROR_PTR(
"invalid direction", __func__, NULL);
949 if (direction == L_HORIZ)
950 snprintf(combname,
sizeof(combname),
"sel_comb_%dh", size);
952 snprintf(combname,
sizeof(combname),
"sel_comb_%dv", size);
956 for (i = 0; i < nsels; i++) {
959 if (sy != 1 && sx != 1)
962 if (!strcmp(selname, combname)) {
971 return (
char *)ERROR_PTR(
"sel not found", __func__, NULL);
977 static void selaComputeCompositeParameters(
const char *fileout);
997 selaComputeCompositeParameters(
const char *fileout)
999 char *str, *nameh1, *nameh2, *namev1, *namev2;
1001 l_int32 size, size1, size2, len;
1003 SELA *selabasic, *selacomb;
1008 for (size = 2; size < 64; size++) {
1019 snprintf(buf,
sizeof(buf),
1020 " { %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\" },",
1021 size, size1, size2, nameh1, nameh2, namev1, namev2);
1069 if (psize1) *psize1 = 0;
1070 if (psize2) *psize2 = 0;
1071 if (pnameh1) *pnameh1 = NULL;
1072 if (pnameh2) *pnameh2 = NULL;
1073 if (pnamev1) *pnamev1 = NULL;
1074 if (pnamev2) *pnamev2 = NULL;
1075 if (size < 2 || size > 63)
1076 return ERROR_INT(
"valid size range is {2 ... 63}", __func__, 1);
1079 *psize1 = comp_parameter_map[index].size1;
1081 *psize2 = comp_parameter_map[index].size2;
1083 *pnameh1 =
stringNew(comp_parameter_map[index].selnameh1);
1085 *pnameh2 =
stringNew(comp_parameter_map[index].selnameh2);
1087 *pnamev1 =
stringNew(comp_parameter_map[index].selnamev1);
1089 *pnamev2 =
stringNew(comp_parameter_map[index].selnamev2);
1109 return (
SARRAY *)ERROR_PTR(
"sela not defined", __func__, NULL);
1111 return (
SARRAY *)ERROR_PTR(
"no sels in sela", __func__, NULL);
1114 return (
SARRAY *)ERROR_PTR(
"sa not made", __func__, NULL);
1115 for (i = 0; i < n; i++) {
1150 l_int32 sx, sy, cx, cy, i, j;
1151 l_int32 maxxp, maxyp, maxxn, maxyn;
1153 if (!pxp || !pyp || !pxn || !pyn)
1154 return ERROR_INT(
"&xp (etc) defined", __func__, 1);
1155 *pxp = *pyp = *pxn = *pyn = 0;
1157 return ERROR_INT(
"sel not defined", __func__, 1);
1160 maxxp = maxyp = maxxn = maxyn = 0;
1161 for (i = 0; i < sy; i++) {
1162 for (j = 0; j < sx; j++) {
1163 if (sel->
data[i][j] == 1) {
1164 maxxp = L_MAX(maxxp, cx - j);
1165 maxyp = L_MAX(maxyp, cy - i);
1166 maxxn = L_MAX(maxxn, j - cx);
1167 maxyn = L_MAX(maxyn, i - cy);
1195 l_int32 i, j, ni, nj, sx, sy, cx, cy, nsx, nsy, ncx, ncy, type;
1199 return (
SEL *)ERROR_PTR(
"sel not defined", __func__, NULL);
1200 if (quads < 0 || quads > 4)
1201 return (
SEL *)ERROR_PTR(
"quads not in {0,1,2,3,4}", __func__, NULL);
1202 if (quads == 0 || quads == 4)
1211 }
else if (quads == 2) {
1226 for (i = 0; i < sy; i++) {
1227 for (j = 0; j < sx; j++) {
1232 }
else if (quads == 2) {
1263 return (
SELA *)ERROR_PTR(
"fname not defined", __func__, NULL);
1266 return (
SELA *)ERROR_PTR(
"stream not opened", __func__, NULL);
1269 return (
SELA *)ERROR_PTR(
"sela not returned", __func__, NULL);
1286 l_int32 i, n, version;
1291 return (
SELA *)ERROR_PTR(
"stream not defined", __func__, NULL);
1293 if (fscanf(fp,
"\nSela Version %d\n", &version) != 1)
1294 return (
SELA *)ERROR_PTR(
"not a sela file", __func__, NULL);
1295 if (version != SEL_VERSION_NUMBER)
1296 return (
SELA *)ERROR_PTR(
"invalid sel version", __func__, NULL);
1297 if (fscanf(fp,
"Number of Sels = %d\n\n", &n) != 1)
1298 return (
SELA *)ERROR_PTR(
"not a sela file", __func__, NULL);
1301 return (
SELA *)ERROR_PTR(
"sela not made", __func__, NULL);
1304 for (i = 0; i < n; i++) {
1307 return (
SELA *)ERROR_PTR(
"sel not read", __func__, NULL);
1329 return (
SEL *)ERROR_PTR(
"fname not defined", __func__, NULL);
1332 return (
SEL *)ERROR_PTR(
"stream not opened", __func__, NULL);
1335 return (
SEL *)ERROR_PTR(
"sela not returned", __func__, NULL);
1354 l_int32 sy, sx, cy, cx, i, j, version, ignore;
1358 return (
SEL *)ERROR_PTR(
"stream not defined", __func__, NULL);
1360 if (fscanf(fp,
" Sel Version %d\n", &version) != 1)
1361 return (
SEL *)ERROR_PTR(
"not a sel file", __func__, NULL);
1362 if (version != SEL_VERSION_NUMBER)
1363 return (
SEL *)ERROR_PTR(
"invalid sel version", __func__, NULL);
1365 if (fgets(linebuf,
sizeof(linebuf), fp) == NULL)
1366 return (
SEL *)ERROR_PTR(
"error reading into linebuf", __func__, NULL);
1367 sscanf(linebuf,
" ------ %200s ------", selname);
1369 if (fscanf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n",
1370 &sy, &sx, &cy, &cx) != 4)
1371 return (
SEL *)ERROR_PTR(
"dimensions not read", __func__, NULL);
1373 if ((sel =
selCreate(sy, sx, selname)) == NULL)
1374 return (
SEL *)ERROR_PTR(
"sel not made", __func__, NULL);
1377 for (i = 0; i < sy; i++) {
1378 ignore = fscanf(fp,
" ");
1379 for (j = 0; j < sx; j++)
1380 ignore = fscanf(fp,
"%1d", &sel->
data[i][j]);
1381 ignore = fscanf(fp,
"\n");
1383 ignore = fscanf(fp,
"\n");
1403 return ERROR_INT(
"fname not defined", __func__, 1);
1405 return ERROR_INT(
"sela not defined", __func__, 1);
1408 return ERROR_INT(
"stream not opened", __func__, 1);
1431 return ERROR_INT(
"stream not defined", __func__, 1);
1433 return ERROR_INT(
"sela not defined", __func__, 1);
1436 fprintf(fp,
"\nSela Version %d\n", SEL_VERSION_NUMBER);
1437 fprintf(fp,
"Number of Sels = %d\n\n", n);
1438 for (i = 0; i < n; i++) {
1461 return ERROR_INT(
"fname not defined", __func__, 1);
1463 return ERROR_INT(
"sel not defined", __func__, 1);
1466 return ERROR_INT(
"stream not opened", __func__, 1);
1485 l_int32 sx, sy, cx, cy, i, j;
1488 return ERROR_INT(
"stream not defined", __func__, 1);
1490 return ERROR_INT(
"sel not defined", __func__, 1);
1493 fprintf(fp,
" Sel Version %d\n", SEL_VERSION_NUMBER);
1494 fprintf(fp,
" ------ %s ------\n",
selGetName(sel));
1495 fprintf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n", sy, sx, cy, cx);
1496 for (i = 0; i < sy; i++) {
1498 for (j = 0; j < sx; j++)
1499 fprintf(fp,
"%d", sel->
data[i][j]);
1547 l_int32 y, x, norig;
1550 if (!text || text[0] ==
'\0')
1551 return (
SEL *)ERROR_PTR(
"text undefined or empty", __func__, NULL);
1553 return (
SEL *)ERROR_PTR(
"height must be > 0", __func__, NULL);
1555 return (
SEL *)ERROR_PTR(
"width must be > 0", __func__, NULL);
1556 if (strlen(text) != (
size_t)w * h)
1557 return (
SEL *)ERROR_PTR(
"text size != w * h", __func__, NULL);
1561 for (y = 0; y < h; ++y) {
1562 for (x = 0; x < w; ++x) {
1596 return (
SEL *)ERROR_PTR(
"unknown char", __func__, NULL);
1601 L_ERROR(
"Exactly one origin must be specified; this string has %d\n",
1635 l_int32 sx, sy, cx, cy, x, y;
1638 return (
char *)ERROR_PTR(
"sel not defined", __func__, NULL);
1641 if ((str = (
char *)LEPT_CALLOC(1, sy * (sx + 1) + 1)) == NULL)
1642 return (
char *)ERROR_PTR(
"calloc fail for str", __func__, NULL);
1645 for (y = 0; y < sy; ++y) {
1646 for (x = 0; x < sx; ++x) {
1648 is_center = (x == cx && y == cy);
1651 *(strptr++) = is_center ?
'X' :
'x';
1654 *(strptr++) = is_center ?
'O' :
'o';
1657 *(strptr++) = is_center ?
'C' :
' ';
1705 char *filestr, *line;
1706 l_int32 i, n, first, last, nsel, insel;
1708 NUMA *nafirst, *nalast;
1714 return (
SELA *)ERROR_PTR(
"filename not defined", __func__, NULL);
1728 for (i = 0; i < n; i++) {
1731 (line[0] !=
'\0' && line[0] !=
' ' &&
1732 line[0] !=
'\t' && line[0] !=
'\n' && line[0] !=
'#')) {
1738 (line[0] ==
'\0' || line[0] ==
' ' ||
1739 line[0] ==
'\t' || line[0] ==
'\n' || line[0] ==
'#')) {
1750 for (i = 0; i < nsel; i++) {
1754 lept_stderr(
"Error reading sel from %d to %d\n", first, last);
1759 return (
SELA *)ERROR_PTR(
"bad sela file", __func__, NULL);
1808 l_int32 n, len, i, w, h, y, x;
1812 return (
SEL *)ERROR_PTR(
"sa not defined", __func__, NULL);
1814 if (first < 0 || first >= n || last <= first || last >= n)
1815 return (
SEL *)ERROR_PTR(
"invalid range", __func__, NULL);
1821 if (line[0] !=
'"' || line[len - 1] !=
'"')
1822 return (
SEL *)ERROR_PTR(
"invalid format", __func__, NULL);
1824 if ((sel =
selCreate(h, w, name)) == NULL)
1825 return (
SEL *)ERROR_PTR(
"sel not made", __func__, NULL);
1826 for (i = first + 1; i <= last; i++) {
1829 for (x = 0; x < w; ++x) {
1856 return (
SEL *)ERROR_PTR(
"unknown char", __func__, NULL);
1887 l_int32 i, n, x, y, w, h;
1892 return (
SEL *)ERROR_PTR(
"pta not defined", __func__, NULL);
1893 if (cy < 0 || cx < 0)
1894 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", __func__, NULL);
1897 return (
SEL *)ERROR_PTR(
"no pts in pta", __func__, NULL);
1903 return (
SEL *)ERROR_PTR(
"not all x and y >= 0", __func__, NULL);
1907 for (i = 0; i < n; i++) {
1938 l_int32 i, j, w, h, d, nhits;
1942 return (
SEL *)ERROR_PTR(
"pix not defined", __func__, NULL);
1943 if (cy < 0 || cx < 0)
1944 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", __func__, NULL);
1947 return (
SEL *)ERROR_PTR(
"pix not 1 bpp", __func__, NULL);
1948 if (w > MaxPixTemplateSize || h > MaxPixTemplateSize) {
1949 L_ERROR(
"pix template too large (w = %d, h = %d)\n", __func__, w, h);
1953 if (nhits > MaxPixTemplateHits) {
1954 L_ERROR(
"too many hits (%d) in pix template\n", __func__, nhits);
1960 for (i = 0; i < h; i++) {
1961 for (j = 0; j < w; j++) {
1994 char *basename, *selname;
1998 LEPT_FREE(basename);
2000 if ((pix =
pixRead(pathname)) == NULL) {
2002 return (
SEL *)ERROR_PTR(
"pix not returned", __func__, NULL);
2005 L_ERROR(
"sel not made\n", __func__);
2038 const char *selname)
2042 l_int32 hascolor, num_origins, nohits;
2043 l_int32 w, h, d, i, j, red, green, blue;
2047 return (
SEL *)ERROR_PTR(
"pixs not defined", __func__, NULL);
2050 cmap = pixGetColormap(pixs);
2054 if (hascolor == FALSE && d != 32)
2055 return (
SEL *)ERROR_PTR(
"pixs has no color", __func__, NULL);
2057 if ((sel =
selCreate (h, w, NULL)) == NULL)
2058 return (
SEL *)ERROR_PTR (
"sel not made", __func__, NULL);
2064 for (i = 0; i < h; i++) {
2065 for (j = 0; j < w; j++) {
2076 if (red < 255 && green < 255 && blue < 255) {
2078 if (num_origins == 1)
2080 if (num_origins == 2)
2081 L_WARNING(
"multiple origins in sel image\n", __func__);
2083 if (!red && green && !blue) {
2086 }
else if (red && !green && !blue) {
2088 }
else if (red && green && blue) {
2092 return (
SEL *)ERROR_PTR(
"invalid color", __func__, NULL);
2099 return (
SEL *)ERROR_PTR(
"no hits in sel", __func__, NULL);
2131 return (
SELA *)ERROR_PTR(
"pixa not defined", __func__, NULL);
2133 return (
SELA *)ERROR_PTR(
"sa of sel names not defined", __func__, NULL);
2137 return (
SELA *)ERROR_PTR(
"sela not allocated", __func__, NULL);
2138 for (i = 0; i < n; i++) {
2175 l_int32 i, j, w, h, sx, sy, cx, cy, type, width;
2176 l_int32 radius1, radius2, shift1, shift2, x0, y0;
2177 PIX *pixd, *pix2, *pixh, *pixm, *pixorig;
2178 PTA *pta1, *pta2, *pta1t, *pta2t;
2181 return (
PIX *)ERROR_PTR(
"sel not defined", __func__, NULL);
2183 L_WARNING(
"size < 13; setting to 13\n", __func__);
2189 L_WARNING(
"grid thickness < 2; setting to 2\n", __func__);
2193 w = size * sx + gthick * (sx + 1);
2194 h = size * sy + gthick * (sy + 1);
2198 for (i = 0; i <= sy; i++)
2200 w - 1, gthick / 2 + i * (size + gthick),
2202 for (j = 0; j <= sx; j++)
2204 gthick / 2 + j * (size + gthick), h - 1,
2208 radius1 = (l_int32)(0.85 * ((size - 1) / 2.0) + 0.5);
2209 radius2 = (l_int32)(0.65 * ((size - 1) / 2.0) + 0.5);
2212 shift1 = (size - 1) / 2 - radius1;
2213 shift2 = (size - 1) / 2 - radius2;
2224 size / 2, (l_int32)(0.88 * size),
2227 (l_int32)(0.85 * size), size / 2,
2229 pixRasterop(pixorig, size / 2 - width, size / 2 - width,
2234 if (type == SEL_HIT)
2235 pixXor(pixorig, pixorig, pixh);
2236 else if (type == SEL_MISS)
2237 pixXor(pixorig, pixorig, pixm);
2241 for (i = 0; i < sy; i++) {
2243 for (j = 0; j < sx; j++) {
2245 if (i == cy && j == cx)
2247 else if (type == SEL_HIT)
2249 else if (type == SEL_MISS)
2251 x0 += size + gthick;
2253 y0 += size + gthick;
2293 l_int32 nsels, i, w, width;
2299 return (
PIX *)ERROR_PTR(
"sela not defined", __func__, NULL);
2301 L_WARNING(
"size < 13; setting to 13\n", __func__);
2307 L_WARNING(
"grid thickness < 2; setting to 2\n", __func__);
2311 L_WARNING(
"spacing < 5; setting to 5\n", __func__);
2318 for (i = 0; i < nsels; i++) {
2328 ncols = L_MIN(nsels, ncols);
2329 for (i = 0; i < ncols; i++) {
2335 width += (ncols + 1) * spacing;
#define GET_DATA_BYTE(pdata, n)
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
void boxDestroy(BOX **pbox)
boxDestroy()
l_ok pixcmapHasColor(PIXCMAP *cmap, l_int32 *pcolor)
pixcmapHasColor()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixRenderLine(PIX *pix, l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2, l_int32 width, l_int32 op)
pixRenderLine()
PTA * generatePtaFilledCircle(l_int32 radius)
generatePtaFilledCircle()
l_ok selectComposableSizes(l_int32 size, l_int32 *pfactor1, l_int32 *pfactor2)
selectComposableSizes()
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()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
l_ok pixGetPixel(PIX *pix, l_int32 x, l_int32 y, l_uint32 *pval)
pixGetPixel()
l_ok pixCountPixels(PIX *pixs, l_int32 *pcount, l_int32 *tab8)
pixCountPixels()
PIX * pixXor(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixXor()
PIX * pixSubtract(PIX *pixd, PIX *pixs1, PIX *pixs2)
pixSubtract()
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_int32 ptaGetCount(PTA *pta)
ptaGetCount()
void ptaDestroy(PTA **ppta)
ptaDestroy()
BOX * ptaGetBoundingRegion(PTA *pta)
ptaGetBoundingRegion()
PIX * pixGenerateFromPta(PTA *pta, l_int32 w, l_int32 h)
pixGenerateFromPta()
PTA * ptaTransform(PTA *ptas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
ptaTransform()
PIX * pixRead(const char *filename)
pixRead()
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()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
static SEL * selCreateFromSArray(SARRAY *sa, l_int32 first, l_int32 last)
selCreateFromSArray()
SEL * selCreateFromPta(PTA *pta, l_int32 cy, l_int32 cx, const char *name)
selCreateFromPta()
l_ok selWrite(const char *fname, SEL *sel)
selWrite()
PIX * selDisplayInPix(SEL *sel, l_int32 size, l_int32 gthick)
selDisplayInPix()
l_ok selWriteStream(FILE *fp, SEL *sel)
selWriteStream()
static const l_int32 InitialPtrArraySize
SARRAY * selaGetSelnames(SELA *sela)
selaGetSelnames()
SEL * selRead(const char *fname)
selRead()
l_ok selGetParameters(SEL *sel, l_int32 *psy, l_int32 *psx, l_int32 *pcy, l_int32 *pcx)
selGetParameters()
SEL * selCreateFromPix(PIX *pix, l_int32 cy, l_int32 cx, const char *name)
selCreateFromPix()
l_ok getCompositeParameters(l_int32 size, l_int32 *psize1, l_int32 *psize2, char **pnameh1, char **pnameh2, char **pnamev1, char **pnamev2)
getCompositeParameters()
l_ok selFindMaxTranslations(SEL *sel, l_int32 *pxp, l_int32 *pyp, l_int32 *pxn, l_int32 *pyn)
selFindMaxTranslations()
SEL * selReadFromColorImage(const char *pathname)
l_ok selSetName(SEL *sel, const char *name)
selSetName()
l_ok selaWriteStream(FILE *fp, SELA *sela)
selaWriteStream()
SEL * selCreateFromString(const char *text, l_int32 h, l_int32 w, const char *name)
selCreateFromString()
void selaDestroy(SELA **psela)
selaDestroy()
l_ok selaFindSelByName(SELA *sela, const char *name, l_int32 *pindex, SEL **psel)
selaFindSelByName()
SEL * selCopy(SEL *sel)
selCopy()
SEL * selCreateComb(l_int32 factor1, l_int32 factor2, l_int32 direction)
selCreateComb()
l_ok selSetOrigin(SEL *sel, l_int32 cy, l_int32 cx)
selSetOrigin()
SELA * selaCreate(l_int32 n)
selaCreate()
SEL * selRotateOrth(SEL *sel, l_int32 quads)
selRotateOrth()
void selDestroy(SEL **psel)
selDestroy()
l_int32 ** create2dIntArray(l_int32 sy, l_int32 sx)
create2dIntArray()
SEL * selReadStream(FILE *fp)
selReadStream()
l_ok selaAddSel(SELA *sela, SEL *sel, const char *selname, l_int32 copyflag)
selaAddSel()
l_ok selSetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 type)
selSetElement()
char * selGetName(SEL *sel)
selGetName()
SELA * selaCreateFromColorPixa(PIXA *pixa, SARRAY *sa)
l_ok selaWrite(const char *fname, SELA *sela)
selaWrite()
SEL * selaGetSel(SELA *sela, l_int32 i)
selaGetSel()
char * selaGetCombName(SELA *sela, l_int32 size, l_int32 direction)
selaGetCombName()
PIX * selaDisplayInPix(SELA *sela, l_int32 size, l_int32 gthick, l_int32 spacing, l_int32 ncols)
selaDisplayInPix()
SEL * selCreate(l_int32 height, l_int32 width, const char *name)
selCreate()
static l_int32 selaExtendArray(SELA *sela)
selaExtendArray()
l_ok selGetElement(SEL *sel, l_int32 row, l_int32 col, l_int32 *ptype)
selGetElement()
l_int32 selaGetCount(SELA *sela)
selaGetCount()
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
selCreateBrick()
SELA * selaReadStream(FILE *fp)
selaReadStream()
SELA * selaCreateFromFile(const char *filename)
selaCreateFromFile()
char * selaGetBrickName(SELA *sela, l_int32 hsize, l_int32 vsize)
selaGetBrickName()
SELA * selaRead(const char *fname)
selaRead()
l_ok selGetTypeAtOrigin(SEL *sel, l_int32 *ptype)
selGetTypeAtOrigin()
char * selPrintToString(SEL *sel)
selPrintToString()
SEL * selCreateFromColorPix(PIX *pixs, const char *selname)
SELA * selaAddBasic(SELA *sela)
selaAddBasic()
SELA * selaAddDwaCombs(SELA *sela)
selaAddDwaCombs()
void lept_stderr(const char *fmt,...)
lept_stderr()
char * stringNew(const char *src)
stringNew()
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
l_ok splitPathAtExtension(const char *pathname, char **pbasename, char **pextension)
splitPathAtExtension()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()