WEB开发网
开发学院软件开发VC DCT快速变换 阅读

DCT快速变换

 2010-07-25 20:45:40 来源:WEB开发网   
核心提示:IDCT快速变换初始化查找表:void initIDCTParam(int deg){if(bHasInit) return;//不用再计算查找表int total, halftotal, i, group, endstart, factor;total = 1 << deg;// if(C!=NULL)

IDCT快速变换

初始化查找表:

void initIDCTParam(int deg)
{
   if(bHasInit)
       return;  //不用再计算查找表
   int total, halftotal, i, group, endstart, factor;
   total = 1 << deg;
   // if(C!=NULL) delete []C;
   // C=(double *)new double[total];
   // 由于正变换已经为C申请了空间,所以逆变换就需再申请空间了!
   halftotal = total >> 1;
   for(i = 0; i < halftotal; i++)
       C[total-i-1] = (double)(2*i+1);
   for(group = 0; group < deg-1; group++)
   {
       endstart = 1 << (deg-1-group);
       int len = endstart>>1;
       factor = 1 << (group+1);
       for(int j = 0; j < len; j++)
          C[endstart-j-1] = factor*C[total-j-1];
   }
   for(i = 1; i < total; i++)
       C[i] = 1.0/(2.0*cos(C[i]*PI/(total << 1)));    // C[0]空着没用
   bHasInit=true;
}

IDCT变换过程也可分为两部分:前向追底和后向回根

前向追底

void idct_forward(double *F,int deg)
{
   int total,i_deg,wing,wings,halfwing,winglen,i_halfwing,temp1,temp2;
   total = 1 << deg;
   for(i_deg = 0; i_deg < deg; i_deg++)
   {
       wings = 1 << i_deg;
       winglen = 1 << (deg-i_deg);
       halfwing = winglen >> 1;
       for(wing = 0; wing < wings; wing++)
       {
          for(i_halfwing = halfwing-1; i_halfwing >= 0; i_halfwing--)
          {
              if(i_halfwing == 0)
              {
                 F[halfwing+wing*winglen+i_halfwing] =
                  2.0*F[halfwing+wing*winglen+i_halfwing];
              }
              else
              {
                 temp1 = bitrev(i_halfwing,deg-i_deg-1);
                 temp2 = bitrev(i_halfwing-1,deg-i_deg-1);
                 F[halfwing+wing*winglen+temp1] = F[halfwing+wing*winglen+temp1]
                     +F[halfwing+wing*winglen+temp2];
              }
          }
       }
   }
}

上一页  1 2 3 4 5 6 7  下一页

Tags:DCT 快速 变换

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接