📄 dwtrans2_alloc.c
字号:
/*..........................................................................*//* *//* L a s t W a v e P a c k a g e 'dwtrans2d' 2.1 *//* *//* Copyright (C) 1998-2002 E.Bacry, J.Fraleu, J.Kalifa, E. Le Pennec, *//* W.L. Hwang , S.Mallat, S.Zhong *//* emails : lastwave@cmap.polytechnique.fr *//* fraleu@cmap.polytechnique.fr *//* kalifa@cmap.polytechnique.fr *//* lepennec@cmap.polytechnique.fr *//* mallat@cmap.polytechnique.fr *//* whwang@iis.sinica.edu.tw *//* szhong@chelsea.princeton.edu *//* *//*..........................................................................*//* *//* This program is a free software, you can redistribute it and/or *//* modify it under the terms of the GNU General Public License as *//* published by the Free Software Foundation; either version 2 of the *//* License, or (at your option) any later version *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//****************************************************************************//* *//* wtrans_alloc.c Functions which deal with the memory allocation *//* of WTRANSFORM structure *//* *//****************************************************************************/#include "lastwave.h"#include "int_fsilist.h"#include "extrema2d.h"char *dwtrans2Type = "&dwtrans2";static char defaultName[] = ""; /* * Answers to the different print messages */ void PrintWtrans2(WTRANS2 wtrans){ if (wtrans->name == NULL) Printf("<&dwtrans2[%d];%p>\n",wtrans->noct,wtrans); else Printf("<'%s';&dwtrans2[%d];%p>\n",wtrans->name,wtrans->noct,wtrans);}char *ToStrWtrans2(WTRANS2 wtrans, char flagShort){ static char str[30]; if (wtrans->name == defaultName) { sprintf(str,"<&dwtrans2;%p>",wtrans); } else { sprintf(str,"<&dwtrans2;%s>",wtrans->name); } return(str);}void PrintInfoWtrans2(WTRANS2 wtrans){ Printf(" number of octave : %2d\n",wtrans->noct); if (wtrans->wName != NULL) Printf(" Wavelet name : %s\n",wtrans->wName); }/* * NumExtraction * * (10a, 20, 31,...) */static IMAGE Extract(WTRANS2 wtrans,int o, int v){ if (o < 0 || o >= W2_MAX_LEVEL) { SetErrorf("Octave index '%d' out of range : should be in [0,%d]",o,W2_MAX_LEVEL); return(NULL); } if (v < 0 || v >= W2_MAX_ORIENTATION) { SetErrorf("Octave index '%d' out of range : should be in [0,%d]",o,W2_MAX_ORIENTATION); return(NULL); } return(wtrans->images[o][v]);}static char *numdoc = "The syntax <i><j> refers to the image [i,j] of the dwtrans2 structure. The image [0,痌 corresponds to the analyzed image. \The projection on the V_oct spaces are stored in [oct,0]. [oct,1] corresponds to the vertical details at octave oct \and [oct,2] corresponds to the horizontal details at octave oct. [oct,3] corresponds to the norm of ([oct,1],[oct,2]) and \[oct,4] to its phase. All the other images are not used by the wavelet transform and can be used as working images.}";static void *NumExtractWtrans2(WTRANS2 wtrans,void **arg){ VALUE value; int n; char flagDot; int v; int o; /* doc */ if (wtrans == NULL) return(numdoc); n = ARG_NE_GetN(arg); flagDot = ARG_NE_GetFlagDot(arg); v = n%10; o = n/10; if (flagDot == YES) { SetErrorf("No '.' allowed in this syntax"); return(NULL); } value = (VALUE) Extract(wtrans,o,v); if (value == NULL) return(NULL); ARG_NE_SetResValue(arg,value); return(imageiType);}/* * Get the options for extraction : There is none !! */static void *GetExtractOptionsWtrans2V(WTRANS2 wtrans, void **arg){ static char *extractOptionsWtrans2[] = {NULL}; return(extractOptionsWtrans2);}/* * Function to get the ExtractInfo */static void *GetExtractInfoWtrans2V(WTRANS2 wtrans, void **arg){ char *field = ARG_EI_GetField(arg); unsigned long *options = ARG_EI_GetPOptions(arg); static ExtractInfo extractInfo; static char flagInit = YES; /* Init of the extraction info */ if (flagInit) { extractInfo.nSignals = 1; extractInfo.dx = 1; extractInfo.xmin = 0; extractInfo.flags = EIIntIndex | EIErrorBound; flagInit = NO; } extractInfo.xmax = MAX(wtrans->noct,9); return(&extractInfo);}/* * Extraction */static char *doc = "{[oct,orient]} {it returns the image which corresponds to octave <oct> and orientation <orient>. The image [0,0] corresponds to the analyzed image. \The projection on the V_oct spaces are stored in [oct,0]. [oct,1] corresponds to the vertical details at octave oct \and [oct,2] corresponds to the horizontal details at octave oct. [oct,3] corresponds to the norm of ([oct,1],[oct,2]) and \[oct,4] to its phase. All the other images are not used by the wavelet transform and can be used as working images.}"; static void *GetExtractWtrans2V(WTRANS2 wtrans, void **arg){ char *field; FSIList *fsiList; IMAGE i; int o,v; /* doc */ if (wtrans == NULL) return(doc); field = ARG_G_GetField(arg); fsiList = ARG_G_GetFsiList(arg); /* 2 integers in between the [] */ if (fsiList->nx != 2) { SetErrorf("dwtrans2[] expects 2 indices"); return(NULL); } /* Get the integers */ o = (int) FSI_FIRST(fsiList); v = (int) FSI_SECOND(fsiList); i = Extract(wtrans,o,v); if (i == NULL) return(NULL); ARG_G_SetResValue(arg,i); return(GetTypeValue(i));}static void *SetExtractWtrans2V(WTRANS2 wtrans, void **arg){ char *field; FSIList *fsiList; IMAGE i; int o,v; /* doc */ if (wtrans == NULL) return(doc); field = ARG_S_GetField(arg); fsiList = ARG_S_GetFsiList(arg); /* 2 integers in between the [] */ if (fsiList->nx != 2) { SetErrorf("dwtrans2[] expects 2 indices"); return(NULL); } /* Get the integers */ o = (int) FSI_FIRST(fsiList); v = (int) FSI_SECOND(fsiList); i = Extract(wtrans,o,v); if (i == NULL) return(NULL); return(SetImageField(i,arg));}/*********************************************************************************** * * Allocation and Desallocation * ***********************************************************************************//************ ALLOCATE A WTRANS2 ****************/extern TypeStruct tsDWtrans2;WTRANS2 NewWtrans2(void){ WTRANS2 trans; int i,j; #ifdef DEBUGALLOCDebugType = "DWtrans2";#endif trans = (WTRANS2) Malloc(sizeof(struct wtrans2)); InitValue(trans,&tsDWtrans2); for (i=0;i<W2_MAX_LEVEL;i++) for (j=0;j<W2_MAX_ORIENTATION;j++) { trans->images[i][j] = NewImage(); trans->images[i][j]->name = CharAlloc(8); if (i==0) sprintf(trans->images[i][j]->name,"%d",j); else sprintf(trans->images[i][j]->name,"%d%d",i,j); } trans->filterg1 = NewFilter2(); /* decomposition filter */ trans->filterh1 = NewFilter2(); trans->filterk1 = NewFilter2(); trans->filterg2 = NewFilter2(); /* reconstruction filter */ trans->filterh2 = NewFilter2(); trans->filterk2 = NewFilter2(); trans->noct = 0; trans->norient = 0; trans->extrep = NewExtrep2(); trans->chainrep = NewChainrep2(); trans->name=defaultName; trans->wName=NULL; trans->periodic=NO; return(trans);}void ClearWtrans2(WTRANS2 wtrans2){ int i,j; for (i=0;i<W2_MAX_LEVEL;i++) for (j=0;j<W2_MAX_ORIENTATION;j++) { ClearImage(wtrans2->images[i][j]); } wtrans2->noct =0; wtrans2->norient=0; wtrans2->periodic=NO; if (wtrans2->wName) Free(wtrans2->wName); wtrans2->wName=NULL; ClearFilter2(wtrans2->filterg1); ClearFilter2(wtrans2->filterh1); ClearFilter2(wtrans2->filterk1); ClearFilter2(wtrans2->filterg2); ClearFilter2(wtrans2->filterh2); ClearFilter2(wtrans2->filterk2); DeleteExtrep2(wtrans2->extrep); DeleteChainrep2(wtrans2->chainrep); wtrans2->extrep = NewExtrep2(); wtrans2->chainrep = NewChainrep2(); }/* * Copy a WTRANS2 into another */WTRANS2 CopyWtrans2(WTRANS2 in,WTRANS2 out){ int i,j; /* Tests*/ if (in == NULL) return(NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -