/************************************************************************ * * * 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; }
int setPtrParms(ParmList p, void **array, int n) { int rtn = 0; int ok = 1; int i; for (i=0; ok && i<n; i++){ if ( (ok=setPtrParm(p, array[i], i)) ) { rtn++; } } return rtn; }
ParmList appendPtrParm(ParmList p, void *value) { ParmList rtn = NULL; int n; if (p[PL_TYPEOFFSET].ival == PL_PTR){ n = countParm(p); rtn = (ParmList)realloc(p, (n+1+PL_DATAOFFSET)*sizeof(ParmItem)); if (rtn){ rtn[PL_SIZEOFFSET].ival = n+1; setPtrParm(rtn, value, n); } } return rtn; }
int mathexpr(ParmList inparms, ParmList *outparms) { float x, y, z; /* User variables */ float r[100]; /* Many user variables */ int ii, jj, kk; /* Integer user variables */ int n[100]; /* Many integer user variables */ int i, j, k; /* Pixel position in row, column, depth */ int width, height, depth; /* Size of all images */ int indx; /* Running pixel number */ char msg[128]; DDLSymbolTable *st; DDLSymbolTable *out; float **img; /* Vector of pointers to input data */ float *iout; /* Pointer to output data */ int nsrcs; /* Number of input images */ ParmList src_ddls; ParmList dst_ddls; /*fprintf(stderr,"mathexpr(0x%x, 0x%x)\n", inparms, outparms);/*CMP*/ /*printParm(inparms);/*CMP*/ /* Grab the input args */ src_ddls = findParm(inparms, "src_ddls"); if (!src_ddls){ ib_errmsg("MATH: \"src_ddls\" not passed"); return FALSE; } nsrcs = countParm(src_ddls); img = (float **)malloc(nsrcs * sizeof(float *)); fdfhandle = (DDLSymbolTable **)malloc(nsrcs * sizeof(DDLSymbolTable *)); if (!img || !fdfhandle){ ib_errmsg("MATH: out of memory"); return FALSE; } /* Check image sizes */ width = height = depth = 0; for (indx=0; indx<nsrcs; indx++){ getPtrParm(src_ddls, &st, indx); i = get_image_width(st); j = get_image_height(st); k = get_image_depth(st); if (!i || !j){ sprintf(msg,"MATH: image size is %dx%d\n", i, j); ib_errmsg(msg); return FALSE; } if ((width && i != width) || (height && j != height) || (depth && k != depth)) { ib_errmsg("MATH: images are different sizes\n"); return FALSE; } width = i; height = j; depth = k; /* Point the working source image pointers to the appropriate data */ img[indx] = get_ddl_data(st); fdfhandle[indx] = st; } /*fprintf(stderr,"MATH: width=%d, height=%d, depth=%d\n", width, height, depth);/*DBG*/ /* Copy the first input object (for storing the output image) */ getPtrParm(src_ddls, &st, 0); out = clone_ddl(st, 1); /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n", get_image_width(out), get_ddl_data(out), *get_ddl_data(out));/*CMP*/ /*fprintf(stderr,"indata=0x%x, *indata=%g\n", img[0], img[0][0]);/*CMP*/ iout = get_ddl_data(out); /* * NOTE: IB_EXPRESSION will be expanded into something like * img[0][indx]+img[1][indx] */ interrupt_begin(); for (indx=k=0; k<depth; k++){ for (j=0; j<height; j++){ for (i=0; i<width && !interrupt(); i++, indx++){ iout[indx] = IB_EXPRESSION; } } } interrupt_end(); /*fprintf(stderr,"MATH: out width=%d, data=0x%x, *data=%g\n", get_image_width(out), get_ddl_data(out), *get_ddl_data(out));/*CMP*/ /* Pass back the output image */ *outparms = allocParm("dst_ddls", PL_PTR, 1); setPtrParm(*outparms, out, 0); return TRUE; }