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

📄 block.c

📁 网络MPEG4IP流媒体开发源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  }  //  vertical  for (i=0; i < BLOCK_SIZE; i++)  {    for (j=0; j < BLOCK_SIZE; j++)    {      m5[j]=img->m7[i][j];    }    m6[0]=(m5[0]+m5[2])*13;    m6[1]=(m5[0]-m5[2])*13;    m6[2]=m5[1]*7-m5[3]*17;    m6[3]=m5[1]*17+m5[3]*7;    for (j=0; j < 2; j++)    {      j1=3-j;      img->m7[i][j] =min(255,max(0,(m6[j]+m6[j1]+JQQ2)/JQQ1));      img->m7[i][j1]=min(255,max(0,(m6[j]-m6[j1]+JQQ2)/JQQ1));    }  }  //  Decoded block moved to frame memory  for (j=0; j < BLOCK_SIZE; j++)    for (i=0; i < BLOCK_SIZE; i++)      imgY[img->pix_y+block_y+j][img->pix_x+block_x+i]=img->m7[i][j];  return nonzero;}#endif/*! ************************************************************************ * \brief *    Transform,quantization,inverse transform for chroma. *    The main reason why this is done in a separate routine is the *    additional 2x2 transform of DC-coeffs. This routine is called *    ones for each of the chroma components. * * \para Input: *    uv    : Make difference between the U and V chroma component               \n *    cr_cbp: chroma coded block pattern * * \para Output: *    cr_cbp: Updated chroma coded block pattern. ************************************************************************ */#ifndef NO_RDQUANTint dct_chroma_sp(int uv,int cr_cbp){  int i,j,i1,j2,ilev,n2,n1,j1,mb_y,coeff_ctr,qp_const,pos_x,pos_y,quant_set,level ,scan_pos,run;  int m1[BLOCK_SIZE],m5[BLOCK_SIZE],m6[BLOCK_SIZE];  int coeff[16];  int predicted_chroma_block[MB_BLOCK_SIZE/2][MB_BLOCK_SIZE/2],alpha,Fq1q2,mp1[BLOCK_SIZE],quant_set1;  qp_const=JQQ4;  for (j=0; j < MB_BLOCK_SIZE/2; j++)    for (i=0; i < MB_BLOCK_SIZE/2; i++)    {      img->m7[i][j]+=img->mpr[i][j];      predicted_chroma_block[i][j]=img->mpr[i][j];    }  for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      //  Horizontal transform.      for (j=0; j < BLOCK_SIZE; j++)      {        mb_y=n2+j;        for (i=0; i < 2; i++)        {          i1=3-i;          m5[i]=img->m7[i+n1][mb_y]+img->m7[i1+n1][mb_y];          m5[i1]=img->m7[i+n1][mb_y]-img->m7[i1+n1][mb_y];        }        img->m7[n1][mb_y]=(m5[0]+m5[1])*13;        img->m7[n1+2][mb_y]=(m5[0]-m5[1])*13;        img->m7[n1+1][mb_y]=m5[3]*17+m5[2]*7;        img->m7[n1+3][mb_y]=m5[3]*7-m5[2]*17;      }      //  Vertical transform.      for (i=0; i < BLOCK_SIZE; i++)      {        j1=n1+i;        for (j=0; j < 2; j++)        {          j2=3-j;          m5[j]=img->m7[j1][n2+j]+img->m7[j1][n2+j2];          m5[j2]=img->m7[j1][n2+j]-img->m7[j1][n2+j2];        }        img->m7[j1][n2+0]=(m5[0]+m5[1])*13;        img->m7[j1][n2+2]=(m5[0]-m5[1])*13;        img->m7[j1][n2+1]=m5[3]*17+m5[2]*7;        img->m7[j1][n2+3]=m5[3]*7-m5[2]*17;      }    }  }  //     2X2 transform of DC coeffs.  m1[0]=(img->m7[0][0]+img->m7[4][0]+img->m7[0][4]+img->m7[4][4])/2;  m1[1]=(img->m7[0][0]-img->m7[4][0]+img->m7[0][4]-img->m7[4][4])/2;  m1[2]=(img->m7[0][0]+img->m7[4][0]-img->m7[0][4]-img->m7[4][4])/2;  m1[3]=(img->m7[0][0]-img->m7[4][0]-img->m7[0][4]+img->m7[4][4])/2;  for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      //  Horizontal transform.      for (j=0; j < BLOCK_SIZE; j++)      {        mb_y=n2+j;        for (i=0; i < 2; i++)        {          i1=3-i;          m5[i]=predicted_chroma_block[i+n1][mb_y]+predicted_chroma_block[i1+n1][mb_y];          m5[i1]=predicted_chroma_block[i+n1][mb_y]-predicted_chroma_block[i1+n1][mb_y];        }        predicted_chroma_block[n1][mb_y]=(m5[0]+m5[1])*13;        predicted_chroma_block[n1+2][mb_y]=(m5[0]-m5[1])*13;        predicted_chroma_block[n1+1][mb_y]=m5[3]*17+m5[2]*7;        predicted_chroma_block[n1+3][mb_y]=m5[3]*7-m5[2]*17;      }      //  Vertical transform.      for (i=0; i < BLOCK_SIZE; i++)      {        j1=n1+i;        for (j=0; j < 2; j++)        {          j2=3-j;          m5[j]=predicted_chroma_block[j1][n2+j]+predicted_chroma_block[j1][n2+j2];          m5[j2]=predicted_chroma_block[j1][n2+j]-predicted_chroma_block[j1][n2+j2];        }        predicted_chroma_block[j1][n2+0]=(m5[0]+m5[1])*13;        predicted_chroma_block[j1][n2+2]=(m5[0]-m5[1])*13;        predicted_chroma_block[j1][n2+1]=m5[3]*17+m5[2]*7;        predicted_chroma_block[j1][n2+3]=m5[3]*7-m5[2]*17;      }    }  }  //     2X2 transform of DC coeffs.  mp1[0]=(predicted_chroma_block[0][0]+predicted_chroma_block[4][0]+predicted_chroma_block[0][4]+predicted_chroma_block[4][4])/2;  mp1[1]=(predicted_chroma_block[0][0]-predicted_chroma_block[4][0]+predicted_chroma_block[0][4]-predicted_chroma_block[4][4])/2;  mp1[2]=(predicted_chroma_block[0][0]+predicted_chroma_block[4][0]-predicted_chroma_block[0][4]-predicted_chroma_block[4][4])/2;  mp1[3]=(predicted_chroma_block[0][0]-predicted_chroma_block[4][0]-predicted_chroma_block[0][4]+predicted_chroma_block[4][4])/2;  //     Quant of chroma 2X2 coeffs.  quant_set=QP_SCALE_CR[img->qp];  quant_set1=QP_SCALE_CR[img->qpsp];  alpha=(JQQ1+JQ[quant_set1][0]/2)/JQ[quant_set1][0];  Fq1q2=(JQQ1*JQ[quant_set1][0]+JQ[quant_set][0]/2)/JQ[quant_set][0];  for (coeff_ctr=0; coeff_ctr < 4; coeff_ctr++)    coeff[coeff_ctr]=m1[coeff_ctr]-alpha*sign((abs (mp1[coeff_ctr]) * JQ[quant_set1][0] +JQQ2) / JQQ1,mp1[coeff_ctr]);  rd_quant(QUANT_CHROMA_DC,coeff);  run=-1;  scan_pos=0;  for (coeff_ctr=0; coeff_ctr < 4; coeff_ctr++)  {    run++;    ilev=0;    level =0;    level =(absm(coeff[coeff_ctr]));    if (level  != 0)    {      cr_cbp=max(1,cr_cbp);      img->cofu[scan_pos][0][uv]=sign(level ,coeff[coeff_ctr]);      img->cofu[scan_pos][1][uv]=run;      scan_pos++;      run=-1;      ilev=level;    }      ilev=coeff[coeff_ctr]*Fq1q2+mp1[coeff_ctr]*JQ[quant_set1][0];      m1[coeff_ctr]=sign((abs(ilev)+JQQ2)/ JQQ1,ilev)*JQ[quant_set1][1];  }  img->cofu[scan_pos][0][uv]=0;  //  Invers transform of 2x2 DC levels  img->m7[0][0]=(m1[0]+m1[1]+m1[2]+m1[3])/2;  img->m7[4][0]=(m1[0]-m1[1]+m1[2]-m1[3])/2;  img->m7[0][4]=(m1[0]+m1[1]-m1[2]-m1[3])/2;  img->m7[4][4]=(m1[0]-m1[1]-m1[2]+m1[3])/2;  //     Quant of chroma AC-coeffs.  for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      pos_x=n1/BLOCK_SIZE + 2*uv;      pos_y=n2/BLOCK_SIZE + BLOCK_SIZE;      run=-1;      scan_pos=0;      for (coeff_ctr=1; coeff_ctr < 16; coeff_ctr++)      {        i=SNGL_SCAN[coeff_ctr][0];        j=SNGL_SCAN[coeff_ctr][1];        coeff[coeff_ctr-1]=img->m7[n1+i][n2+j]-alpha*sign((abs (predicted_chroma_block[n1+i][n2+j]) * JQ[quant_set1][0] +JQQ2) / JQQ1,predicted_chroma_block[n1+i][n2+j]);      }      rd_quant(QUANT_CHROMA_AC,coeff);      for (coeff_ctr=1; coeff_ctr < 16; coeff_ctr++)      {        i=SNGL_SCAN[coeff_ctr][0];        j=SNGL_SCAN[coeff_ctr][1];        ++run;        ilev=0;        level=absm(coeff[coeff_ctr-1]);        if (level  != 0)        {          cr_cbp=2;          img->cof[pos_x][pos_y][scan_pos][0][0]=sign(level,coeff[coeff_ctr-1]);          img->cof[pos_x][pos_y][scan_pos][1][0]=run;          ++scan_pos;          run=-1;          ilev=level;        }        ilev=sign(ilev,coeff[coeff_ctr-1])*Fq1q2+predicted_chroma_block[n1+i][n2+j]*JQ[quant_set1][0];        img->m7[n1+i][n2+j]=sign((abs(ilev)+JQQ2)/ JQQ1,ilev)*JQ[quant_set1][1];      }      img->cof[pos_x][pos_y][scan_pos][0][0]=0; // EOB      //     IDCT.      //     Horizontal.      for (j=0; j < BLOCK_SIZE; j++)      {        for (i=0; i < BLOCK_SIZE; i++)        {          m5[i]=img->m7[n1+i][n2+j];        }        m6[0]=(m5[0]+m5[2])*13;        m6[1]=(m5[0]-m5[2])*13;        m6[2]=m5[1]*7-m5[3]*17;        m6[3]=m5[1]*17+m5[3]*7;        for (i=0; i < 2; i++)        {          i1=3-i;          img->m7[n1+i][n2+j]=m6[i]+m6[i1];          img->m7[n1+i1][n2+j]=m6[i]-m6[i1];        }      }      //     Vertical.      for (i=0; i < BLOCK_SIZE; i++)      {        for (j=0; j < BLOCK_SIZE; j++)        {          m5[j]=img->m7[n1+i][n2+j];        }        m6[0]=(m5[0]+m5[2])*13;        m6[1]=(m5[0]-m5[2])*13;        m6[2]=m5[1]*7-m5[3]*17;        m6[3]=m5[1]*17+m5[3]*7;        for (j=0; j < 2; j++)        {          j2=3-j;          img->m7[n1+i][n2+j]=min(255,max(0,(m6[j]+m6[j2]+JQQ2)/JQQ1));          img->m7[n1+i][n2+j2]=min(255,max(0,(m6[j]-m6[j2]+JQQ2)/JQQ1));        }      }    }  }  //  Decoded block moved to memory  for (j=0; j < BLOCK_SIZE*2; j++)    for (i=0; i < BLOCK_SIZE*2; i++)    {      imgUV[uv][img->pix_c_y+j][img->pix_c_x+i]= img->m7[i][j];    }  return cr_cbp;}#endif#ifdef NO_RDQUANTint dct_chroma_sp(int uv,int cr_cbp){  int i,j,i1,j2,ilev,n2,n1,j1,mb_y,coeff_ctr,qp_const,pos_x,pos_y,quant_set,quant_set1,c_err,level ,scan_pos,run;  int m1[BLOCK_SIZE],m5[BLOCK_SIZE],m6[BLOCK_SIZE];// int coeff[16];  int coeff_cost;  int cr_cbp_tmp;  int predicted_chroma_block[MB_BLOCK_SIZE/2][MB_BLOCK_SIZE/2],alpha,Fq1q2,mp1[BLOCK_SIZE];  Macroblock *currMB = &img->mb_data[img->current_mb_nr];  qp_const=JQQ4;  for (j=0; j < MB_BLOCK_SIZE/2; j++)        for (i=0; i < MB_BLOCK_SIZE/2; i++)        {          img->m7[i][j]+=img->mpr[i][j];          predicted_chroma_block[i][j]=img->mpr[i][j];        }  for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      //  Horizontal transform.      for (j=0; j < BLOCK_SIZE; j++)      {        mb_y=n2+j;        for (i=0; i < 2; i++)        {          i1=3-i;          m5[i]=img->m7[i+n1][mb_y]+img->m7[i1+n1][mb_y];          m5[i1]=img->m7[i+n1][mb_y]-img->m7[i1+n1][mb_y];        }        img->m7[n1][mb_y]=(m5[0]+m5[1])*13;        img->m7[n1+2][mb_y]=(m5[0]-m5[1])*13;        img->m7[n1+1][mb_y]=m5[3]*17+m5[2]*7;        img->m7[n1+3][mb_y]=m5[3]*7-m5[2]*17;      }      //  Vertical transform.      for (i=0; i < BLOCK_SIZE; i++)      {        j1=n1+i;        for (j=0; j < 2; j++)        {          j2=3-j;          m5[j]=img->m7[j1][n2+j]+img->m7[j1][n2+j2];          m5[j2]=img->m7[j1][n2+j]-img->m7[j1][n2+j2];        }        img->m7[j1][n2+0]=(m5[0]+m5[1])*13;        img->m7[j1][n2+2]=(m5[0]-m5[1])*13;        img->m7[j1][n2+1]=m5[3]*17+m5[2]*7;        img->m7[j1][n2+3]=m5[3]*7-m5[2]*17;      }    }  }  //     2X2 transform of DC coeffs.  m1[0]=(img->m7[0][0]+img->m7[4][0]+img->m7[0][4]+img->m7[4][4])/2;  m1[1]=(img->m7[0][0]-img->m7[4][0]+img->m7[0][4]-img->m7[4][4])/2;  m1[2]=(img->m7[0][0]+img->m7[4][0]-img->m7[0][4]-img->m7[4][4])/2;  m1[3]=(img->m7[0][0]-img->m7[4][0]-img->m7[0][4]+img->m7[4][4])/2;for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      //  Horizontal transform.      for (j=0; j < BLOCK_SIZE; j++)      {        mb_y=n2+j;        for (i=0; i < 2; i++)        {          i1=3-i;          m5[i]=predicted_chroma_block[i+n1][mb_y]+predicted_chroma_block[i1+n1][mb_y];          m5[i1]=predicted_chroma_block[i+n1][mb_y]-predicted_chroma_block[i1+n1][mb_y];        }        predicted_chroma_block[n1][mb_y]=(m5[0]+m5[1])*13;        predicted_chroma_block[n1+2][mb_y]=(m5[0]-m5[1])*13;        predicted_chroma_block[n1+1][mb_y]=m5[3]*17+m5[2]*7;        predicted_chroma_block[n1+3][mb_y]=m5[3]*7-m5[2]*17;      }      //  Vertical transform.      for (i=0; i < BLOCK_SIZE; i++)      {        j1=n1+i;        for (j=0; j < 2; j++)        {          j2=3-j;          m5[j]=predicted_chroma_block[j1][n2+j]+predicted_chroma_block[j1][n2+j2];          m5[j2]=predicted_chroma_block[j1][n2+j]-predicted_chroma_block[j1][n2+j2];        }        predicted_chroma_block[j1][n2+0]=(m5[0]+m5[1])*13;        predicted_chroma_block[j1][n2+2]=(m5[0]-m5[1])*13;        predicted_chroma_block[j1][n2+1]=m5[3]*17+m5[2]*7;        predicted_chroma_block[j1][n2+3]=m5[3]*7-m5[2]*17;      }    }  }  //     2X2 transform of DC coeffs.  mp1[0]=(predicted_chroma_block[0][0]+predicted_chroma_block[4][0]+predicted_chroma_block[0][4]+predicted_chroma_block[4][4])/2;  mp1[1]=(predicted_chroma_block[0][0]-predicted_chroma_block[4][0]+predicted_chroma_block[0][4]-predicted_chroma_block[4][4])/2;  mp1[2]=(predicted_chroma_block[0][0]+predicted_chroma_block[4][0]-predicted_chroma_block[0][4]-predicted_chroma_block[4][4])/2;  mp1[3]=(predicted_chroma_block[0][0]-predicted_chroma_block[4][0]-predicted_chroma_block[0][4]+predicted_chroma_block[4][4])/2;//     Quant of chroma 2X2 coeffs.  quant_set=QP_SCALE_CR[img->qp];  quant_set1=QP_SCALE_CR[img->qpsp];  alpha=(JQQ1+JQ[quant_set1][0]/2)/JQ[quant_set1][0];  Fq1q2=(JQQ1*JQ[quant_set1][0]+JQ[quant_set][0]/2)/JQ[quant_set][0];  run=-1;  scan_pos=0;  for (coeff_ctr=0; coeff_ctr < 4; coeff_ctr++)  {    run++;    ilev=0;    c_err=m1[coeff_ctr]-alpha*sign((abs (mp1[coeff_ctr]) * JQ[quant_set1][0] +JQQ2) / JQQ1,mp1[coeff_ctr]);    level =(abs(c_err)*JQ[quant_set][0]+qp_const)/JQQ1;    if (level  != 0)    {      currMB->cbp_blk |= 0xf0000 << (uv << 2) ;  // if one of the 2x2-DC levels is != 0 the coded-bit      cr_cbp=max(1,cr_cbp);      img->cofu[scan_pos][0][uv]=sign(level ,c_err);      img->cofu[scan_pos][1][uv]=run;      scan_pos++;      run=-1;      ilev=level;    }    ilev=sign(level,c_err)*Fq1q2+mp1[coeff_ctr]*JQ[quant_set1][0];    m1[coeff_ctr]=sign((abs(ilev)+JQQ2)/ JQQ1,ilev)*JQ[quant_set1][1];  }  img->cofu[scan_pos][0][uv]=0;  //  Invers transform of 2x2 DC levels  img->m7[0][0]=(m1[0]+m1[1]+m1[2]+m1[3])/2;  img->m7[4][0]=(m1[0]-m1[1]+m1[2]-m1[3])/2;  img->m7[0][4]=(m1[0]+m1[1]-m1[2]-m1[3])/2;  img->m7[4][4]=(m1[0]-m1[1]-m1[2]+m1[3])/2;  //     Quant of chroma AC-coeffs.  coeff_cost=0;  cr_cbp_tmp=0;  for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)  {    for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)    {      pos_x=n1/BLOCK_SIZE + 2*uv;      pos_y=n2/BLOCK_SIZE + BLOCK_SIZE;      run=-1;      scan_pos=0;      for (coeff_ctr=1; coeff_ctr < 16; coeff_ctr++)// start change rd_quant      {        i=SNGL_SCAN[coeff_ctr][0];        j=SNGL_SCAN[coeff_ctr][1];        ++run;        ilev=0;        c_err=img->m7[n1+i][n2+j]-alpha*sign((abs (predicted_chroma_block[n1+i][n2+j]) * JQ[quant_set1][0] +JQQ2) / JQQ1,predicted_chroma_block[n1+i][n2+j]);        level= (abs(c_err)*JQ[quant_set][0]+qp_const)/JQQ1;        if (level  != 0)        {          currMB->cbp_blk |=  1 << (16 + (uv << 2) + ((n2 >> 1) + (n1 >> 2))) ;          if (level > 1)            coeff_cost += MAX_VALUE;                // set high cost, shall not be discarded          else            coeff_cost += COEFF_COST[run];          cr_

⌨️ 快捷键说明

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