Exemple #1
0
/************************************************************************
*                                                                       *
*  Frame numbers are stripped out of the command string.
*  Each image vector is repllaced with just a "#".
*  
*  (STATIC)								*
*									*/
ParmList
Win_math::get_imagevector_list(char *name, char *cmd)
{
    int i;
    int j;
    int n;
    ParmList plp;		// List of parms (each one a framevector)
    ParmList plf;		// List of frame numbers (framevector)
    ParmList pli;		// List of images (imagevector)
    Imginfo *img;

    plp = allocParm(name, PL_PARM, 0);
    while (plf=get_framevector("framevec", &cmd)){ // "cmd" pointer gets updated
	// Convert framevector to imagevector
	n = countParm(plf);	// n will be positive
	pli = allocParm("imagevec", PL_PTR, n);
	for (i=0; i<n; i++){
	    getIntParm(plf, &j, i);
	    img = Gframe::get_frame_by_number(j)->imginfo;
	    if (!img){
		msgerr_print("Math: no image in input frame #%d.", j);
		freeParms(plp);
		freeParms(plf);
		return 0;
	    }
	    setPtrParm(pli, img->st, i);
	}
	plp = appendParmParm(plp, pli);
    }
    return plp;
}
Exemple #2
0
void
freeParms(ParmList p)
{
    int n;
    int i;
    int type;
    char *s;
    ParmList p2;

    if (p){
	n = countParm(p);
	if ((type=typeofParm(p)) == PL_PARM) {
	    for (i=0; i<n; i++){
		getParmParm(p, &p2, i);
		freeParms(p2);
	    }
	}else if (type == PL_STRING){
	    for (i=0; i<n; i++){
		getStrParm(p, &s, i);
		if (s){
		    free(s);
		}
	    }
	}
	free(p);
    }
}
Exemple #3
0
/************************************************************************
*                                                                       *
*  The string "cmd" is MODIFIED by removing all image specs
*  
*  (STATIC)								*
*									*/
ParmList
Win_math::parse_frame_spec(char *str, ParmList pl)
{
    int j;
    int brange;
    int erange;

    while (*str && *str != ')'){
	str++;
	erange = brange = (int)strtoul(str, &str, 10);
	if (*str == '-'){
	    str++;
	    erange = (int)strtoul(str, &str, 10);
	}
	for (j=brange; j<=erange; j++){
	    if (!Gframe::get_frame_by_number(j)){
		msgerr_print("Math: frame #%d does not exist", j);
		freeParms(pl);
		return NULL;
	    }
	    pl = appendIntParm(pl, j);
	}
    }
    return pl;
}
Exemple #4
0
/************************************************************************
*                                                                       *
*  Parse the RHS of math expression "cmd".
*  Returns number of source images
*  (STATIC)								*
*									*/
int
Win_math::parse_rhs(char *cmd,
		    ParmList *ddls,
		    ParmList *ddlvecs,
		    ParmList *strings,
		    ParmList *constants)
{
    int i;
    int j;
    int m;
    int n;
    char *pc;
    char *tbuf;
    ParmList frames;
    ParmList pl;
    void *pv;
    Imginfo *img;

    pc = strchr(cmd, '=');
    if (!pc){
	return 0;
    }

    tbuf = strdup(++pc);	// tbuf contains the RHS
    if (!tbuf) return 0;

    *ddlvecs = get_imagevector_list("src_ddlvecs", tbuf); // frame nbrs stripped

    *ddls = allocParm("src_ddls", PL_PTR, 0);
    n = countParm(*ddlvecs);
    for (i=0; i<n; i++){
	getParmParm(*ddlvecs, &pl, i);
	m = countParm(pl);
	for (j=0; j<m; j++){
	    getPtrParm(pl, &pv, j);
	    *ddls = appendPtrParm(*ddls, pv);
	}
    }
    /*fprintf(stderr,"cmd w/o frames = \"%s\"\n", tbuf);/*CMP*/

    *strings = get_stringlist("src_strings", tbuf); // strings stripped off
    /*fprintf(stderr,"cmd w/o strings = \"%s\"\n", tbuf);/*CMP*/

    *constants = get_constlist("src_constants", tbuf); // tbuf unchanged
    /*fprintf(stderr,"cmd w/ constants = \"%s\"\n", tbuf);/*CMP*/

    n = countParm(*ddls);
    if (!n){
	msgerr_print("Math: no input image(s) specified");
	freeParms(*ddls);
	*ddls = NULL;
	return 0;
    }
    free(tbuf);
    return n;
}
Exemple #5
0
/************************************************************************
*                                                                       *
*  The "cmd" pointer is moved past the stuff that gets parsed.
*  The string itself is not changed.
*  Parses stuff like #1 or ##1-10 or #(1,2,4-6,10) or #(1-)
*  
*  (STATIC)								*
*									*/
ParmList
Win_math::get_framevector(char *name, char **cmd)
{
    int i;
    int j;
    int n;
    int brange;
    int erange;
    char *p;
    char *pp;
    char *ppp;
    ParmList pl;

    /* Load up the list of frames */
    pl = 0;
    if (p=strchr(*cmd, '#')){	// p --> first #
	pl = allocParm(name, PL_INT, 0);
	pp = ++p;		// Mark spot to delete frame numbers
	if (*p == '#'){
	    /* Specified a range of frames, like ##20-30 */
	    p++;
	    sscanf(p,"%u", &brange);
	    erange = brange;
	    p += strspn(p, "0123456789");
	    switch (*p){
	      case '-':
		p++;
		sscanf(p,"%u", &erange);
		p += strspn(p, "0123456789");
		break;
	    }
	    for (j=brange; j<=erange; j++){
		if (!Gframe::get_frame_by_number(j)){
		    msgerr_print("Math: frame #%d does not exist", j);
		    return NULL;
		}
		pl = appendIntParm(pl, j);
	    }
	}else if (*p == '('){
	    pl = parse_frame_spec(p, pl);
	    if (ppp=strchr(p, ')')){
		p = ppp;
	    }else{
		p += strlen(p);
	    }
	}else if (sscanf(p,"%d",&j) == 1){
	    p += strspn(p, "0123456789");
	    if (!Gframe::get_frame_by_number(j)){
		msgerr_print("Math: frame #%d does not exist", j);
		return NULL;
	    }
	    pl = appendIntParm(pl, j);
	}
	/* Consolidate string--replacing image spec with "#" */
	ppp = pp;
	while (*pp++ = *p++);
	*cmd = ppp;

	if (countParm(pl) == 0){
	    freeParms(pl);
	    pl = 0;
	}
	/*printParm(pl);/*CMP*/
    }
    return pl;
}