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

Function morphSequenceVerify

deps/leptonica/src/morphseq.c:736–857  ·  view source on GitHub ↗

-------------------------------------------------------------------------* * Parser verifier for binary morphological operations * *-------------------------------------------------------------------------*/ ! * \brief morphSequenceVerify() * * \param[in] sa string array of operation sequence * \return TRUE if valid; FALSE otherwise or on error * * * Notes:

Source from the content-addressed store, hash-verified

734 * </pre>
735 */
736l_int32
737morphSequenceVerify(SARRAY *sa)
738{
739char *rawop, *op;
740l_int32 nops, i, j, nred, fact, valid, w, h, netred, border;
741l_int32 level[4];
742l_int32 intlogbase2[5] = {1, 2, 3, 0, 4}; /* of arg/4 */
743
744 PROCNAME("morphSequenceVerify");
745
746 if (!sa)
747 return ERROR_INT("sa not defined", procName, FALSE);
748
749 nops = sarrayGetCount(sa);
750 valid = TRUE;
751 netred = 0;
752 border = 0;
753 for (i = 0; i < nops; i++) {
754 rawop = sarrayGetString(sa, i, L_NOCOPY);
755 op = stringRemoveChars(rawop, " \n\t");
756 switch (op[0])
757 {
758 case 'd':
759 case 'D':
760 case 'e':
761 case 'E':
762 case 'o':
763 case 'O':
764 case 'c':
765 case 'C':
766 if (sscanf(&op[1], "%d.%d", &w, &h) != 2) {
767 fprintf(stderr, "*** op: %s invalid\n", op);
768 valid = FALSE;
769 break;
770 }
771 if (w <= 0 || h <= 0) {
772 fprintf(stderr,
773 "*** op: %s; w = %d, h = %d; must both be > 0\n",
774 op, w, h);
775 valid = FALSE;
776 break;
777 }
778/* fprintf(stderr, "op = %s; w = %d, h = %d\n", op, w, h); */
779 break;
780 case 'r':
781 case 'R':
782 nred = strlen(op) - 1;
783 netred += nred;
784 if (nred < 1 || nred > 4) {
785 fprintf(stderr,
786 "*** op = %s; num reduct = %d; must be in {1,2,3,4}\n",
787 op, nred);
788 valid = FALSE;
789 break;
790 }
791 for (j = 0; j < nred; j++) {
792 level[j] = op[j + 1] - '0';
793 if (level[j] < 1 || level[j] > 4) {

Callers 4

pixMorphSequenceFunction · 0.85
pixMorphCompSequenceFunction · 0.85
pixMorphSequenceDwaFunction · 0.85
pixMorphCompSequenceDwaFunction · 0.85

Calls 3

sarrayGetCountFunction · 0.85
sarrayGetStringFunction · 0.85
stringRemoveCharsFunction · 0.85

Tested by

no test coverage detected