MCPcopy Create free account
hub / github.com/creatale/node-dv / fmorphautogen2

Function fmorphautogen2

deps/leptonica/src/fmorphauto.c:489–665  ·  view source on GitHub ↗

* fmorphautogen2() * * Input: sela * fileindex * filename ( ; can be null) * Return: 0 if OK; 1 on error * * Notes: * (1) This function uses morphtemplate2.txt to create a * low-level file that contains the low-level functions for * implementing dilation and erosion for every sel * in the input sela. *

Source from the content-addressed store, hash-verified

487 * (4) If filename != NULL, the output file is <filename>low.<n>.c.
488 */
489l_int32
490fmorphautogen2(SELA *sela,
491 l_int32 fileindex,
492 const char *filename)
493{
494char *filestr, *linestr, *fname;
495char *str_doc1, *str_doc2, *str_doc3, *str_doc4, *str_def1;
496char bigbuf[L_BUF_SIZE];
497char breakstring[] = " break;";
498char staticstring[] = "static void";
499l_int32 i, nsels, nbytes, actstart, end, newstart;
500l_int32 argstart, argend, loopstart, loopend, finalstart, finalend;
501size_t size;
502SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6;
503SEL *sel;
504
505 PROCNAME("fmorphautogen2");
506
507 if (!sela)
508 return ERROR_INT("sela not defined", procName, 1);
509 if (fileindex < 0)
510 fileindex = 0;
511 if ((nsels = selaGetCount(sela)) == 0)
512 return ERROR_INT("no sels in sela", procName, 1);
513
514 /* Make the array of textlines from morphtemplate2.txt */
515 if ((filestr = (char *)l_binaryRead(TEMPLATE2, &size)) == NULL)
516 return ERROR_INT("filestr not made", procName, 1);
517 sa1 = sarrayCreateLinesFromString(filestr, 1);
518 LEPT_FREE(filestr);
519 if (!sa1)
520 return ERROR_INT("sa1 not made", procName, 1);
521
522 /* Make the array of static function names */
523 if ((sa2 = sarrayCreate(2 * nsels)) == NULL) {
524 sarrayDestroy(&sa1);
525 return ERROR_INT("sa2 not made", procName, 1);
526 }
527 for (i = 0; i < nsels; i++) {
528 sprintf(bigbuf, "fdilate_%d_%d", fileindex, i);
529 sarrayAddString(sa2, bigbuf, L_COPY);
530 sprintf(bigbuf, "ferode_%d_%d", fileindex, i);
531 sarrayAddString(sa2, bigbuf, L_COPY);
532 }
533
534 /* Make the static prototype strings */
535 sa3 = sarrayCreate(2 * nsels); /* should be ok */
536 for (i = 0; i < 2 * nsels; i++) {
537 fname = sarrayGetString(sa2, i, L_NOCOPY);
538 sprintf(bigbuf, "static void %s%s", fname, PROTOARGS);
539 sarrayAddString(sa3, bigbuf, L_COPY);
540 }
541
542 /* Make strings containing function names */
543 sprintf(bigbuf, " * l_int32 fmorphopgen_low_%d()",
544 fileindex);
545 str_doc1 = stringNew(bigbuf);
546 sprintf(bigbuf, " * void fdilate_%d_*()", fileindex);

Callers 1

fmorphautogenFunction · 0.85

Calls 15

selaGetCountFunction · 0.85
l_binaryReadFunction · 0.85
sarrayCreateFunction · 0.85
sarrayDestroyFunction · 0.85
sarrayAddStringFunction · 0.85
sarrayGetStringFunction · 0.85
stringNewFunction · 0.85
sarrayParseRangeFunction · 0.85
sarrayAppendRangeFunction · 0.85
selaGetSelFunction · 0.85
sarrayJoinFunction · 0.85

Tested by

no test coverage detected