📄 transform8x8.c
字号:
img->mprr_3[HOR_DOWN_PRED][5][3] =
img->mprr_3[HOR_DOWN_PRED][6][5] =
img->mprr_3[HOR_DOWN_PRED][7][7] = (P_S + P_U + 2*P_T + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][5][1] =
img->mprr_3[HOR_DOWN_PRED][6][3] =
img->mprr_3[HOR_DOWN_PRED][7][5] = (P_T + P_V + 2*P_U + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][6][1] =
img->mprr_3[HOR_DOWN_PRED][7][3] = (P_U + P_W + 2*P_V + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][7][1] = (P_V + P_X + 2*P_W + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][2] =
img->mprr_3[HOR_DOWN_PRED][1][4] =
img->mprr_3[HOR_DOWN_PRED][2][6] = (P_Z + P_B + 2*P_A + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][3] =
img->mprr_3[HOR_DOWN_PRED][1][5] =
img->mprr_3[HOR_DOWN_PRED][2][7] = (P_A + P_C + 2*P_B + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][4] =
img->mprr_3[HOR_DOWN_PRED][1][6] = (P_B + P_D + 2*P_C + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][5] =
img->mprr_3[HOR_DOWN_PRED][1][7] = (P_C + P_E + 2*P_D + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][6] = (P_D + P_F + 2*P_E + 2) >> 2;
img->mprr_3[HOR_DOWN_PRED][0][7] = (P_E + P_G + 2*P_F + 2) >> 2;
}
///////////////////////////////////
// make horizontal up prediction
///////////////////////////////////
if (block_available_left)
{
img->mprr_3[HOR_UP_PRED][0][0] = (P_Q + P_R + 1) >> 1;
img->mprr_3[HOR_UP_PRED][1][0] =
img->mprr_3[HOR_UP_PRED][0][2] = (P_R + P_S + 1) >> 1;
img->mprr_3[HOR_UP_PRED][2][0] =
img->mprr_3[HOR_UP_PRED][1][2] =
img->mprr_3[HOR_UP_PRED][0][4] = (P_S + P_T + 1) >> 1;
img->mprr_3[HOR_UP_PRED][3][0] =
img->mprr_3[HOR_UP_PRED][2][2] =
img->mprr_3[HOR_UP_PRED][1][4] =
img->mprr_3[HOR_UP_PRED][0][6] = (P_T + P_U + 1) >> 1;
img->mprr_3[HOR_UP_PRED][4][0] =
img->mprr_3[HOR_UP_PRED][3][2] =
img->mprr_3[HOR_UP_PRED][2][4] =
img->mprr_3[HOR_UP_PRED][1][6] = (P_U + P_V + 1) >> 1;
img->mprr_3[HOR_UP_PRED][5][0] =
img->mprr_3[HOR_UP_PRED][4][2] =
img->mprr_3[HOR_UP_PRED][3][4] =
img->mprr_3[HOR_UP_PRED][2][6] = (P_V + P_W + 1) >> 1;
img->mprr_3[HOR_UP_PRED][6][0] =
img->mprr_3[HOR_UP_PRED][5][2] =
img->mprr_3[HOR_UP_PRED][4][4] =
img->mprr_3[HOR_UP_PRED][3][6] = (P_W + P_X + 1) >> 1;
img->mprr_3[HOR_UP_PRED][4][6] =
img->mprr_3[HOR_UP_PRED][4][7] =
img->mprr_3[HOR_UP_PRED][5][4] =
img->mprr_3[HOR_UP_PRED][5][5] =
img->mprr_3[HOR_UP_PRED][5][6] =
img->mprr_3[HOR_UP_PRED][5][7] =
img->mprr_3[HOR_UP_PRED][6][2] =
img->mprr_3[HOR_UP_PRED][6][3] =
img->mprr_3[HOR_UP_PRED][6][4] =
img->mprr_3[HOR_UP_PRED][6][5] =
img->mprr_3[HOR_UP_PRED][6][6] =
img->mprr_3[HOR_UP_PRED][6][7] =
img->mprr_3[HOR_UP_PRED][7][0] =
img->mprr_3[HOR_UP_PRED][7][1] =
img->mprr_3[HOR_UP_PRED][7][2] =
img->mprr_3[HOR_UP_PRED][7][3] =
img->mprr_3[HOR_UP_PRED][7][4] =
img->mprr_3[HOR_UP_PRED][7][5] =
img->mprr_3[HOR_UP_PRED][7][6] =
img->mprr_3[HOR_UP_PRED][7][7] = P_X;
img->mprr_3[HOR_UP_PRED][6][1] =
img->mprr_3[HOR_UP_PRED][5][3] =
img->mprr_3[HOR_UP_PRED][4][5] =
img->mprr_3[HOR_UP_PRED][3][7] = (P_W + 3*P_X + 2) >> 2;
img->mprr_3[HOR_UP_PRED][5][1] =
img->mprr_3[HOR_UP_PRED][4][3] =
img->mprr_3[HOR_UP_PRED][3][5] =
img->mprr_3[HOR_UP_PRED][2][7] = (P_X + P_V + 2*P_W + 2) >> 2;
img->mprr_3[HOR_UP_PRED][4][1] =
img->mprr_3[HOR_UP_PRED][3][3] =
img->mprr_3[HOR_UP_PRED][2][5] =
img->mprr_3[HOR_UP_PRED][1][7] = (P_W + P_U + 2*P_V + 2) >> 2;
img->mprr_3[HOR_UP_PRED][3][1] =
img->mprr_3[HOR_UP_PRED][2][3] =
img->mprr_3[HOR_UP_PRED][1][5] =
img->mprr_3[HOR_UP_PRED][0][7] = (P_V + P_T + 2*P_U + 2) >> 2;
img->mprr_3[HOR_UP_PRED][2][1] =
img->mprr_3[HOR_UP_PRED][1][3] =
img->mprr_3[HOR_UP_PRED][0][5] = (P_U + P_S + 2*P_T + 2) >> 2;
img->mprr_3[HOR_UP_PRED][1][1] =
img->mprr_3[HOR_UP_PRED][0][3] = (P_T + P_R + 2*P_S + 2) >> 2;
img->mprr_3[HOR_UP_PRED][0][1] = (P_S + P_Q + 2*P_R + 2) >> 2;
}
}
/*!
*************************************************************************************
* \brief
* Prefiltering for Intra8x8 prediction
*************************************************************************************
*/
void LowPassForIntra8x8Pred(int *PredPel, int block_up_left, int block_up, int block_left)
{
int i;
int LoopArray[25];
for(i = 0; i < 25; i++)
LoopArray[i] = PredPel[i] ;
if(block_up)
{
if(block_up_left)
{
LoopArray[1] = ((&P_Z)[0] + ((&P_Z)[1]<<1) + (&P_Z)[2] + 2)>>2;
}
else
LoopArray[1] = ((&P_Z)[1] + ((&P_Z)[1]<<1) + (&P_Z)[2] + 2)>>2;
for(i = 2; i <16; i++)
{
LoopArray[i] = ((&P_Z)[i-1] + ((&P_Z)[i]<<1) + (&P_Z)[i+1] + 2)>>2;
}
LoopArray[16] = (P_P + (P_P<<1) + P_O + 2)>>2;
}
if(block_up_left)
{
if(block_up && block_left)
{
LoopArray[0] = (P_Q + (P_Z<<1) + P_A +2)>>2;
}
else
{
if(block_up)
LoopArray[0] = (P_Z + (P_Z<<1) + P_A +2)>>2;
else
if(block_left)
LoopArray[0] = (P_Z + (P_Z<<1) + P_Q +2)>>2;
}
}
if(block_left)
{
if(block_up_left)
LoopArray[17] = (P_Z + (P_Q<<1) + P_R + 2)>>2;
else
LoopArray[17] = (P_Q + (P_Q<<1) + P_R + 2)>>2;
for(i = 18; i <24; i++)
{
LoopArray[i] = ((&P_Z)[i-1] + ((&P_Z)[i]<<1) + (&P_Z)[i+1] + 2)>>2;
}
LoopArray[24] = (P_W + (P_X<<1) + P_X + 2)>>2;
}
for(i = 0; i < 25; i++)
PredPel[i] = LoopArray[i];
}
/*!
*************************************************************************************
* \brief
* R-D Cost for an 8x8 Intra block
*************************************************************************************
*/
double RDCost_for_8x8IntraBlocks(int *nonzero, int b8, int ipmode, double lambda, double min_rdcost, int mostProbableMode)
{
double rdcost = 0.0;
int dummy, x, y, rate;
int64 distortion = 0;
int block_x = 8*(b8 & 0x01);
int block_y = 8*(b8 >> 1);
int pic_pix_x = img->pix_x+block_x;
int pic_pix_y = img->pix_y+block_y;
int pic_opix_y = img->opix_y+block_y;
imgpel **imgY_orig = imgY_org;
imgpel **imgY = enc_picture->imgY;
Slice *currSlice = img->currentSlice;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
SyntaxElement *currSE = &img->MB_SyntaxElements[currMB->currSEnr];
const int *partMap = assignSE2partition[input->partition_mode];
DataPartition *dataPart;
//===== perform DCT, Q, IQ, IDCT, Reconstruction =====
dummy = 0;
#ifdef USE_INTRA_MDDT
if(input->UseIntraMDDT)
{
*nonzero = (ipmode == 2) ?
dct_luma8x8 (b8, &dummy, 1, ipmode) :
klt_luma8x8_sep_fast (b8, &dummy, ipmode);
}
else
*nonzero = dct_luma8x8 (b8, &dummy, 1, ipmode) ;
#else
*nonzero = dct_luma8x8 (b8, &dummy, 1);
#endif
//===== get distortion (SSD) of 8x8 block =====
for (y=0; y<8; y++)
for (x=pic_pix_x; x<pic_pix_x+8; x++)
#ifdef INTERNAL_BIT_DEPTH_INCREASE
distortion += SQR_DEPTH(imgY_orig[pic_opix_y+y][x], imgY[pic_pix_y+y][x], input->BitDepthLuma, img->BitDepthIncrease);
#else
distortion += img->quad [imgY_orig[pic_opix_y+y][x] - imgY[pic_pix_y+y][x]];
#endif
//===== RATE for INTRA PREDICTION MODE (SYMBOL MODE MUST BE SET TO UVLC) =====
currSE->value1 = (mostProbableMode == ipmode) ? -1 : ipmode < mostProbableMode ? ipmode : ipmode-1;
//--- set position and type ---
currSE->context = b8;
currSE->type = SE_INTRAPREDMODE;
//--- choose data partition ---
if (img->type!=B_SLICE)
dataPart = &(currSlice->partArr[partMap[SE_INTRAPREDMODE]]);
else
dataPart = &(currSlice->partArr[partMap[SE_BFRAME]]);
//--- encode and update rate ---
if (input->symbol_mode == UVLC)
writeSyntaxElement_Intra4x4PredictionMode(currSE, dataPart);
else
{
currSE->writing = writeIntraPredMode_CABAC;
dataPart->writeSyntaxElement (currSE, dataPart);
}
rate = currSE->len;
currSE++;
currMB->currSEnr++;
//===== RATE for LUMINANCE COEFFICIENTS =====
if (input->symbol_mode == UVLC)
{
int b4;
for(b4=0; b4<4; b4++)
rate += writeCoeff4x4_CAVLC (LUMA, b8, b4, 0);
}
else
{
rate += writeLumaCoeff8x8_CABAC (b8, 1);
}
rdcost = (double)distortion + lambda*(double)rate;
if(img->residue_transform_flag)
return (double)rate;
else
return rdcost;
}
/*!
************************************************************************
* \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:
* b8: Block position inside a macro block (0,1,2,3).
*
* \par Output:
* nonzero: 0 if no levels are nonzero. 1 if there are nonzero levels.
* coeff_cost: Counter for nonzero coefficients, used to discard expensive levels.
************************************************************************
*/
#define MC(coeff) ((coeff)&3)
#ifdef RDO_Q //TREL_CAVLC
extern const byte SNGL_SCAN[16][2];
extern const byte FIELD_SCAN[16][2];
void TrellisCAVLC_Q(int m4[4][4], levelDataStruct *levelData, int *levelTrellis, int block_type, int b8, int b4, int coeff_num, double lambda);
void TrellisCAVLC8x8(int img_m7[16][16], int q_bits, int qp_rem, int **levelscale, int **leveloffset, int *levelTrellis, int b8, double lambda)
{
int i, j, i4, j4, coeff_ctr, MCcoeff, scan_poss4x4;
int m4[4][4][4];
int level;
int levelTrellis4x4[4][16];
levelDataStruct levelData[64], levelData4x4[4][16];
#ifdef INTERNAL_BIT_DEPTH_INCREASE
double normFact=pow(2,(2*Q_BITS_8+9))*(1<<(2*img->BitDepthIncrease));
#else
double normFact=pow(2,(2*Q_BITS_8+9));
#endif
double err;
short is_field_mode = (img->field_picture || ( img->MbaffFrameFlag && img->mb_data[img->current_mb_nr].mb_field));
const byte (*pos_scan4x4)[2] = is_field_mode ? FIELD_SCAN : SNGL_SCAN;
int lowerInt, ii;
//if(input->UseRDO_Q)
{
for (coeff_ctr=0;coeff_ctr < 64;coeff_ctr++)
{
if (is_field_mode)
{ // Alternate scan for field coding
i=FIELD_SCAN8x8[coeff_ctr][0];
j=FIELD_SCAN8x8[coeff_ctr][1];
}
else
{
i=SNGL_SCAN8x8[coeff_ctr][0];
j=SNGL_SCAN8x8[coeff_ctr][1];
}
levelData[coeff_ctr].levelDouble=absm(img_m7[j][i]*levelscale[i][j]);
level=(int) (levelData[coeff_ctr].levelDouble>>q_bits);
lowerInt=(((int)levelData[coeff_ctr].levelDouble-(level<<q_bits))<(1<<(q_bits-1)))? 1 : 0;
levelData[coeff_ctr].level[0]=0;
if (level==0 && lowerInt==1)
{
levelData[coeff_ctr].noLevels=1;
}
else if (level==0 && lowerInt==0)
{
levelData[coeff_ctr].level[1] = level+1;
levelData[coeff_ctr].noLevels=2;
}
else if (lev
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -