142 #include "allheaders.h" 144 static const l_int32 L_BUFSIZE = 256;
145 static const l_int32 INITIAL_PTR_ARRAYSIZE = 50;
146 static const l_int32 MANY_SELS = 1000;
164 { { 2, 2, 1,
"sel_2h",
"",
"sel_2v",
"" },
165 { 3, 3, 1,
"sel_3h",
"",
"sel_3v",
"" },
166 { 4, 2, 2,
"sel_2h",
"sel_comb_4h",
"sel_2v",
"sel_comb_4v" },
167 { 5, 5, 1,
"sel_5h",
"",
"sel_5v",
"" },
168 { 6, 3, 2,
"sel_3h",
"sel_comb_6h",
"sel_3v",
"sel_comb_6v" },
169 { 7, 7, 1,
"sel_7h",
"",
"sel_7v",
"" },
170 { 8, 4, 2,
"sel_4h",
"sel_comb_8h",
"sel_4v",
"sel_comb_8v" },
171 { 9, 3, 3,
"sel_3h",
"sel_comb_9h",
"sel_3v",
"sel_comb_9v" },
172 { 10, 5, 2,
"sel_5h",
"sel_comb_10h",
"sel_5v",
"sel_comb_10v" },
173 { 11, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
174 { 12, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
175 { 13, 4, 3,
"sel_4h",
"sel_comb_12h",
"sel_4v",
"sel_comb_12v" },
176 { 14, 7, 2,
"sel_7h",
"sel_comb_14h",
"sel_7v",
"sel_comb_14v" },
177 { 15, 5, 3,
"sel_5h",
"sel_comb_15h",
"sel_5v",
"sel_comb_15v" },
178 { 16, 4, 4,
"sel_4h",
"sel_comb_16h",
"sel_4v",
"sel_comb_16v" },
179 { 17, 4, 4,
"sel_4h",
"sel_comb_16h",
"sel_4v",
"sel_comb_16v" },
180 { 18, 6, 3,
"sel_6h",
"sel_comb_18h",
"sel_6v",
"sel_comb_18v" },
181 { 19, 5, 4,
"sel_5h",
"sel_comb_20h",
"sel_5v",
"sel_comb_20v" },
182 { 20, 5, 4,
"sel_5h",
"sel_comb_20h",
"sel_5v",
"sel_comb_20v" },
183 { 21, 7, 3,
"sel_7h",
"sel_comb_21h",
"sel_7v",
"sel_comb_21v" },
184 { 22, 11, 2,
"sel_11h",
"sel_comb_22h",
"sel_11v",
"sel_comb_22v" },
185 { 23, 6, 4,
"sel_6h",
"sel_comb_24h",
"sel_6v",
"sel_comb_24v" },
186 { 24, 6, 4,
"sel_6h",
"sel_comb_24h",
"sel_6v",
"sel_comb_24v" },
187 { 25, 5, 5,
"sel_5h",
"sel_comb_25h",
"sel_5v",
"sel_comb_25v" },
188 { 26, 5, 5,
"sel_5h",
"sel_comb_25h",
"sel_5v",
"sel_comb_25v" },
189 { 27, 9, 3,
"sel_9h",
"sel_comb_27h",
"sel_9v",
"sel_comb_27v" },
190 { 28, 7, 4,
"sel_7h",
"sel_comb_28h",
"sel_7v",
"sel_comb_28v" },
191 { 29, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
192 { 30, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
193 { 31, 6, 5,
"sel_6h",
"sel_comb_30h",
"sel_6v",
"sel_comb_30v" },
194 { 32, 8, 4,
"sel_8h",
"sel_comb_32h",
"sel_8v",
"sel_comb_32v" },
195 { 33, 11, 3,
"sel_11h",
"sel_comb_33h",
"sel_11v",
"sel_comb_33v" },
196 { 34, 7, 5,
"sel_7h",
"sel_comb_35h",
"sel_7v",
"sel_comb_35v" },
197 { 35, 7, 5,
"sel_7h",
"sel_comb_35h",
"sel_7v",
"sel_comb_35v" },
198 { 36, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
199 { 37, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
200 { 38, 6, 6,
"sel_6h",
"sel_comb_36h",
"sel_6v",
"sel_comb_36v" },
201 { 39, 13, 3,
"sel_13h",
"sel_comb_39h",
"sel_13v",
"sel_comb_39v" },
202 { 40, 8, 5,
"sel_8h",
"sel_comb_40h",
"sel_8v",
"sel_comb_40v" },
203 { 41, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
204 { 42, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
205 { 43, 7, 6,
"sel_7h",
"sel_comb_42h",
"sel_7v",
"sel_comb_42v" },
206 { 44, 11, 4,
"sel_11h",
"sel_comb_44h",
"sel_11v",
"sel_comb_44v" },
207 { 45, 9, 5,
"sel_9h",
"sel_comb_45h",
"sel_9v",
"sel_comb_45v" },
208 { 46, 9, 5,
"sel_9h",
"sel_comb_45h",
"sel_9v",
"sel_comb_45v" },
209 { 47, 8, 6,
"sel_8h",
"sel_comb_48h",
"sel_8v",
"sel_comb_48v" },
210 { 48, 8, 6,
"sel_8h",
"sel_comb_48h",
"sel_8v",
"sel_comb_48v" },
211 { 49, 7, 7,
"sel_7h",
"sel_comb_49h",
"sel_7v",
"sel_comb_49v" },
212 { 50, 10, 5,
"sel_10h",
"sel_comb_50h",
"sel_10v",
"sel_comb_50v" },
213 { 51, 10, 5,
"sel_10h",
"sel_comb_50h",
"sel_10v",
"sel_comb_50v" },
214 { 52, 13, 4,
"sel_13h",
"sel_comb_52h",
"sel_13v",
"sel_comb_52v" },
215 { 53, 9, 6,
"sel_9h",
"sel_comb_54h",
"sel_9v",
"sel_comb_54v" },
216 { 54, 9, 6,
"sel_9h",
"sel_comb_54h",
"sel_9v",
"sel_comb_54v" },
217 { 55, 11, 5,
"sel_11h",
"sel_comb_55h",
"sel_11v",
"sel_comb_55v" },
218 { 56, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
219 { 57, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
220 { 58, 8, 7,
"sel_8h",
"sel_comb_56h",
"sel_8v",
"sel_comb_56v" },
221 { 59, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
222 { 60, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
223 { 61, 10, 6,
"sel_10h",
"sel_comb_60h",
"sel_10v",
"sel_comb_60v" },
224 { 62, 9, 7,
"sel_9h",
"sel_comb_63h",
"sel_9v",
"sel_comb_63v" },
225 { 63, 9, 7,
"sel_9h",
"sel_comb_63h",
"sel_9v",
"sel_comb_63v" } };
243 PROCNAME(
"selaCreate");
246 n = INITIAL_PTR_ARRAYSIZE;
248 L_WARNING(
"%d sels\n", procName, n);
250 if ((sela = (
SELA *)LEPT_CALLOC(1,
sizeof(
SELA))) == NULL)
251 return (
SELA *)ERROR_PTR(
"sela not made", procName, NULL);
257 if ((sela->
sel = (
SEL **)LEPT_CALLOC(n,
sizeof(
SEL *))) == NULL) {
259 return (
SELA *)ERROR_PTR(
"sel ptrs not made", procName, NULL);
278 if ((sela = *psela) == NULL)
281 for (i = 0; i < sela->
n; i++)
283 LEPT_FREE(sela->
sel);
312 PROCNAME(
"selCreate");
314 if ((sel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL))) == NULL)
315 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
321 LEPT_FREE(sel->
name);
323 return (
SEL *)ERROR_PTR(
"data not allocated", procName, NULL);
342 PROCNAME(
"selDestroy");
345 L_WARNING(
"ptr address is NULL!\n", procName);
348 if ((sel = *psel) == NULL)
351 for (i = 0; i < sel->
sy; i++)
352 LEPT_FREE(sel->
data[i]);
353 LEPT_FREE(sel->
data);
355 LEPT_FREE(sel->
name);
372 l_int32 sx, sy, cx, cy, i, j;
378 return (
SEL *)ERROR_PTR(
"sel not defined", procName, NULL);
380 if ((csel = (
SEL *)LEPT_CALLOC(1,
sizeof(
SEL))) == NULL)
381 return (
SEL *)ERROR_PTR(
"csel not made", procName, NULL);
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) {
486 for (i = 0; i < factor2; i++) {
487 z = factor1 / 2 + i * factor1;
490 if (direction == L_HORIZ)
518 l_int32 i, j, success;
521 PROCNAME(
"create2dIntArray");
523 if ((array = (l_int32 **)LEPT_CALLOC(sy,
sizeof(l_int32 *))) == NULL)
524 return (l_int32 **)ERROR_PTR(
"ptr array not made", procName, NULL);
527 for (i = 0; i < sy; i++) {
528 if ((array[i] = (l_int32 *)LEPT_CALLOC(sx,
sizeof(l_int32))) == NULL) {
533 if (success)
return array;
536 for (j = 0; j < i; j++)
539 return (l_int32 **)ERROR_PTR(
"array not made", procName, NULL);
574 PROCNAME(
"selaAddSel");
577 return ERROR_INT(
"sela not defined", procName, 1);
579 return ERROR_INT(
"sel not defined", procName, 1);
580 if (!sel->
name && !selname)
581 return ERROR_INT(
"added sel must have name", procName, 1);
583 return ERROR_INT(
"invalid copyflag", procName, 1);
586 if ((csel =
selCopy(sel)) == NULL)
587 return ERROR_INT(
"csel not made", procName, 1);
613 PROCNAME(
"selaExtendArray");
616 return ERROR_INT(
"sela not defined", procName, 1);
619 sizeof(
SEL *) * sela->
nalloc,
620 2 *
sizeof(
SEL *) * sela->
nalloc)) == NULL)
621 return ERROR_INT(
"new ptr array not returned", procName, 1);
641 PROCNAME(
"selaGetCount");
644 return ERROR_INT(
"sela not defined", procName, 0);
667 PROCNAME(
"selaGetSel");
670 return (
SEL *)ERROR_PTR(
"sela not defined", procName, NULL);
672 if (i < 0 || i >= sela->
n)
673 return (
SEL *)ERROR_PTR(
"invalid index", procName, NULL);
687 PROCNAME(
"selGetName");
690 return (
char *)ERROR_PTR(
"sel not defined", procName, NULL);
713 PROCNAME(
"selSetName");
716 return ERROR_INT(
"sel not defined", procName, 1);
741 PROCNAME(
"selaFindSelByName");
743 if (pindex) *pindex = -1;
744 if (psel) *psel = NULL;
747 return ERROR_INT(
"sela not defined", procName, 1);
750 for (i = 0; i < n; i++)
753 L_WARNING(
"missing sel\n", procName);
758 if (sname && (!strcmp(name, sname))) {
786 PROCNAME(
"selGetElement");
789 return ERROR_INT(
"&type not defined", procName, 1);
790 *ptype = SEL_DONT_CARE;
792 return ERROR_INT(
"sel not defined", procName, 1);
793 if (row < 0 || row >= sel->
sy)
794 return ERROR_INT(
"sel row out of bounds", procName, 1);
795 if (col < 0 || col >= sel->
sx)
796 return ERROR_INT(
"sel col out of bounds", procName, 1);
798 *ptype = sel->
data[row][col];
826 PROCNAME(
"selSetElement");
829 return ERROR_INT(
"sel not defined", procName, 1);
830 if (type != SEL_HIT && type != SEL_MISS && type != SEL_DONT_CARE)
831 return ERROR_INT(
"invalid sel element type", procName, 1);
832 if (row < 0 || row >= sel->
sy)
833 return ERROR_INT(
"sel row out of bounds", procName, 1);
834 if (col < 0 || col >= sel->
sx)
835 return ERROR_INT(
"sel col out of bounds", procName, 1);
837 sel->
data[row][col] = type;
856 PROCNAME(
"selGetParameters");
863 return ERROR_INT(
"sel not defined", procName, 1);
864 if (psy) *psy = sel->
sy;
865 if (psx) *psx = sel->
sx;
866 if (pcy) *pcy = sel->
cy;
867 if (pcx) *pcx = sel->
cx;
884 PROCNAME(
"selSetOrigin");
887 return ERROR_INT(
"sel not defined", procName, 1);
905 l_int32 sx, sy, cx, cy, i, j;
907 PROCNAME(
"selGetTypeAtOrigin");
910 return ERROR_INT(
"&type not defined", procName, 1);
911 *ptype = SEL_DONT_CARE;
913 return ERROR_INT(
"sel not defined", procName, 1);
916 for (i = 0; i < sy; i++) {
917 for (j = 0; j < sx; j++) {
918 if (i == cy && j == cx) {
925 return ERROR_INT(
"sel origin not found", procName, 1);
941 l_int32 i, nsels, sx, sy;
944 PROCNAME(
"selaGetBrickName");
947 return (
char *)ERROR_PTR(
"sela not defined", procName, NULL);
950 for (i = 0; i < nsels; i++) {
953 if (hsize == sx && vsize == sy)
957 return (
char *)ERROR_PTR(
"sel not found", procName, NULL);
981 char combname[L_BUFSIZE];
982 l_int32 i, nsels, sx, sy, found;
985 PROCNAME(
"selaGetCombName");
988 return (
char *)ERROR_PTR(
"sela not defined", procName, NULL);
989 if (direction != L_HORIZ && direction != L_VERT)
990 return (
char *)ERROR_PTR(
"invalid direction", procName, NULL);
993 if (direction == L_HORIZ)
994 snprintf(combname, L_BUFSIZE,
"sel_comb_%dh", size);
996 snprintf(combname, L_BUFSIZE,
"sel_comb_%dv", size);
1000 for (i = 0; i < nsels; i++) {
1003 if (sy != 1 && sx != 1)
1006 if (!strcmp(selname, combname)) {
1015 return (
char *)ERROR_PTR(
"sel not found", procName, NULL);
1021 static void selaComputeCompositeParameters(
const char *fileout);
1041 selaComputeCompositeParameters(
const char *fileout)
1043 char *str, *nameh1, *nameh2, *namev1, *namev2;
1044 char buf[L_BUFSIZE];
1045 l_int32 size, size1, size2, len;
1047 SELA *selabasic, *selacomb;
1052 for (size = 2; size < 64; size++) {
1063 snprintf(buf, L_BUFSIZE,
1064 " { %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\" },",
1065 size, size1, size2, nameh1, nameh2, namev1, namev2);
1114 PROCNAME(
"selaGetSelnames");
1116 if (psize1) *psize1 = 0;
1117 if (psize2) *psize2 = 0;
1118 if (pnameh1) *pnameh1 = NULL;
1119 if (pnameh2) *pnameh2 = NULL;
1120 if (pnamev1) *pnamev1 = NULL;
1121 if (pnamev2) *pnamev2 = NULL;
1122 if (size < 2 || size > 63)
1123 return ERROR_INT(
"valid size range is {2 ... 63}", procName, 1);
1126 *psize1 = comp_parameter_map[index].size1;
1128 *psize2 = comp_parameter_map[index].size2;
1130 *pnameh1 =
stringNew(comp_parameter_map[index].selnameh1);
1132 *pnameh2 =
stringNew(comp_parameter_map[index].selnameh2);
1134 *pnamev1 =
stringNew(comp_parameter_map[index].selnamev1);
1136 *pnamev2 =
stringNew(comp_parameter_map[index].selnamev2);
1155 PROCNAME(
"selaGetSelnames");
1158 return (
SARRAY *)ERROR_PTR(
"sela not defined", procName, NULL);
1160 return (
SARRAY *)ERROR_PTR(
"no sels in sela", procName, NULL);
1163 return (
SARRAY *)ERROR_PTR(
"sa not made", procName, NULL);
1164 for (i = 0; i < n; i++) {
1199 l_int32 sx, sy, cx, cy, i, j;
1200 l_int32 maxxp, maxyp, maxxn, maxyn;
1202 PROCNAME(
"selaFindMaxTranslations");
1204 if (!pxp || !pyp || !pxn || !pyn)
1205 return ERROR_INT(
"&xp (etc) defined", procName, 1);
1206 *pxp = *pyp = *pxn = *pyn = 0;
1208 return ERROR_INT(
"sel not defined", procName, 1);
1211 maxxp = maxyp = maxxn = maxyn = 0;
1212 for (i = 0; i < sy; i++) {
1213 for (j = 0; j < sx; j++) {
1214 if (sel->
data[i][j] == 1) {
1215 maxxp = L_MAX(maxxp, cx - j);
1216 maxyp = L_MAX(maxyp, cy - i);
1217 maxxn = L_MAX(maxxn, j - cx);
1218 maxyn = L_MAX(maxyn, i - cy);
1246 l_int32 i, j, ni, nj, sx, sy, cx, cy, nsx, nsy, ncx, ncy, type;
1249 PROCNAME(
"selRotateOrth");
1252 return (
SEL *)ERROR_PTR(
"sel not defined", procName, NULL);
1253 if (quads < 0 || quads > 4)
1254 return (
SEL *)ERROR_PTR(
"quads not in {0,1,2,3,4}", procName, NULL);
1255 if (quads == 0 || quads == 4)
1264 }
else if (quads == 2) {
1279 for (i = 0; i < sy; i++) {
1280 for (j = 0; j < sx; j++) {
1285 }
else if (quads == 2) {
1315 PROCNAME(
"selaRead");
1318 return (
SELA *)ERROR_PTR(
"fname not defined", procName, NULL);
1321 return (
SELA *)ERROR_PTR(
"stream not opened", procName, NULL);
1324 return (
SELA *)ERROR_PTR(
"sela not returned", procName, NULL);
1341 l_int32 i, n, version;
1345 PROCNAME(
"selaReadStream");
1348 return (
SELA *)ERROR_PTR(
"stream not defined", procName, NULL);
1350 if (fscanf(fp,
"\nSela Version %d\n", &version) != 1)
1351 return (
SELA *)ERROR_PTR(
"not a sela file", procName, NULL);
1352 if (version != SEL_VERSION_NUMBER)
1353 return (
SELA *)ERROR_PTR(
"invalid sel version", procName, NULL);
1354 if (fscanf(fp,
"Number of Sels = %d\n\n", &n) != 1)
1355 return (
SELA *)ERROR_PTR(
"not a sela file", procName, NULL);
1358 return (
SELA *)ERROR_PTR(
"sela not made", procName, NULL);
1361 for (i = 0; i < n; i++) {
1364 return (
SELA *)ERROR_PTR(
"sel not read", procName, NULL);
1385 PROCNAME(
"selRead");
1388 return (
SEL *)ERROR_PTR(
"fname not defined", procName, NULL);
1391 return (
SEL *)ERROR_PTR(
"stream not opened", procName, NULL);
1394 return (
SEL *)ERROR_PTR(
"sela not returned", procName, NULL);
1412 char linebuf[L_BUFSIZE];
1413 l_int32 sy, sx, cy, cx, i, j, version, ignore;
1416 PROCNAME(
"selReadStream");
1419 return (
SEL *)ERROR_PTR(
"stream not defined", procName, NULL);
1421 if (fscanf(fp,
" Sel Version %d\n", &version) != 1)
1422 return (
SEL *)ERROR_PTR(
"not a sel file", procName, NULL);
1423 if (version != SEL_VERSION_NUMBER)
1424 return (
SEL *)ERROR_PTR(
"invalid sel version", procName, NULL);
1426 if (fgets(linebuf, L_BUFSIZE, fp) == NULL)
1427 return (
SEL *)ERROR_PTR(
"error reading into linebuf", procName, NULL);
1429 sscanf(linebuf,
" ------ %200s ------", selname);
1431 if (fscanf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n",
1432 &sy, &sx, &cy, &cx) != 4) {
1434 return (
SEL *)ERROR_PTR(
"dimensions not read", procName, NULL);
1437 if ((sel =
selCreate(sy, sx, selname)) == NULL) {
1439 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
1443 for (i = 0; i < sy; i++) {
1444 ignore = fscanf(fp,
" ");
1445 for (j = 0; j < sx; j++)
1446 ignore = fscanf(fp,
"%1d", &sel->
data[i][j]);
1447 ignore = fscanf(fp,
"\n");
1449 ignore = fscanf(fp,
"\n");
1469 PROCNAME(
"selaWrite");
1472 return ERROR_INT(
"fname not defined", procName, 1);
1474 return ERROR_INT(
"sela not defined", procName, 1);
1477 return ERROR_INT(
"stream not opened", procName, 1);
1499 PROCNAME(
"selaWriteStream");
1502 return ERROR_INT(
"stream not defined", procName, 1);
1504 return ERROR_INT(
"sela not defined", procName, 1);
1507 fprintf(fp,
"\nSela Version %d\n", SEL_VERSION_NUMBER);
1508 fprintf(fp,
"Number of Sels = %d\n\n", n);
1509 for (i = 0; i < n; i++) {
1531 PROCNAME(
"selWrite");
1534 return ERROR_INT(
"fname not defined", procName, 1);
1536 return ERROR_INT(
"sel not defined", procName, 1);
1539 return ERROR_INT(
"stream not opened", procName, 1);
1558 l_int32 sx, sy, cx, cy, i, j;
1560 PROCNAME(
"selWriteStream");
1563 return ERROR_INT(
"stream not defined", procName, 1);
1565 return ERROR_INT(
"sel not defined", procName, 1);
1568 fprintf(fp,
" Sel Version %d\n", SEL_VERSION_NUMBER);
1569 fprintf(fp,
" ------ %s ------\n",
selGetName(sel));
1570 fprintf(fp,
" sy = %d, sx = %d, cy = %d, cx = %d\n", sy, sx, cy, cx);
1571 for (i = 0; i < sy; i++) {
1573 for (j = 0; j < sx; j++)
1574 fprintf(fp,
"%d", sel->
data[i][j]);
1622 l_int32 y, x, norig;
1625 PROCNAME(
"selCreateFromString");
1627 if (!text || text[0] ==
'\0')
1628 return (
SEL *)ERROR_PTR(
"text undefined or empty", procName, NULL);
1630 return (
SEL *)ERROR_PTR(
"height must be > 0", procName, NULL);
1632 return (
SEL *)ERROR_PTR(
"width must be > 0", procName, NULL);
1633 if (strlen(text) != (
size_t)w * h)
1634 return (
SEL *)ERROR_PTR(
"text size != w * h", procName, NULL);
1638 for (y = 0; y < h; ++y) {
1639 for (x = 0; x < w; ++x) {
1670 return (
SEL *)ERROR_PTR(
"unknown char", procName, NULL);
1675 L_ERROR(
"Exactly one origin must be specified; this string has %d\n",
1709 l_int32 sx, sy, cx, cy, x, y;
1711 PROCNAME(
"selPrintToString");
1714 return (
char *)ERROR_PTR(
"sel not defined", procName, NULL);
1717 if ((str = (
char *)LEPT_CALLOC(1, sy * (sx + 1) + 1)) == NULL)
1718 return (
char *)ERROR_PTR(
"calloc fail for str", procName, NULL);
1721 for (y = 0; y < sy; ++y) {
1722 for (x = 0; x < sx; ++x) {
1724 is_center = (x == cx && y == cy);
1727 *(strptr++) = is_center ?
'X' :
'x';
1730 *(strptr++) = is_center ?
'O' :
'o';
1733 *(strptr++) = is_center ?
'C' :
' ';
1781 char *filestr, *line;
1782 l_int32 i, n, first, last, nsel, insel;
1784 NUMA *nafirst, *nalast;
1789 PROCNAME(
"selaCreateFromFile");
1792 return (
SELA *)ERROR_PTR(
"filename not defined", procName, NULL);
1806 for (i = 0; i < n; i++) {
1809 (line[0] !=
'\0' && line[0] !=
' ' &&
1810 line[0] !=
'\t' && line[0] !=
'\n' && line[0] !=
'#')) {
1816 (line[0] ==
'\0' || line[0] ==
' ' ||
1817 line[0] ==
'\t' || line[0] ==
'\n' || line[0] ==
'#')) {
1828 for (i = 0; i < nsel; i++) {
1832 fprintf(stderr,
"Error reading sel from %d to %d\n", first, last);
1837 return (
SELA *)ERROR_PTR(
"bad sela file", procName, NULL);
1886 l_int32 n, len, i, w, h, y, x;
1889 PROCNAME(
"selCreateFromSArray");
1892 return (
SEL *)ERROR_PTR(
"sa not defined", procName, NULL);
1894 if (first < 0 || first >= n || last <= first || last >= n)
1895 return (
SEL *)ERROR_PTR(
"invalid range", procName, NULL);
1901 if (line[0] !=
'"' || line[len - 1] !=
'"')
1902 return (
SEL *)ERROR_PTR(
"invalid format", procName, NULL);
1904 if ((sel =
selCreate(h, w, name)) == NULL)
1905 return (
SEL *)ERROR_PTR(
"sel not made", procName, NULL);
1906 for (i = first + 1; i <= last; i++) {
1909 for (x = 0; x < w; ++x) {
1933 return (
SEL *)ERROR_PTR(
"unknown char", procName, NULL);
1964 l_int32 i, n, x, y, w, h;
1968 PROCNAME(
"selCreateFromPta");
1971 return (
SEL *)ERROR_PTR(
"pta not defined", procName, NULL);
1972 if (cy < 0 || cx < 0)
1973 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", procName, NULL);
1976 return (
SEL *)ERROR_PTR(
"no pts in pta", procName, NULL);
1982 return (
SEL *)ERROR_PTR(
"not all x and y >= 0", procName, NULL);
1986 for (i = 0; i < n; i++) {
2015 l_int32 i, j, w, h, d;
2018 PROCNAME(
"selCreateFromPix");
2021 return (
SEL *)ERROR_PTR(
"pix not defined", procName, NULL);
2022 if (cy < 0 || cx < 0)
2023 return (
SEL *)ERROR_PTR(
"(cy, cx) not both >= 0", procName, NULL);
2026 return (
SEL *)ERROR_PTR(
"pix not 1 bpp", procName, NULL);
2030 for (i = 0; i < h; i++) {
2031 for (j = 0; j < w; j++) {
2064 char *basename, *selname;
2066 PROCNAME(
"selReadFromColorImage");
2070 LEPT_FREE(basename);
2072 if ((pix =
pixRead(pathname)) == NULL) {
2074 return (
SEL *)ERROR_PTR(
"pix not returned", procName, NULL);
2077 L_ERROR(
"sel not made\n", procName);
2110 const char *selname)
2114 l_int32 hascolor, hasorigin, nohits;
2115 l_int32 w, h, d, i, j, red, green, blue;
2118 PROCNAME(
"selCreateFromColorPix");
2121 return (
SEL *)ERROR_PTR(
"pixs not defined", procName, NULL);
2124 cmap = pixGetColormap(pixs);
2128 if (hascolor == FALSE && d != 32)
2129 return (
SEL *)ERROR_PTR(
"pixs has no color", procName, NULL);
2131 if ((sel =
selCreate (h, w, NULL)) == NULL)
2132 return (
SEL *)ERROR_PTR (
"sel not made", procName, NULL);
2138 for (i = 0; i < h; i++) {
2139 for (j = 0; j < w; j++) {
2150 if (red < 255 && green < 255 && blue < 255) {
2152 L_WARNING(
"multiple origins in sel image\n", procName);
2156 if (!red && green && !blue) {
2159 }
else if (red && !green && !blue) {
2161 }
else if (red && green && blue) {
2165 return (
SEL *)ERROR_PTR(
"invalid color", procName, NULL);
2172 return (
SEL *)ERROR_PTR(
"no hits in sel", procName, NULL);
2204 l_int32 i, j, w, h, sx, sy, cx, cy, type, width;
2205 l_int32 radius1, radius2, shift1, shift2, x0, y0;
2206 PIX *pixd, *pix2, *pixh, *pixm, *pixorig;
2207 PTA *pta1, *pta2, *pta1t, *pta2t;
2209 PROCNAME(
"selDisplayInPix");
2212 return (
PIX *)ERROR_PTR(
"sel not defined", procName, NULL);
2214 L_WARNING(
"size < 13; setting to 13\n", procName);
2220 L_WARNING(
"grid thickness < 2; setting to 2\n", procName);
2224 w = size * sx + gthick * (sx + 1);
2225 h = size * sy + gthick * (sy + 1);
2229 for (i = 0; i <= sy; i++)
2231 w - 1, gthick / 2 + i * (size + gthick),
2233 for (j = 0; j <= sx; j++)
2235 gthick / 2 + j * (size + gthick), h - 1,
2239 radius1 = (l_int32)(0.85 * ((size - 1) / 2.0) + 0.5);
2240 radius2 = (l_int32)(0.65 * ((size - 1) / 2.0) + 0.5);
2243 shift1 = (size - 1) / 2 - radius1;
2244 shift2 = (size - 1) / 2 - radius2;
2255 size / 2, (l_int32)(0.88 * size),
2258 (l_int32)(0.85 * size), size / 2,
2260 pixRasterop(pixorig, size / 2 - width, size / 2 - width,
2265 if (type == SEL_HIT)
2266 pixXor(pixorig, pixorig, pixh);
2267 else if (type == SEL_MISS)
2268 pixXor(pixorig, pixorig, pixm);
2272 for (i = 0; i < sy; i++) {
2274 for (j = 0; j < sx; j++) {
2276 if (i == cy && j == cx)
2278 else if (type == SEL_HIT)
2280 else if (type == SEL_MISS)
2282 x0 += size + gthick;
2284 y0 += size + gthick;
2324 l_int32 nsels, i, w, width;
2329 PROCNAME(
"selaDisplayInPix");
2332 return (
PIX *)ERROR_PTR(
"sela not defined", procName, NULL);
2334 L_WARNING(
"size < 13; setting to 13\n", procName);
2340 L_WARNING(
"grid thickness < 2; setting to 2\n", procName);
2344 L_WARNING(
"spacing < 5; setting to 5\n", procName);
2351 for (i = 0; i < nsels; i++) {
2361 ncols = L_MIN(nsels, ncols);
2362 for (i = 0; i < ncols; i++) {
2368 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()
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()
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()
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()
void * reallocNew(void **pindata, l_int32 oldsize, l_int32 newsize)
reallocNew()
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()
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()
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()
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)