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

📄 hplx_hor.c

📁 JPEG2000 EBCOT算法源码
💻 C
📖 第 1 页 / 共 3 页
字号:
      Lfilt[-i-self->EvenFilter]=(float)(0.0);
  }
  
  for(i=-2;i>=self->V_min;i-=2)
  {
    if(i>=self->VL_min)
      Lfilt[-i-self->EvenFilter]=l_taps[i];
    else
      Lfilt[-i-self->EvenFilter]=(float)(0.0);
    if(i-self->EvenFilter>=self->VH_min)
      Hfilt[-i]=h_taps[i-self->EvenFilter];
    else
      Hfilt[-i]=(float)(0.0);
  }       
  
  for(i=1;i<self->V_max;i+=2)
  {
    if(i+self->EvenFilter<self->VH_max)
      Lfilt[-i-self->EvenFilter]=h_taps[i+self->EvenFilter];
    else
      Lfilt[-i-self->EvenFilter]=(float)(0.0);
  }
  
  for(i=1;i<=-self->V_min;i+=2)
  {                       
    if(i-2*self->EvenFilter<self->VL_max)
      Hfilt[-i]=l_taps[i-2*self->EvenFilter];
    else
      Hfilt[-i]=(float)(0.0);
  }
  
  for(i=-1;i>=self->V_min;i-=2)
  {
    if(i+self->EvenFilter>=self->VH_min)
      Lfilt[-i-self->EvenFilter]=h_taps[i+self->EvenFilter];
    else
      Lfilt[-i-self->EvenFilter]=(float)(0.0);
    
    if(i-2*self->EvenFilter>=self->VL_min)
      Hfilt[-i]=l_taps[i-2*self->EvenFilter];
    else
      Hfilt[-i]=(float)(0.0);    
    
    /*** Problem detected here.  Accesses one beyond nominal array bounds. */
    
  }
  
  self->VL_min = self->V_min;
  self->VL_max = self->V_max;
  self->VH_min = self->V_min;
  self->VH_max = self->V_max;
  
  if(self->EvenFilter)
  {
    self->VL_Low  = self->VL_High = Hfilt;
    self->VH_Low  = self->VH_High = Lfilt;
  }
  else
  {
    self->VL_Low  = self->VL_High = Lfilt;
    self->VH_Low  = self->VH_High = Hfilt;
  }
  
  self->VL_Low  += self->VL_min; 
  self->VL_High += self->VL_max;
  self->VH_Low  += self->VH_min; 
  self->VH_High += self->VH_max;
}

/************************************************************************/
/*
*    c_levs -> number of levels in the inverse WT
*
*/
/************************************************************************/
static void
  interpolator__interpolate(interpolator_ref self, float *Output)
{
  int i,j, g2H,g2L,z,lengthL,lengthH,evenF;    
  int shift_factorL, shift_factorH,NotBothOdd,_Strange,OddSignal;
  float *downH,*downL,*tmp;
  float *SindxLI;
  int PLUSMINUS1=self->EvenFilter?(-1):1;
  downL=self->VL_Low;
  downH=self->VH_Low;
  evenF=self->EvenFilter;  
  z=self->Length;
  OddSignal = z & 1;
  _Strange = (OddSignal && evenF);
  lengthL = ((z+1) >> 1)  - _Strange;
  lengthH = z>>1;
  NotBothOdd =(!OddSignal) || evenF ;
  shift_factorL =
	  - 2 * ( evenF ||OddSignal)
	  + 2 * (int)(!NotBothOdd) ;
  shift_factorH = - 1;
  g2L = 2 * (lengthL - !NotBothOdd );
  g2H = 2 * ( lengthH + !NotBothOdd -  !evenF ) + 1 ;
  /************************************************/
 
  SindxLI = self->_data + lengthL + _Strange;
  
 /***********************************************
  ** This is the main part of the signal high pass
  ***********************************************/
  
  for ( j = 0, tmp = self->buffer - 1 ;
  j < (int)(lengthH)  ; j++ )
	  *(tmp+=2)=*(SindxLI++);
  
  /************************************************/
  
  SindxLI = self->_data;
  
  /***********************************************
  ** This is the main part of the signal low pass
  ***********************************************/
  
  for ( j = 0,tmp= self->buffer - 2;
  j < (int)(lengthL); j++ ) 
	  *(tmp+=2)=*(SindxLI++);
  
  if (_Strange)
        *( Output   + z - 1) = *( SindxLI  ) ;
      
        /***********************************************
        ** Extension to the left of the signal low pass
      ***********************************************/
      
      for ( j = -2 , i = shift_factorL ;
      j > - self->VL_max - 1; j-=2)
        self->buffer[j] =  self->buffer[i+=2];
      
        /***********************************************
        ** Extension to the right of the signal low pass
      ***********************************************/
      
      for ( j = (int)(z)-(int)(_Strange)+!NotBothOdd, i= g2L;
            j < (int)(z) - (int)(_Strange) - self->VL_min ;
            j+=2 ) 
        self->buffer[j] =  self->buffer[i-=2];
      
        /***********************************************
        ** Extension to the left of the signal high pass
      ***********************************************/
      
      for( j = -1 , i = shift_factorH;
           j > -self->VH_max; j-=2 )
        self->buffer[j]= PLUSMINUS1 * self->buffer[i+=2];
      
        /***********************************************
        ** Extension to the right of the signal high pass
      ***********************************************/
      
      for( j = (int)(z) + NotBothOdd - (int)(_Strange),
           i = g2H; j < (int)(z) -  self->VH_min ; j+=2 ) 
        self->buffer[j]= PLUSMINUS1 *  self->buffer[i-=2];
      
      SindxLI = self->buffer -self->V_max+1 ;                       
      
      /******************************************
      *      filtering done here
      ******************************************/
 
      
if(!self->DefaultFB) 
  {int flag,k;
   float *Sindex1,*SindxL,*tmpf,*tmpf1,*tmp_ptr,*SindxH;
   register float ftmp;
if(!evenF)
{
   /* Low pass*/
   j=((z-_Strange+1)>>1);
   flag=1;
   i=-self->VL_min;
   SindxL=self->buffer-self->V_max+1 -2;
   Sindex1=SindxL+i+self->VL_max-1;
   while(i--){
              ftmp=*(downL++);
              tmpf=SindxL++;
	          tmpf1=Sindex1--;
              tmp_ptr=Output-2;
              k=j;
    if(ftmp){
    if(flag) 
		while(k--) *(tmp_ptr+=2) = ftmp* (*(tmpf +=2 )+*(tmpf1 +=2)) ;
    else     
		while(k--) *(tmp_ptr+=2) +=ftmp* (*(tmpf +=2 )+*(tmpf1 +=2));
	flag=0;} }

	  ftmp=*(downL++);
      tmpf=SindxL++;
      tmp_ptr=Output-2;
      k=j;
   if(flag)  while(k--)*(tmp_ptr+=2) = ftmp* *((tmpf +=2) );
   else      while(k--) *(tmp_ptr+=2) += ftmp* *(tmpf +=2);
  
     
      /*  High Pass */  

	j=((int)(z) - (int)(_Strange))>>1;
	flag=1;
    i=-self->VH_min;
	SindxH=self->buffer+1-self->V_max+1-2-evenF;
	Sindex1=SindxH+self->VH_max+i-1;
	while(i--){
	           ftmp=*(downH++);
               tmpf=SindxH++;
	           tmpf1=Sindex1--;
	           tmp_ptr=Output-1;
	           k=j;
	 if(ftmp)
	 {if(flag) while(k--) *(tmp_ptr+=2)= ftmp*(*(tmpf +=2 )+*(tmpf1 +=2)) ;
	 else      while(k--) *(tmp_ptr+=2)+=ftmp*(*(tmpf +=2 )+*(tmpf1 +=2)); 
	 flag=0;}
	}
    ftmp=*(downH++);
	tmpf=SindxH++;
	tmp_ptr=Output-1;
	k=j;
	if(flag) while(k--) *(tmp_ptr+=2) =  ftmp* *(tmpf += 2 );
	else     while(k--) *(tmp_ptr+=2) += ftmp* *(tmpf += 2 );
}
else
{
		i=((int)(z) - (int)(_Strange) )>>1;
        while(i--)
        {
          *(Output++) = inner_prod( self->VL_Low, self->VL_High,
            SindxLI++, (float)(0.0));
          *(Output++) = inner_prod( self->VH_Low, self->VH_High,
            SindxLI++ - self->EvenFilter,
            (float)(0.0));
        }
        if( ((int)(z) - (int)(_Strange) ) &1)
          *(Output++) = inner_prod( self->VL_Low, self->VL_High,
          SindxLI++, (float)(0.0));
 	
}
}/* if (defaultFB */ 
else   
{
	i=((int)(z) - (int)(_Strange) )>>1;
       while(i--)
        {     
          *(Output++) =  
            (float)(gs3) * (SindxLI[1]+SindxLI[7])+
            (float)(hs2) * (SindxLI[2]+SindxLI[6])+
            (float)(gs1) * (SindxLI[3]+SindxLI[5])+
            (float)(hs0) *  SindxLI[4];
          SindxLI++;       
          *(Output++) =
            (float)(gs4)* (SindxLI[0]+SindxLI[8]) +
            (float)(hs3)* (SindxLI[1]+SindxLI[7]) +
            (float)(gs2)* (SindxLI[2]+SindxLI[6]) +
            (float)(hs1)* (SindxLI[3]+SindxLI[5]) +
            (float)(gs0)*  SindxLI[4];
          SindxLI++;       
		 
        }
        if( ((int)(z) - (int)(_Strange) ) &1)
        {
          *(Output++) =  
            (float)(gs3) * (SindxLI[1]+SindxLI[7])+
            (float)(hs2) * (SindxLI[2]+SindxLI[6])+
            (float)(gs1) * (SindxLI[3]+SindxLI[5])+
            (float)(hs0) *  SindxLI[4];
          SindxLI++;       
        }

	  }
   
}

/************************************************************************/
/* Initialization routine for class decimator
*
*/
/************************************************************************/

static void
  decimator__initialize_fixed(decimator_ref self,      
                              int  X,
                              filter_info_ref info,int c_levs,
                              int component_idx)
{       
  int i,PLUSMINUS1;
  float *l_taps, *h_taps;
  int h_neg, h_pos, l_neg, l_pos, Lmin, Lbeyond, Hmin, Hbeyond;
  char *built_in_id;
  
  self->DefaultFB = 0;
  self->component_idx = component_idx;
  
  l_taps = info->get_taps(info,0,component_idx,0x0F&c_levs,&l_neg,&l_pos,NULL);
  h_taps = info->get_taps(info,FILTER__HIGH,component_idx,0x0F&c_levs,
                          &h_neg,&h_pos,&built_in_id);
  self->shiftFactor =
    compute_shift_factor(l_taps,l_neg+l_pos+1,
                         h_taps,h_neg+h_pos+1,
                         self->coeff_precision,1.0F);
  
  if ((built_in_id != NULL) && (strcmp(built_in_id,"0") == 0))
    self->DefaultFB = 1;
  
  self->EvenFilter = (l_neg+l_pos) & 1;
  Lmin = -l_pos; Lbeyond = l_neg+1;
  Hmin = -h_pos; Hbeyond = h_neg+1;
  if (self->EvenFilter)
  { Hmin--; Hbeyond--; }
  
  self->VL_min = Lmin;
  self->VL_max = Lbeyond;
  self->VH_min = Hmin;
  self->VH_max = Hbeyond;
  self->V_min = min( self->VL_min, self->VH_min );
  self->V_max = max( self->VL_max, self->VH_max );
  PLUSMINUS1     = self->EvenFilter?(-1):1;          
  

  self->VL_Low_I = ( int  *)
    local_malloc(sizeof( int )*(size_t)(Lbeyond-Lmin));
  self->VH_Low_I = ( int  *)
    local_malloc(sizeof( int )*(size_t)(Hbeyond-Hmin));
  self->VL_High_I = self->VL_Low_I + (Lbeyond - Lmin);
  self->VH_High_I = self->VH_Low_I + (Hbeyond - Hmin);
  for (i=0; i < (Lbeyond - Lmin); i++)
    self->VL_High_I[-i-1] = roundshift(l_taps[i],self->shiftFactor);
  for (i=0; i < (Hbeyond - Hmin); i++)
    self->VH_High_I[-i-1] = roundshift(h_taps[i],self->shiftFactor);
  
  for(i=0;i<self->VH_max-self->VH_min;i++)
    self->VH_Low_I[i] *=PLUSMINUS1;
  
  self->xdim=self->Length=X;
     
  self->buffer_I =
    ((short int *)
    local_malloc((self->Length-self->V_min+self->V_max)*sizeof(short int )))
    + self->V_max;

  self->BufFast =
    (( int *)
    local_malloc((self->Length)*sizeof(int ))); 
}

/************************************************************************/
/*
*  decomposes an input line, 
*
*/
/************************************************************************/

static void 
  decimator__decimate_fixed(decimator_ref self,short int  * V)
{
  register int j,i,k,l,l1,flag;
  short int  *SindxL,*SindxH,*OindxH,qu=0;
  int  shift_factorL, shift_factorH,_Strange;  
  int *downL,*downH,evenF,OddSignal;
  int effectiveL;
  register int ftmp,*tmp_ptr;
  register short int *tmpf,*tmpf1;
  short int *Sindex1;
 
  downL=self->VL_Low_I;
  downH=self->VH_Low_I;
  evenF=self->EvenFilter;
 
  l=self->shiftFactor;
  l1= 1<<(l-1);
  
  effectiveL=self->Length;
  if( (effectiveL&1) && evenF)
  {effectiveL--; _Strange=1;} else _Strange=0;
  
  /***********************************************
  ** This is the main part of the signal
  ***********************************************/
  
 
      OddSignal = effectiveL & 1;
      shift_factorL =  - self->VL_max - 1;
      shift_factorH =  - self->VH_max - evenF ;
      if (_Strange)qu=(short int )( (*(self->buffer_I+effectiveL))); 
      
        /***********************************************
        ** Extension to the left of the signal
      ***********************************************/
      
      for(j=-1,i=-(int)(evenF);j>-self->V_max;j--)
        self->buffer_I[j]=self->buffer_I[(++i)%effectiveL];
      
        /***********************************************
        ** Extension to the right of the signal
      ***********************************************/
      
      for ( j = effectiveL ,
            i = ( ( effectiveL << 1 ) - !evenF ) ;
            j < effectiveL - self->V_min; j++ )  
        self->buffer_I[j]=self->buffer_I[(--i)%effectiveL];
      
        /********************************
        Filtering for the Low pass
        Filtering for the High pass
      ********************************/
      
      SindxL        = self->buffer_I + shift_factorL ;
      OindxH        = V + ((effectiveL+1+_Strange)>>1);
      SindxH        = self->buffer_I + shift_factorH ;

	  /* Low Pass*/
	  /************************************************************/
	  j=(effectiveL>>1)+OddSignal;
	  flag=1;
      i=self->VL_max-self->VL_min;
	  Sindex1=SindxL+i-1;
	  i>>=1;
	  while(i--){
		  ftmp=*(downL++);
          tmpf=SindxL++;
	      tmpf1=Sindex1--;
	      tmp_ptr=self->BufFast;
	      k=j;
	      if(flag) while(k--) *(tmp_ptr++) = 
			           ftmp* ((int)*(tmpf +=2 )+(int)*(tmpf1 +=2)) ;
	      else     while(k--) *(tmp_ptr++) += 
			           ftmp* ((int)*(tmpf +=2 )+(int)*(tmpf1 +=2));
           flag=0; }

      if(!evenF) {  /*Oddlength Filter */
		  ftmp=*(downL++);
          tmpf=SindxL++;
          tmp_ptr=self->BufFast;
          k=j;
	      if(flag)   while(k--)*(tmp_ptr++) = 
			                 ftmp* *((tmpf +=2) );
	      else    while(k--) *(tmp_ptr++) += 
			                 ftmp* *(tmpf +=2);}
      tmp_ptr=self->BufFast;
	  k=j;
	  /* Write data to output buffer*/
      while(k--)   *(V++) = (*(tmp_ptr++) +l1)>>l;;
      if(_Strange) *(V++)=qu;  

      /*  High Pass */  

	  j=(effectiveL>>1);
	  flag=1;
      i=self->VH_max-self->VH_min;
	  Sindex1=SindxH+i-1;

⌨️ 快捷键说明

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