📄 transform8x8.c
字号:
else
upMode = top_block.available ? img->ipredmode [top_block.pos_y ][top_block.pos_x ] : -1;
if(b8 & 0x01)
leftMode = left_block.available ? img->ipredmode8x8[left_block.pos_y][left_block.pos_x] : -1;
else
leftMode = left_block.available ? img->ipredmode[left_block.pos_y][left_block.pos_x] : -1;
mostProbableMode = (upMode < 0 || leftMode < 0) ? DC_PRED : upMode < leftMode ? upMode : leftMode;
*min_cost = INT_MAX;
ipmode_DPCM = NO_INTRA_PMODE; //For residual DPCM
//===== INTRA PREDICTION FOR 8x8 BLOCK =====
intrapred_8x8 (currMB, PLANE_Y, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
if(img->P444_joined)
{
select_plane(PLANE_U);
intrapred_8x8(currMB, PLANE_U, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
select_plane(PLANE_V);
intrapred_8x8(currMB, PLANE_V, pic_pix_x, pic_pix_y, &left_available, &up_available, &all_available);
select_plane(PLANE_Y);
}
//===== LOOP OVER ALL 8x8 INTRA PREDICTION MODES =====
for (ipmode = 0; ipmode < NO_INTRA_PMODE; ipmode++)
{
if( (ipmode==DC_PRED) ||
((ipmode==VERT_PRED||ipmode==VERT_LEFT_PRED||ipmode==DIAG_DOWN_LEFT_PRED) && up_available ) ||
((ipmode==HOR_PRED||ipmode==HOR_UP_PRED) && left_available ) ||
(all_available) )
{
// get prediction and prediction error
for (j=block_y; j < block_y + 8; j++)
{
memcpy(&mb_pred[j][block_x],img->mpr_8x8[0][ipmode][j - block_y], 8 * sizeof(imgpel));
img_org = &pCurImg[img->opix_y+j][pic_opix_x];
img_prd = &mb_pred[j][block_x];
residual = &mb_ores[j][block_x];
for (i=0; i<8; i++)
{
*residual++ = *img_org++ - *img_prd++;
}
}
if(img->P444_joined)
{
for (k = PLANE_U; k <= PLANE_V; k++)
{
for (j=0; j<8; j++)
{
memcpy(&img->mb_pred[k][block_y+j][block_x],img->mpr_8x8[k][ipmode][j], 8 * sizeof(imgpel));
for (i=0; i<8; i++)
{
img->mb_ores[k][block_y+j][block_x+i] = (int) (pImgOrg[k][pic_opix_y+j][pic_opix_x+i] - img->mpr_8x8[k][ipmode][j][i]);
img->mb_ores[k][block_y+j][block_x+i] = img->mb_ores[k][block_y+j][block_x+i]; // line is temporary until we fix code to use img->mb_ores
}
}
}
}
ipmode_DPCM=ipmode;
//===== store the coding state =====
// store_coding_state_cs_cm(currMB);
// get and check rate-distortion cost
if ((rdcost = RDCost_for_8x8IntraBlocks (currMB, &c_nz, b8, ipmode, lambda, min_rdcost, mostProbableMode, c_nzCbCr)) < min_rdcost)
{
//--- set coefficients ---
memcpy(cofAC8x8[b8][0][0],img->cofAC[b8][0][0], 4 * 2 * 65 * sizeof(int));
//--- set reconstruction ---
for (y=0; y<8; y++)
{
memcpy(rec8x8[0][y],&enc_picture->imgY[pic_pix_y+y][pic_pix_x], 8 * sizeof(imgpel));
}
if (img->AdaptiveRounding)
{
for (j=block_y; j<block_y + 8; j++)
memcpy(&fadjust8x8[1][j][block_x],&img->fadjust8x8[1][j][block_x], 8 * sizeof(int));
if (img->P444_joined)
{
for (j=block_y; j<block_y + 8; j++)
{
memcpy(&fadjust8x8Cr[0][1][j][block_x],&img->fadjust8x8Cr[0][1][j][block_x], 8 * sizeof(int));
memcpy(&fadjust8x8Cr[1][1][j][block_x],&img->fadjust8x8Cr[1][1][j][block_x], 8 * sizeof(int));
}
}
}
if (img->P444_joined)
{
//--- set coefficients ---
for (uv=0; uv < 2; uv++)
{
memcpy(cofAC8x8CbCr[uv][b8][0][0],img->cofAC[4+b8+4*uv][0][0], 2 * 4 * 65 * sizeof(int));
cr_cbp[uv + 1] = c_nzCbCr[uv + 1];
//--- set reconstruction ---
for (y=0; y<8; y++)
{
memcpy(rec8x8[uv + 1][y],&enc_picture->imgUV[uv][pic_pix_y+y][pic_pix_x], 8 * sizeof(imgpel));
}
}
}
//--- flag if dct-coefficients must be coded ---
nonzero = c_nz;
//--- set best mode update minimum cost ---
*min_cost = rdcost;
min_rdcost = rdcost;
best_ipmode = ipmode;
}
reset_coding_state_cs_cm(currMB);
}
}
//===== set intra mode prediction =====
img->ipredmode8x8[pic_block_y][pic_block_x] = (char) best_ipmode;
ipmode_DPCM = best_ipmode; //For residual DPCM
if(img->P444_joined)
{
ColorPlane k;
CbCr_predmode_8x8[b8] = best_ipmode;
for (k = PLANE_U; k <= PLANE_V; k++)
{
cr_cbp[k] = 0;
select_plane(k);
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
{
img->mb_pred[k][block_y+j][block_x+i] = img->mpr_8x8[k][best_ipmode][j][i];
img->mb_ores[k][block_y+j][block_x+i] = pImgOrg[k][img->pix_y+block_y+j][img->pix_x+block_x+i] - img->mpr_8x8[k][best_ipmode][j][i];
}
}
ipmode_DPCM = best_ipmode;
if (pDCT_8x8(currMB, k, b8, &dummy, 1))
cr_cbp[k] = 1;
}
select_plane(PLANE_Y);
}
currMB->intra_pred_modes8x8[4*b8] = (mostProbableMode == best_ipmode)
? -1
: (best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1);
for(j = img->mb_y*4+(b8 >> 1)*2; j < img->mb_y*4+(b8 >> 1)*2 + 2; j++) //loop 4x4s in the subblock for 8x8 prediction setting
memset(&img->ipredmode8x8[j][img->mb_x*4+(b8 & 0x01)*2], best_ipmode, 2 * sizeof(char));
//===== restore coefficients =====
memcpy(img->cofAC[b8][0][0],cofAC8x8[b8][0][0], 4 * 2 * 65 * sizeof(int));
if (img->AdaptiveRounding)
{
for (j=block_y; j< block_y + 8; j++)
memcpy(&img->fadjust8x8[1][j][block_x], &fadjust8x8[1][j][block_x], 8 * sizeof(int));
if (img->P444_joined)
{
for (j=0; j<8; j++)
{
memcpy(&img->fadjust8x8Cr[0][1][block_y+j][block_x], &fadjust8x8Cr[0][1][block_y+j][block_x], 8 * sizeof(int));
memcpy(&img->fadjust8x8Cr[1][1][block_y+j][block_x], &fadjust8x8Cr[1][1][block_y+j][block_x], 8 * sizeof(int));
}
}
}
//===== restore reconstruction and prediction (needed if single coeffs are removed) =====
for (y=0; y<8; y++)
{
memcpy(&enc_picture->imgY[pic_pix_y + y][pic_pix_x], rec8x8[0][y], 8 * sizeof(imgpel));
memcpy(&mb_pred[block_y + y][block_x], img->mpr_8x8[0][best_ipmode][y], 8 * sizeof(imgpel));
}
if (img->P444_joined)
{
//===== restore coefficients =====
memcpy(img->cofAC[4+b8+4*0][0][0], cofAC8x8CbCr[0][b8][0][0], 4 * 2 * 65 * sizeof(int));
memcpy(img->cofAC[4+b8+4*1][0][0], cofAC8x8CbCr[1][b8][0][0], 4 * 2 * 65 * sizeof(int));
//===== restore reconstruction and prediction (needed if single coeffs are removed) =====
for (y=0; y<8; y++)
{
memcpy(&enc_picture->imgUV[0][pic_pix_y+y][pic_pix_x], rec8x8[1][y], 8 * sizeof(imgpel));
memcpy(&enc_picture->imgUV[1][pic_pix_y+y][pic_pix_x], rec8x8[2][y], 8 * sizeof(imgpel));
memcpy(&img->mb_pred[1][block_y+y][block_x], img->mpr_8x8[1][best_ipmode][y], 8 * sizeof(imgpel));
memcpy(&img->mb_pred[2][block_y+y][block_x], img->mpr_8x8[2][best_ipmode][y], 8 * sizeof(imgpel));
}
}
return nonzero;
}
// Notation for comments regarding prediction and predictors.
// The pels of the 4x4 block are labelled a..p. The predictor pels above
// are labelled A..H, from the left I..P, and from above left X, as follows:
//
// Z A B C D E F G H I J K L M N O P
// Q a1 b1 c1 d1 e1 f1 g1 h1
// R a2 b2 c2 d2 e2 f2 g2 h2
// S a3 b3 c3 d3 e3 f3 g3 h3
// T a4 b4 c4 d4 e4 f4 g4 h4
// U a5 b5 c5 d5 e5 f5 g5 h5
// V a6 b6 c6 d6 e6 f6 g6 h6
// W a7 b7 c7 d7 e7 f7 g7 h7
// X a8 b8 c8 d8 e8 f8 g8 h8
// Predictor array index definitions
#define P_Z (PredPel[0])
#define P_A (PredPel[1])
#define P_B (PredPel[2])
#define P_C (PredPel[3])
#define P_D (PredPel[4])
#define P_E (PredPel[5])
#define P_F (PredPel[6])
#define P_G (PredPel[7])
#define P_H (PredPel[8])
#define P_I (PredPel[9])
#define P_J (PredPel[10])
#define P_K (PredPel[11])
#define P_L (PredPel[12])
#define P_M (PredPel[13])
#define P_N (PredPel[14])
#define P_O (PredPel[15])
#define P_P (PredPel[16])
#define P_Q (PredPel[17])
#define P_R (PredPel[18])
#define P_S (PredPel[19])
#define P_T (PredPel[20])
#define P_U (PredPel[21])
#define P_V (PredPel[22])
#define P_W (PredPel[23])
#define P_X (PredPel[24])
/*!
************************************************************************
* \brief
* Make intra 8x8 prediction according to all 9 prediction modes.
* The routine uses left and upper neighbouring points from
* previous coded blocks to do this (if available). Notice that
* inaccessible neighbouring points are signalled with a negative
* value in the predmode array .
*
* \par Input:
* Starting point of current 8x8 block image posision
*
* \par Output:
* none
************************************************************************
*/
void intrapred_8x8(Macroblock *currMB, ColorPlane pl, int img_x,int img_y, int *left_available, int *up_available, int *all_available)
{
int i,j;
int s0;
static imgpel PredPel[25]; // array of predictor pels
imgpel **img_enc = enc_picture->p_curr_img;
imgpel *img_pel;
static imgpel (*cur_pred)[16];
imgpel (*curr_mpr_8x8)[16][16] = img->mpr_8x8[pl];
unsigned int dc_pred_value = img->dc_pred_value;
int *mb_size = img->mb_size[IS_LUMA];
int ioff = (img_x & 15);
int joff = (img_y & 15);
PixelPos pix_a[8];
PixelPos pix_b, pix_c, pix_d;
int block_available_up;
int block_available_left;
int block_available_up_left;
int block_available_up_right;
for (i=0;i<8;i++)
{
getNeighbour(currMB, ioff - 1, joff + i , mb_size, &pix_a[i]);
}
getNeighbour(currMB, ioff , joff - 1, mb_size, &pix_b);
getNeighbour(currMB, ioff + 8, joff - 1, mb_size, &pix_c);
getNeighbour(currMB, ioff - 1, joff - 1, mb_size, &pix_d);
pix_c.available = pix_c.available &&!(ioff == 8 && joff == 8);
if (params->UseConstrainedIntraPred)
{
for (i=0, block_available_left=1; i<8;i++)
block_available_left &= pix_a[i].available ? img->intra_block[pix_a[i].mb_addr]: 0;
block_available_up = pix_b.available ? img->intra_block [pix_b.mb_addr] : 0;
block_available_up_right = pix_c.available ? img->intra_block [pix_c.mb_addr] : 0;
block_available_up_left = pix_d.available ? img->intra_block [pix_d.mb_addr] : 0;
}
else
{
block_available_left = pix_a[0].available;
block_available_up = pix_b.available;
block_available_up_right = pix_c.available;
block_available_up_left = pix_d.available;
}
*left_available = block_available_left;
*up_available = block_available_up;
*all_available = block_available_up && block_available_left && block_available_up_left;
i = (img_x & 15);
j = (img_y & 15);
// form predictor pels
// form predictor pels
if (block_available_up)
{
img_pel = &img_enc[pix_b.pos_y][pix_b.pos_x];
P_A = *(img_pel++);
P_B = *(img_pel++);
P_C = *(img_pel++);
P_D = *(img_pel++);
P_E = *(img_pel++);
P_F = *(img_pel++);
P_G = *(img_pel++);
P_H = *(img_pel);
}
else
{
P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = dc_pred_value;
}
if (block_available_up_right)
{
img_pel = &img_enc[pix_c.pos_y][pix_c.pos_x];
P_I = *(img_pel++);
P_J = *(img_pel++);
P_K = *(img_pel++);
P_L = *(img_pel++);
P_M = *(img_pel++);
P_N = *(img_pel++);
P_O = *(img_pel++);
P_P = *(img_pel);
}
else
{
P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = P_H;
}
if (block_available_left)
{
P_Q = img_enc[pix_a[0].pos_y][pix_a[0].pos_x];
P_R = img_enc[pix_a[1].pos_y][pix_a[1].pos_x];
P_S = img_enc[pix_a[2].pos_y][pix_a[2].pos_x];
P_T = img_enc[pix_a[3].pos_y][pix_a[3].pos_x];
P_U = img_enc[pix_a[4].pos_y][pix_a[4].pos_x];
P_V = img_enc[pix_a[5].pos_y][pix_a[5].pos_x];
P_W = img_enc[pix_a[6].pos_y][pix_a[6].pos_x];
P_X = img_enc[pix_a[7].pos_y][pix_a[7].pos_x];
}
else
{
P_Q = P_R = P_S = P_T = P_U = P_V = P_W = P_X = dc_pred_value;
}
if (block_available_up_left)
{
P_Z = img_enc[pix_d.pos_y][pix_d.pos_x];
}
else
{
P_Z = dc_pred_value;
}
for(i=0;i<9;i++)
curr_mpr_8x8[i][0][0]=-1;
LowPassForIntra8x8Pred(&(P_Z), block_available_up_left, block_available_up, block_available_left);
///////////////////////////////
// make DC prediction
///////////////////////////////
s0 = 0;
if (block_available_up && block_available_left)
{
// no edge
s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H + P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 4);
}
else if (!block_available_up && block_available_left)
{
// upper edge
s0 = rshift_rnd_sf((P_Q + P_R + P_S + P_T + P_U + P_V + P_W + P_X), 3);
}
else if (block_available_up && !block_available_left)
{
// left edge
s0 = rshift_rnd_sf((P_A + P_B + P_C + P_D + P_E + P_F + P_G + P_H), 3);
}
else //if (!block_available_up && !block_available_left)
{
// top left corner, nothing to predict from
s0 = dc_pred_value;
}
// store DC prediction
cur_pred = curr_mpr_8x8[DC_PRED];
for (j=0; j < BLOCK_SIZE_8x8; j++)
{
for (i=0; i < BLOCK_SIZE_8x8; i++)
{
cur_pred[j][i] = (imgpel) s0;
}
}
///////////////////////////////
// make horiz and vert prediction
///////////////////////////////
cur_pred = curr_mpr_8x8[VERT_PRED];
for (i=0; i < BLOCK_SIZE_8x8; i++)
{
cur_pred[0][i] =
cur_pred[1][i] =
cur_pred[2][i] =
cur_pred[3][i] =
cur_pred[4][i] =
cur_pred[5][i] =
cur_pred[6][i] =
cur_pred[7][i] = (imgpel)(&P_A)[i];
}
if(!block_available_up)
cur_pred[0][0]=-1;
cur_pred = curr_mpr_8x8[HOR_PRED];
for (i=0; i < BLOCK_SIZE_8x8; i++)
{
cur_pred[i][0] =
cur_pred[i][1] =
cur_pred[i][2] =
cur_pred[i][3] =
cur_pred[i][4] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -