📄 int_fsilist.c
字号:
*left = begin1; SetErrorf("Row with an exceeding number of columns %d (>%d)",ncolCur,ncol); break; } } list->fsi[j].val.i = i; list->fsi[j].array = i->pixels; list->fsi[j].size = i->nrow*i->ncol; i = NULL; val = NULL; j++; list->size++; } /* Case of a float */ else { if (nhblock == 1) {nrowCur = 1; nrow += nrowCur;} else if (nrowCur != 1) { /* a float is on the same row as an image */ flagError = YES; *left = begin1; SetErrorf("Expect an image with %d rows (not a float !)",nrowCur); break; } if (nvblock == 1) ncol ++; else { ncolCur ++; if (!flagExtract && ncolCur > ncol) { /* One row has too many columns */ flagError = YES; *left = begin1; SetErrorf("Row with an exceeding number of columns %d (>%d)",ncolCur,ncol); break; } } if (flagExtract) { if (min > max) (*nValid)++; else { nVal = ValidIndexBound(f); if (nVal == -1) { flagError=YES; break; } *nValid += nVal; } if (ei->flags & EIIntIndex) { if (ValidIndexInt(f) == -1) { flagError= YES; break; } } } list->fsi[j].val.f = f; list->fsi[j].array = &(list->fsi[j].val.f); list->fsi[j].size = 1; j++; list->size++; } jumpEmptyListv : /* Skip spaces */ if (!lv) { begin = *left; ParamSkipSpace(begin); } /* another column with a ',' */ if (*begin == ',') { nhblock++; begin++; ParamSkipSpace(begin); continue; }; /* another column with a listv */ if (lv) { nhblock++; continue; }; /* another row */ if (*begin == FSISEPARATOR) { if (ei && ei->nSignals == 1) { SetErrorf("Expecting only one row of indexes"); flagError = YES; break; } if (flagExtract) { min = ei->ymin; dy = ei->dy; max = ei->ymax; nValid = &(list->ny1); *nValid = 0; RestoreDefaultVector(defParam); if (min <= max) { SaveDefaultVector(defParam); SetDefaultVector(defParam,min,dy,max,NULL,YES); } } list->fsi[j].type = FSISeparator; list->size++; list->nSep++; if (jsep == -1) jsep = j; j++; begin++; ParamSkipSpace(begin); if (!flagExtract && nvblock > 1 && ncolCur != ncol) { flagError = YES; *left = begin1; SetErrorf("Row with a wrong number of columns %d (should be %d)",ncolCur,ncol); break; } if (row1NCol == -1) row1NCol = ncol; nhblock = 1; nvblock++; ncolCur = 0; nrowCur = 0; continue; } break; } if (flagExtract) { RestoreDefaultVector(defParam); } /* If we expected 2 signals and we get an image with 2 rows, it's ok ! */ if (!flagError && ei && ei->nSignals != list->nSep+1) { if (list->size != 1 || list->fsi[0].type != FSIImage || list->fsi[0].val.i->nrow != 2) { SetErrorf("Expecting %d rows of indexes",ei->nSignals); flagError = YES; } else { i = list->fsi[0].val.i; if (ei->flags & (EIErrorBound | EIIntIndex)) { for (j=0;j<2*i->ncol;j++) { if (ei->flags & EIIntIndex && i->pixels[j] != (int) i->pixels[j]) { SetErrorf("Expecting integer indexes"); flagError = YES; break; } if (ei->flags & EIErrorBound && (j<i->ncol && (i->pixels[j]<ei->xmin || i->pixels[j]>ei->xmax) || j>=i->ncol && (i->pixels[j]<ei->ymin || i->pixels[j]>ei->ymax))) { SetErrorf("Indexes are out of range"); flagError = YES; break; } } } if (!flagError) { list->size = 3; list->fsi[0].type = FSISignal; list->fsi[0].val.s = NULL; list->fsi[0].array = i->pixels; list->fsi[0].size = i->ncol; list->fsi[1].type = FSISeparator; list->fsi[1].array = NULL; list->fsi[2].type = FSISignal; list->fsi[2].val.s = NULL; list->fsi[2].array = i->pixels+i->ncol; list->fsi[2].size = i->ncol; ncolCur = ncol = i->ncol; list->flagImage = YES; } } } /* A test (the end of a list is like a new separator) */ if (!flagExtract && nvblock > 1 && ncolCur != ncol) { flagError = YES; *left = begin1; SetErrorf("Row with a wrong number of columns %d (should be %d)",ncolCur,ncol); } /* Set the number of columns of the second row */ if (flagExtract) { row1NCol = ncol; row2NCol = ncolCur; } /* Set the nx,ny fields */ if (flagExtract) { list->nx = row1NCol; list->ny = row2NCol; } else { list->nx = ncol; list->ny = nrow; } /* Error */ if (flagError) { DeleteFSIList(list); Clean(val); return(NULL); } ParamSkipSpace(*left); list->ei = ei; return(list);}/* * Convert a size 1 signal, range or image to a float and returns YES or NO if went well or not */#define Convert2Float(elem,fl) \ ((elem).type == FSIFloat ? ((fl) = (elem).val.f, YES) : \ (((elem).type == FSISignal && (elem).val.s->size == 1) ? ((fl) = (elem).val.s->Y[0], YES) : \ (((elem).type == FSIRange && (elem).val.r->size == 1) ? ((fl) = (elem).val.r->first, YES) : \ (((elem).type == FSIImage && (elem).val.i->nrow == 1 && (elem).val.i->ncol == 1) ? ((fl) = (elem).val.i->pixels[0], YES) : NO))))/* * Expansion of a list of content into a signal, an image or a float */unsigned char ExpandFSIList(FSIList *list, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType) { int nrow, ncol,nrow1,ncol1,nrow2,k,l,k1,k2,n; SIGNAL s,s1; IMAGE i,i1; unsigned char answer; RANGE rg; int ii; if (list->nx == 0) { *resVC = (VALUE) TNewSignal(); DeleteFSIList(list); return(SignalType); } nrow = list->ny; ncol = list->nx; /* Error */ if (nrow>1 && !(flagType&ImageType)) { SetErrorf("Do not expect an image"); DeleteFSIList(list); return(NO); } if (nrow==1 && ncol>1 && flagType==FloatType) { SetErrorf("Expect a float"); DeleteFSIList(list); return(NO); } /********************************************* * * Case of a single row * *********************************************/ if (nrow == 1) { /* Case we can return a float */ if (ncol == 1) { ii = 0; while (list->fsi[ii].size == 0) ii++; if (Convert2Float(list->fsi[ii],*resFlt)==NO) Errorf("ExpandFSIList() : Weird"); Clean(*resVC); DeleteFSIList(list); return(FloatType); } /* Case of a single signal or range */ else if (list->size==1 && (list->fsi[0].type == FSISignal || list->fsi[0].type == FSIRange)) { if (list->fsi[0].val.s->nRef == 1 && list->fsi[0].type != FSIRange) { Clean(*resVC); *resVC = (VALUE) list->fsi[0].val.s; } else { if (list->fsi[0].type == FSIRange) { Clean(*resVC); *resVC = (VALUE) TNewSignal(); SizeSignal((SIGNAL) *resVC,list->fsi[0].val.r->size,YSIG); for (k=0;k<list->fsi[0].val.r->size;k++) { ((SIGNAL) *resVC)->Y[k] = RangeVal(list->fsi[0].val.r,k); } } else { if (*resVC == NULL || GetTypeValue(*resVC) != signaliType) { Clean(*resVC); *resVC = (VALUE) TNewSignal(); } CopySig(list->fsi[0].val.s,(SIGNAL) *resVC); } } DeleteFSIList(list); return(SignalType); } /* Case of more than one signal/range or of single rowed images */ /* allocation */ if (*resVC == NULL || GetTypeValue(*resVC) != signaliType) { Clean(*resVC); *resVC = (VALUE) TNewSignal(); } s = (SIGNAL) *resVC; SizeSignal(s,ncol,YSIG); k = 0; /* Set the x0/dx if necessary */ if (list->fsi[0].type == FSISignal && list->fsi[0].val.s->type == YSIG) { s->x0 = list->fsi[0].val.s->x0; s->dx = list->fsi[0].val.s->dx; } for (n=0;n<list->size;n++) { /* case 0 */ if (list->fsi[n].type == FSISeparator) Errorf("ExpandFSIList() : Weird 4"); /* case FloatType */ else if (list->fsi[n].type == FSIFloat) { s->Y[k] = list->fsi[n].val.f; k++; } /* case SignalType */ else if (list->fsi[n].type == FSISignal) { s1 = list->fsi[n].val.s; memcpy(s->Y+k,s1->Y,s1->size*sizeof(LWFLOAT));k+= s1->size; } /* case RangeType */ else if (list->fsi[n].type == FSIRange) { rg = list->fsi[n].val.r; for (k1 = 0;k1<rg->size;k1++,k++) s->Y[k] = RangeVal(rg,k1); } /* case ImageType */ else if (list->fsi[n].type == FSIImage) { i1 = list->fsi[n].val.i; memcpy(s->Y+k,i1->pixels,i1->ncol*sizeof(LWFLOAT));k+= i1->ncol; } else Errorf("ExpandFSIList() : weird"); } answer = SignalType; } /********************************************* * * Case of a several rows * *********************************************/ else { /* Case of a single image */ if (list->size==1 && list->fsi[0].type == FSIImage) { if (list->fsi[0].val.i->nRef == 1) { Clean(*resVC); *resVC = (VALUE) list->fsi[0].val.i; } else { if (*resVC == NULL || GetTypeValue(*resVC) != imageiType) { Clean(*resVC); *resVC = (VALUE) TNewImage(); } CopyImage(list->fsi[0].val.i,(IMAGE) *resVC); } DeleteFSIList(list); return(ImageType); } /* Case of more than one image */ /* allocation */ if (*resVC == NULL || GetTypeValue(*resVC) != imageiType) { Clean(*resVC); *resVC = (VALUE) TNewImage(); } i = (IMAGE) *resVC; SizeImage(i,ncol,nrow); k = 0; nrow1 = ncol1 = 0; for (n=0;n<list->size;n++) { /* case 0 */ if (list->fsi[n].type == FSISeparator) {nrow1+= nrow2; ncol1 = 0;} /* case FloatType */ else if (list->fsi[n].type == FSIFloat) { i->pixels[k] = list->fsi[n].val.f; k++; ncol1++; nrow2 = 1; } /* case SignalType */ else if (list->fsi[n].type == FSISignal) { s1 = list->fsi[n].val.s; memcpy(i->pixels+k,s1->Y,s1->size*sizeof(LWFLOAT));k+= s1->size; ncol1+= s1->size; nrow2 = 1; } /* case RangeType */ else if (list->fsi[n].type == FSIRange) { rg = list->fsi[n].val.r; for (k1 = 0;k1<rg->size;k1++,k++) i->pixels[k] = RangeVal(rg,k1); ncol1+= rg->size; nrow2 = 1; } /* case ImageType */ else if (list->fsi[n].type == FSIImage) { i1 = list->fsi[n].val.i; l = 0; for (k2 = nrow1;k2<nrow1+i1->nrow;k2++) { for (k1 = ncol1;k1<ncol1+i1->ncol;k1++) { i->pixels[k] = i1->pixels[l]; k++; l++; } } ncol1 += i1->ncol; nrow2 = i1->nrow; } else Errorf("ExpandFSIList() : weird"); } answer = ImageType; } /* Desallocation */ DeleteFSIList(list); return(answer);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -