?? block.c
字號:
M6[3]= M5[1]*17+M5[3]*7;
for (i=0;i<2;i++)
{
i1=3-i;
img->cof[i ][j][0][0]= M6[i]+M6[i1];
img->cof[i1][j][0][0]=M6[i]-M6[i1];
}
}
// vertical
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
M5[j]=img->cof[i][j][0][0];
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->cof[i][j][0][0] = ((M6[j]+M6[j1])/8) *JQ1[img->qp];
img->cof[i][j1][0][0]= ((M6[j]-M6[j1])/8) *JQ1[img->qp];
}
}
for (j=0;j<4;j++)
{
for (i=0;i<4;i++)
{
img->cof[i][j][0][0] = 3 * img->cof[i][j][0][0]/256;
}
}
}
void itrans_sp(struct img_par *img, //!< image parameters
int ioff, //!< index to 4x4 block
int joff, //!<
int i0, //!<
int j0) //!<
{
int i,j,i1,j1;
int m5[4];
int m6[4];
int predicted_block[BLOCK_SIZE][BLOCK_SIZE],Fq1q2,ilev;
for (j=0; j< BLOCK_SIZE; j++)
for (i=0; i< BLOCK_SIZE; i++)
{
predicted_block[i][j]=img->mpr[i+ioff][j+joff];
}
for (j=0; j < BLOCK_SIZE; j++)
{
for (i=0; i < 2; i++)
{
i1=3-i;
m5[i]=predicted_block[i][j]+predicted_block[i1][j];
m5[i1]=predicted_block[i][j]-predicted_block[i1][j];
}
predicted_block[0][j]=(m5[0]+m5[1])*13;
predicted_block[2][j]=(m5[0]-m5[1])*13;
predicted_block[1][j]=m5[3]*17+m5[2]*7;
predicted_block[3][j]=m5[3]*7-m5[2]*17;
}
// Vertival transform
for (i=0; i < BLOCK_SIZE; i++)
{
for (j=0; j < 2; j++)
{
j1=3-j;
m5[j]=predicted_block[i][j]+predicted_block[i][j1];
m5[j1]=predicted_block[i][j]-predicted_block[i][j1];
}
predicted_block[i][0]=(m5[0]+m5[1])*13;
predicted_block[i][2]=(m5[0]-m5[1])*13;
predicted_block[i][1]=m5[3]*17+m5[2]*7;
predicted_block[i][3]=m5[3]*7-m5[2]*17;
}
Fq1q2=(JQQ*JQ[img->qpsp]+JQ[img->qp]/2)/JQ[img->qp];
for (j=0;j<BLOCK_SIZE;j++)
for (i=0;i<BLOCK_SIZE;i++)
{
ilev=img->cof[i0][j0][i][j]/JQ1[img->qp]*Fq1q2+predicted_block[i][j]*JQ[img->qpsp];
img->cof[i0][j0][i][j]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[img->qpsp];
}
// horizontal
for (j=0;j<BLOCK_SIZE;j++)
{
for (i=0;i<BLOCK_SIZE;i++)
{
m5[i]=img->cof[i0][j0][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 (i=0;i<2;i++)
{
i1=3-i;
img->m7[i][j]=m6[i]+m6[i1];
img->m7[i1][j]=m6[i]-m6[i1];
}
}
// 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]=mmax(0,mmin(255,(m6[j]+m6[j1]+JQQ2)/JQQ));
img->m7[i][j1]=mmax(0,mmin(255,(m6[j]-m6[j1]+JQQ2)/JQQ));
}
}
}
/*!
***********************************************************************
* \brief
* The routine performs transform,quantization,inverse transform, adds the diff.
* to the prediction and writes the result to the decoded luma frame. Includes the
* RD constrained quantization also.
*
* \par Input:
* block_x,block_y: Block position inside a macro block (0,4,8,12).
*
* \par Output:
* nonzero: 0 if no levels are nonzero. 1 if there are nonzero levels. \n
* coeff_cost: Counter for nonzero coefficients, used to discard expencive levels.
************************************************************************
*/
void copyblock_sp(struct img_par *img,int block_x,int block_y)
{
int sign(int a,int b);
int i,j,i1,j1,m5[4],m6[4];
int predicted_block[BLOCK_SIZE][BLOCK_SIZE],quant_set1;
// Horizontal transform
for (j=0; j< BLOCK_SIZE; j++)
for (i=0; i< BLOCK_SIZE; i++)
{
predicted_block[i][j]=img->mpr[i+block_x][j+block_y];
}
for (j=0; j < BLOCK_SIZE; j++)
{
for (i=0; i < 2; i++)
{
i1=3-i;
m5[i]=predicted_block[i][j]+predicted_block[i1][j];
m5[i1]=predicted_block[i][j]-predicted_block[i1][j];
}
predicted_block[0][j]=(m5[0]+m5[1])*13;
predicted_block[2][j]=(m5[0]-m5[1])*13;
predicted_block[1][j]=m5[3]*17+m5[2]*7;
predicted_block[3][j]=m5[3]*7-m5[2]*17;
}
// Vertical transform
for (i=0; i < BLOCK_SIZE; i++)
{
for (j=0; j < 2; j++)
{
j1=3-j;
m5[j]=predicted_block[i][j]+predicted_block[i][j1];
m5[j1]=predicted_block[i][j]-predicted_block[i][j1];
}
predicted_block[i][0]=(m5[0]+m5[1])*13;
predicted_block[i][2]=(m5[0]-m5[1])*13;
predicted_block[i][1]=m5[3]*17+m5[2]*7;
predicted_block[i][3]=m5[3]*7-m5[2]*17;
}
// Quant
quant_set1=img->qpsp;
for (j=0;j < BLOCK_SIZE; j++)
for (i=0; i < BLOCK_SIZE; i++)
img->m7[i][j]=sign((abs(predicted_block[i][j])*JQ[quant_set1]+JQQ2)/ JQQ,predicted_block[i][j])*JQ1[quant_set1];
// IDCT.
// horizontal
for (j=0; j < BLOCK_SIZE; j++)
{
for (i=0; i < BLOCK_SIZE; i++)
{
m5[i]=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 (i=0; i < 2; i++)
{
i1=3-i;
img->m7[i][j]=m6[i]+m6[i1];
img->m7[i1][j]=m6[i]-m6[i1];
}
}
// 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)/JQQ));
img->m7[i][j1]=min(255,max(0,(m6[j]-m6[j1]+JQQ2)/JQQ));
}
}
// 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];
}
void itrans_sp_chroma(struct img_par *img,int ll)
{
int i,j,i1,j2,ilev,n2,n1,j1,mb_y,qp_const,quant_set;
int m5[BLOCK_SIZE];
int predicted_chroma_block[MB_BLOCK_SIZE/2][MB_BLOCK_SIZE/2],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++)
{
predicted_chroma_block[i][j]=img->mpr[i][j];
img->mpr[i][j]=0;
}
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_set=QP_SCALE_CR[img->qp];
quant_set1=QP_SCALE_CR[img->qpsp];
Fq1q2=(JQQ*JQ[quant_set1]+JQ[quant_set]/2)/JQ[quant_set];
ilev=img->cof[0+ll][4][0][0]*Fq1q2+mp1[0]*JQ[quant_set1];
mp1[0]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[quant_set1];
ilev=img->cof[1+ll][4][0][0]*Fq1q2+mp1[1]*JQ[quant_set1];
mp1[1]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[quant_set1];
ilev=img->cof[0+ll][5][0][0]*Fq1q2+mp1[2]*JQ[quant_set1];
mp1[2]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[quant_set1];
ilev=img->cof[1+ll][5][0][0]*Fq1q2+mp1[3]*JQ[quant_set1];
mp1[3]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[quant_set1];
img->cof[0+ll][4][0][0]=(mp1[0]+mp1[1]+mp1[2]+mp1[3])/2;
img->cof[1+ll][4][0][0]=(mp1[0]-mp1[1]+mp1[2]-mp1[3])/2;
img->cof[0+ll][5][0][0]=(mp1[0]+mp1[1]-mp1[2]-mp1[3])/2;
img->cof[1+ll][5][0][0]=(mp1[0]-mp1[1]-mp1[2]+mp1[3])/2;
for (n2=0; n2 <= BLOCK_SIZE; n2 += BLOCK_SIZE)
for (n1=0; n1 <= BLOCK_SIZE; n1 += BLOCK_SIZE)
for (i=0;i< BLOCK_SIZE; i++)
for (j=0;j< BLOCK_SIZE; j++)
if ((i!=0) || (j!=0))
{
ilev=img->cof[n1/BLOCK_SIZE+ll][4+n2/BLOCK_SIZE][i][j]/JQ1[QP_SCALE_CR[img->qp]]*Fq1q2+predicted_chroma_block[n1+i][n2+j]*JQ[quant_set1];
img->cof[n1/BLOCK_SIZE+ll][4+n2/BLOCK_SIZE][i][j]=sign((abs(ilev)+JQQ2)/ JQQ,ilev)*JQ1[quant_set1];
}
}
int sign(int a , int b)
{
int x;
x=abs(a);
if (b>0)
return(x);
else return(-x);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -