/* This function moves the IFS image associated with the right label into the left label so that further processing can be carried out on it. */ void IFSOperationViewer::swap() { if(rightImageLabel->ifsImage == NULL) { return; } //Allocate a buffer to put the image in IFSHDR *buffer = create2DFloatImage(ifsdimen(rightImageLabel->ifsImage, 0), ifsdimen(rightImageLabel->ifsImage, 1)); if(buffer == NULL) { //Image allocation failed fprintf(stderr, "There was a failure when allocating space for the swap operation\n"); return; } //Copy the image into the buffer if(flcp(rightImageLabel->ifsImage, buffer) != 1) { fprintf(stderr, "Error copying the swap image into a buffer\n"); ifsfree(buffer, IFS_FR_ALL); return; } //Put the image in the left label leftImageLabel->setIFSImage(buffer); }
/** handle one line of the read command. * more fields than variables -> remainder shall be part of last variable. * less fields than variables -> remaining variables unset. * * @param line complete line of input * @param ap argument (variable) list * @param len length of line including trailing '\0' */ static void readcmd_handle_line(char *s, char **ap) { struct arglist arglist; struct strlist *sl; char *backup; char *line; /* ifsbreakup will fiddle with stack region... */ line = stackblock(); s = grabstackstr(s); /* need a copy, so that delimiters aren't lost * in case there are more fields than variables */ backup = sstrdup(line); arglist.lastp = &arglist.list; ifsbreakup(s, &arglist); *arglist.lastp = NULL; ifsfree(); sl = arglist.list; do { if (!sl) { /* nullify remaining arguments */ do { setvar(*ap, nullstr, 0); } while (*++ap); return; } /* remaining fields present, but no variables left. */ if (!ap[1] && sl->next) { size_t offset; char *remainder; /* FIXME little bit hacky, assuming that ifsbreakup * will not modify the length of the string */ offset = sl->text - s; remainder = backup + offset; rmescapes(remainder); setvar(*ap, remainder, 0); return; } /* set variable to field */ rmescapes(sl->text); setvar(*ap, sl->text, 0); sl = sl->next; } while (*++ap); }
void expandarg(shinstance *psh, union node *arg, struct arglist *arglist, int flag) { struct strlist *sp; char *p; psh->argbackq = arg->narg.backquote; STARTSTACKSTR(psh, psh->expdest); psh->ifsfirst.next = NULL; psh->ifslastp = NULL; argstr(psh, arg->narg.text, flag); if (arglist == NULL) { return; /* here document expanded */ } STPUTC(psh, '\0', psh->expdest); p = grabstackstr(psh, psh->expdest); TRACE2((psh, "expandarg: p='%s'\n", p)); psh->exparg.lastp = &psh->exparg.list; /* * TODO - EXP_REDIR */ if (flag & EXP_FULL) { ifsbreakup(psh, p, &psh->exparg); *psh->exparg.lastp = NULL; psh->exparg.lastp = &psh->exparg.list; expandmeta(psh, psh->exparg.list, flag); } else { if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ rmescapes(psh, p); sp = (struct strlist *)stalloc(psh, sizeof (struct strlist)); sp->text = p; *psh->exparg.lastp = sp; psh->exparg.lastp = &sp->next; } ifsfree(psh); *psh->exparg.lastp = NULL; if (psh->exparg.list) { *arglist->lastp = psh->exparg.list; arglist->lastp = psh->exparg.lastp; } }
void expandarg(union node *arg, struct arglist *arglist, int flag) { struct strlist *sp; char *p; argbackq = arg->narg.backquote; STARTSTACKSTR(expdest); ifsfirst.next = NULL; ifslastp = NULL; argstr(arg->narg.text, flag); if (arglist == NULL) { return; /* here document expanded */ } STPUTC('\0', expdest); p = grabstackstr(expdest); exparg.lastp = &exparg.list; /* * TODO - EXP_REDIR */ if (flag & EXP_FULL) { ifsbreakup(p, &exparg); *exparg.lastp = NULL; exparg.lastp = &exparg.list; expandmeta(exparg.list, flag); } else { if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ rmescapes(p); sp = (struct strlist *)stalloc(sizeof (struct strlist)); sp->text = p; *exparg.lastp = sp; exparg.lastp = &sp->next; } ifsfree(); *exparg.lastp = NULL; if (exparg.list) { *arglist->lastp = exparg.list; arglist->lastp = exparg.lastp; } }
/* This function (normally activated by the Apply button) attempts to apply the selected IFS function to the image in the left label and store the result in the right label. */ void IFSOperationViewer::applyOperation() { if(leftImageLabel->ifsImage == NULL) { return; } //If any of the parameter widgets are empty, set them to 0.0 for(int i=0; i<parameterLineEdits.size(); i++) { if(parameterLineEdits[i]->text() == QString("")) { parameterLineEdits[i]->setText("0.0"); } } //Get the parameters std::vector<float> parameters; for(int i=0; i<parameterLineEdits.size(); i++) { bool isOkay=false; parameters.push_back(parameterLineEdits[i]->text().toFloat(&isOkay)); if(!isOkay) { fprintf(stderr, "One of the function parameters was non-numeric\n"); return; } } std::string functionName = std::string(operationListBox->currentItem()->text().toAscii().constData()); //Allocate buffer space for the operation IFSHDR *buffer = create2DFloatImage(ifsdimen(leftImageLabel->ifsImage, 0), ifsdimen(leftImageLabel->ifsImage, 1)); if(buffer == NULL) { //Image allocation failed fprintf(stderr, "There was a failure when allocating space for the result of the operation\n"); return; } //Do the appropriate function given the current text value /* if(functionName == "flabsolute") { if(flabsolute(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else*/ if(functionName == "fladds") { if(fladds(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flclip") { if(flclip(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flcp") { if(flcp(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldivs") { if(fldivs(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flexp") { if(flexp(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flln") { if(flln(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flmults") { if(flmults(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flneg") { if(flneg(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flrec") { if(flrec(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flsq") { if(flsq(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flsqrt") { if(flsqrt(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flsubs") { if(flsubs(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flthresh") { if(flthresh(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flone_border") { if(flone_border(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flpad") { if(flpad(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flplanar") { if(flplanar(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flshx") { if(flshx(leftImageLabel->ifsImage, parameters[0], buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flshxy") { if(flshxy(leftImageLabel->ifsImage, parameters[0], parameters[1], buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flshy") { if(flshy(leftImageLabel->ifsImage, parameters[0], buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flzero_border") { if(flzero_border(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flDoG") { if(flDoG(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1], parameters[2]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "flGabor") { if(flGabor(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldx") { if(fldx(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldx_back") { if(fldx_back(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldx_forw") { if(fldx_forw(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldxx") { if(fldxx(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldxy") { if(fldxy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldy") { if(fldy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldy_back") { if(fldy_back(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldy_forw") { if(fldy_forw(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else if(functionName == "fldyy") { if(fldyy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue) { fprintf(stderr, "%s returned an error\n", functionName.c_str()); ifsfree(buffer, IFS_FR_ALL); return; } } else { fprintf(stderr, "Error, function operation %s not found\n", functionName.c_str()); } rightImageLabel->setIFSImage(buffer); }