⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image_alloc.c

📁 LastWave
💻 C
📖 第 1 页 / 共 3 页
字号:
  char **pStr;    FSI_DECL_ROW;  FSI_DECL_COL;  BorderType bt;  SIGNAL sigResult;  IMAGE imResult;  LWFLOAT xmax,xmin,ymax,ymin;  ExtractInfo *ei;  int n;  int nx1,ny1;  field = ARG_G_GetField(arg);  fsiList = ARG_G_GetFsiList(arg);  pFlt = ARG_G_GetResPFloat(arg);  pStr = ARG_G_GetResPStr(arg);  if (fsiList == NULL) Errorf("GetExtractImageV() : Weird error");  /* Get extractInfo */  ei = fsiList->ei;  xmax = ei->xmax;  xmin = ei->xmin;  ymax = ei->ymax;  ymin = ei->ymin;  if (fsiList->options & FSIOptImBPer) bt = BorderPer;  else if (fsiList->options & FSIOptImBMir) bt = BorderMir;  else if (fsiList->options & FSIOptImBMir1) bt = BorderMir1;  else if (fsiList->options & FSIOptImB0) bt = Border0;  else bt = BorderNone;   /* Case of flagImage im[<;>] */  if (fsiList->flagImage) {    sigResult = TNewSignal();    SizeSignal(sigResult,fsiList->nx,YSIG);    sigResult->size = 0;    FSI_FOR_INIT(fsiList);    fsic = &(fsiList->fsi[_ns+1]);    FSI_FOR_START_ROW(fsiList);     _fc = FSIArray(fsic,_kr1);    if (fsiList->options & FSIOptImNoLimit) {      if (_fr<0 || _fr >= im->nrow) continue;      if (_fc<0 || _fc >= im->ncol) continue;    }    sigResult->Y[sigResult->size++] = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);    FSI_FOR_END_ROW;    ARG_G_SetResValue(arg,sigResult);    return(signaliType);  }  if (bt == BorderNone) {nx1 = fsiList->nx1; ny1 = fsiList->ny1;}  else {nx1 = fsiList->nx; ny1 = fsiList->ny;}    /* case of an empty extraction */  if (nx1 == 0 || ny1 == 0) {    ARG_G_SetResValue(arg,TNewImage());    return(imageType);  }      /*   * Case the result will be a simple LWFLOAT   */  if (nx1 == 1 && ny1 == 1) {    FSI_FOR_INIT(fsiList);        if (fsiList->options & FSIOptImNoLimit) {      FSI_FOR_START_ROW(fsiList);       if (_fr<xmin || _fr > xmax) continue;      else break;      FSI_FOR_END_ROW;      FSI_FOR_START_COL(fsiList);       if (_fc<ymin || _fc > ymax) continue;      else break;      FSI_FOR_END_COL;    }    else  {      _fr =  FSIArray((&(fsiList->fsi[0])),0);      _fc =  FSIArray((&(fsiList->fsi[_ns+1])),0);    }    *pFlt = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);    return(numType);  }    /*   * Case the result will be a signal   */  if (nx1 == 1) {    FSI_FOR_INIT(fsiList);        if (fsiList->options & FSIOptImNoLimit) {      FSI_FOR_START_ROW(fsiList);       if (_fr<xmin || _fr > xmax) continue;      else break;      FSI_FOR_END_ROW;      sigResult = TNewSignal();      SizeSignal(sigResult,ny1,YSIG);      n = 0;      FSI_FOR_START_COL(fsiList);       if (_fc<ymin || _fc > ymax) continue;      else sigResult->Y[n] = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);      n++;      FSI_FOR_END_COL;    }    else  {      _fr =  FSIArray((&(fsiList->fsi[0])),0);      sigResult = TNewSignal();      SizeSignal(sigResult,ny1,YSIG);      n = 0;      FSI_FOR_START_COL(fsiList);       sigResult->Y[n] = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);      n++;      FSI_FOR_END_COL;    }    ARG_G_SetResValue(arg,sigResult);    return(signaliType);  }  /*   * Case the result will be an image   */  FSI_FOR_INIT(fsiList);      if (fsiList->options & FSIOptImNoLimit) {    imResult = TNewImage();    SizeImage(imResult,ny1,nx1);    n = 0;    FSI_FOR_START_ROW(fsiList);     if (_fr<xmin || _fr > xmax) continue;    FSI_FOR_START_COL(fsiList);     if (_fc<ymin || _fc > ymax) continue;    imResult->pixels[n] = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);    n++;    FSI_FOR_END_COL;    FSI_FOR_END_ROW;  }  else  {    imResult = TNewImage();    SizeImage(imResult,ny1,nx1);    n = 0;    FSI_FOR_START_ROW(fsiList);     FSI_FOR_START_COL(fsiList);     imResult->pixels[n] = CR2PixIm(im,(int) _fr,(int) _fc,bt,bt);    n++;    FSI_FOR_END_COL;    FSI_FOR_END_ROW;  }  ARG_G_SetResValue(arg,imResult);  return(imageiType);  }void *GetImageExtractField(IMAGE im, void **arg){  char *field = ARG_G_GetField(arg);  void *res;    ARG_G_SetField(arg,NULL);    res = GetImageField_(im, arg);    ARG_G_SetField(arg,field);  return(res);}  static void *GetExtractImageV(VALUE value, void **arg){  char *field = ARG_G_GetField(arg);  /* doc */  if (value == NULL) return(doc);    return(GetImageField_((IMAGE) value, arg));}/* * Function to get the ExtractInfo for field NULL */static void *GetExtractInfoImageV(VALUE value, void **arg){  static ExtractInfo extractInfo;  static char flagInit = YES;    IMAGE im = (IMAGE) value;  char *field = (char *) ARG_EI_GetField(arg);  unsigned long *options = ARG_EI_GetPOptions(arg);  if (im->nrow == 0 || im->ncol == 0) {    SetErrorf("No extraction on empty image");    return(NULL);  }  /* If *bperiodic,... then *nolimit must be off */  if (*options & (FSIOptImBPer | FSIOptImBMir | FSIOptImBMir1 | FSIOptImB0)) *options &= ~FSIOptImNoLimit;        /* Init of the extraction info */  if (flagInit) {    extractInfo.nSignals = 2;    flagInit = NO;  }    extractInfo.xmax = im->nrow-1;  extractInfo.dx = 1;  extractInfo.xmin = 0;  extractInfo.ymax = im->ncol-1;  extractInfo.dy = 1;  extractInfo.ymin = 0;        /* '*nolimit' option : set some flags */  extractInfo.flags = EIIntIndex;  if (!(*options & (FSIOptImNoLimit | FSIOptImBPer | FSIOptImBMir | FSIOptImBMir1 | FSIOptImB0))) extractInfo.flags |= EIErrorBound;        return(&extractInfo);}/* * Get the options for extraction (called for field NULL only) */static char *optionDoc = "{{*nolimit,*b0,*bconst,*bmirror,*bmirror1,*bperiodic} \{*nolimit : indexes can be out of range} \{*b0 : border effect with 0 value} \{*bperiodic : periodic border effect)} \{*bmirror1 : mirror+periodic border effect (first and last points are repeated)} \{*bmirror : mirror+periodic border effect (first and last points are NOT repeated)}\}";static void *GetExtractOptionsImageV(VALUE value, void **arg){  IMAGE im;  char *field;     /* doc */  if (value == NULL) {return(optionDoc);}  im = (IMAGE) value;  field = (char *) ARG_EO_GetField(arg);  if (field != NULL) return(NULL);  return(extractOptionsIm);}/* * 'ncol' field */static char *ncolDoc = "{[= <ncol>]} {Sets/Gets the number of columns of an image. If allocation is changed then all the values are initialized to 0.}";static void * GetNcolImageV(VALUE value, void **arg){  /* Documentation */  if (value == NULL) return(ncolDoc);    return(GetIntField(((IMAGE) value)->ncol,arg));}static void * SetNcolImageV(VALUE value, void **arg){ IMAGE im = (IMAGE) value; int size;   /* doc */ if (value == NULL) return(ncolDoc); size = im->ncol; if (SetIntField(&size,arg,FieldPositive)==NULL) return(NULL); SizeImage(im,size,im->nrow); return(numType);}/* * 'nrow' field */static char *nrowDoc = "{[= <nrow>]} {Sets/Gets the number of rows of an image. If allocation is changed then all the values are initialized to 0.}";static void * GetNrowImageV(VALUE value, void **arg){  /* Documentation */  if (value == NULL) return(nrowDoc);    return(GetIntField(((IMAGE) value)->nrow,arg));}static void * SetNrowImageV(VALUE value, void **arg){ IMAGE im = (IMAGE) value; int size;   /* doc */ if (value == NULL) return(nrowDoc); size = im->nrow; if (SetIntField(&size,arg,FieldPositive)==NULL) return(NULL); SizeImage(im,im->ncol,size); return(numType);}/* * 'name' field */static char *nameDoc = "{[= <name>]} {Sets/Gets the name of an image}";static void * GetNameImageV(VALUE value, void **arg){  /* Documentation */  if (value == NULL) return(nameDoc);    return(GetStrField(((IMAGE) value)->name,arg));}/* Set the name of an image */int SetNameImage(IMAGE im, char *name){  if (im->name != defaultName && im->name != NULL) {    Free(im->name);    im->name = NULL;  }  if (name == NULL) im->name = defaultName;  else im->name = CopyStr(name);  return(1);}static void * SetNameImageV(VALUE value, void **arg){  IMAGE im = (IMAGE) value;       /* doc */  if (value == NULL) return(nameDoc);  if (im->name==defaultName) {    im->name=CharAlloc(1);    im->name[0] = '\0';  }  return(SetStrField(&(im->name),arg));}/* * 'tosignal' field */static char *tosignalDoc = "{} {Converts the image to a signal (it just puts the rows one after the other)}";static void * GetSignalImageV(IMAGE im, void **arg){  SIGNAL sig;    if (im == NULL) return(tosignalDoc);  sig = TNewSignal();  SizeSignal(sig,im->nrow*im->ncol,YSIG);  memcpy(sig->Y,im->pixels,sizeof(LWFLOAT)*sig->size);    return(GetValueField(sig,arg));}/* * The field list */struct field fieldsImage[] = {  "", GetExtractImageV, SetExtractImageV, GetExtractOptionsImageV, GetExtractInfoImageV,  "ncol", GetNcolImageV, SetNcolImageV, NULL, NULL,  "nrow", GetNrowImageV, SetNrowImageV, NULL, NULL,  "name", GetNameImageV, SetNameImageV, NULL, NULL,  "tosignal", GetSignalImageV, NULL, NULL, NULL,  NULL, NULL, NULL, NULL, NULL};/* * The type structure for IMAGE */TypeStruct tsImage = {  "{{{&image} {This type is the basic type for images/matrices. Images \can be built using the <value11,...,value1M;value21,...,value2M;...;valueN1,...,valueNM> syntax. \The values can be either a LWFLOAT, a signal, a range, or an image, \signals, ranges and images. The different operators are \n \- +,-,*,/ (and +=,-=,*=,/=) : regular operators \n \- //,% : integer division and remainder \n \- ==,!=,<=,>=,<,> : regular tests \n \- x^f (and ^=) : each value of |x| is taken to the popwer f \n \- x*^n : each value of x to the power n where n is a positive integer \n\- ~ : transposition operator \n\- ** : matrix multiplication \n\- x^^n : take the square matrix m to the power n where n is an integer \n\- is,isnot : test if 2 signals correspond or not to the same C object \n \- sinh,sin,cosh,cos,tanh,tan,acos,asin,atan : trigonometric operators \n \- min,max : if 1 argument, returns the min or max value of an image, if 2 arguments returns \the image made of the min/max of each value. \n\- log2,log,ln,sqrt,abs,exp,ceil,floor,round,frac,int : other math functions \n \- sum : computes the sum of all image values \n \- mean : same as sum but divides by the total number of points\n \- any : returns 1 if at least one of the values is different from 0\n \- all : returns 1 if all of the values are different from 0\n \- find : returns a 2xN image made of index couples corresponding to non 0 values \n\- Image Constructors : <...;...;...>,Id,Zero,One,I,J,Grand,Urand and diag (for building diagonal matrices from a range/signal).}} \{{&imagei} {This type corresponds to non empty images.}}}",  /* Documentation */  &imageType,       /* The basic (unique) type name */  GetTypeImage,     /* The GetType function */                           DeleteImage,     /* The Delete function */  NewImage,     /* The New function */    CopyImage,       /* The copy function */  ClearImage,       /* The clear function */    ToStrImage,       /* String conversion */  PrintImage,   /* The Print function : print the object when 'print' is called */  PrintInfoImage,   /* The PrintInfo function : called by 'info' */  NULL,              /* The NumExtract function : used to deal with syntax like 10a */     fieldsImage,      /* The list of fields */};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -