📄 block.c
字号:
img_y=img_block_y*4;
block_available_up = (pgImage->ipredmode[img_block_x+1][img_block_y] >=0); /// can use frm
block_available_left = (pgImage->ipredmode[img_block_x][img_block_y+1] >=0); /// can use frm
block_available_up_left = (pgImage->ipredmode[img_block_x][img_block_y] >=0);
block_available_left_down = 0; // undecoded
block_available_up_right = 0; // undecoded
// end
i = (img_x & 15);
j = (img_y & 15);
// form predictor pels
if (block_available_up)
{
P_A = imgY[img_y-1][img_x+0];
P_B = imgY[img_y-1][img_x+1];
P_C = imgY[img_y-1][img_x+2];
P_D = imgY[img_y-1][img_x+3];
P_E = P_F = P_G = P_H = P_D; //last 5 pixels is equivalent.
}
else
P_A = P_B = P_C = P_D = P_E = P_F = P_G = P_H = 128;
//
if (block_available_left)
{
P_I = imgY[img_y+0][img_x-1];
P_J = imgY[img_y+1][img_x-1];
P_K = imgY[img_y+2][img_x-1];
P_L = imgY[img_y+3][img_x-1];
P_M = P_N = P_O = P_P = P_L;
}
else
P_I = P_J = P_K = P_L = P_M = P_N = P_O = P_P = 128;
//luma r0 picking up
if (block_available_up_left)
P_X = imgY[img_y-1][img_x-1];
else
P_X = 128;
//predmode selection
// 9 modes proposed by HUST in AVS_Mxxxx
switch (predmode)
{
case DC_PRED: // DC prediction
s0 = 0;
if (block_available_up && block_available_left)
{
// no edge
s0 = (P_A + P_B + P_C + P_D + P_I + P_J + P_K + P_L + 4)/(2*BLOCK_SIZE);
}
else if (!block_available_up && block_available_left)
{
// upper edge
s0 = (P_I + P_J + P_K + P_L + 2)/BLOCK_SIZE;
}
else if (block_available_up && !block_available_left)
{
// left edge
s0 = (P_A + P_B + P_C + P_D + 2)/BLOCK_SIZE;
}
else //if (!block_available_up && !block_available_left)
{
// top left corner, nothing to predict from
s0 = 128;
}
for (j=0; j < BLOCK_SIZE; j++)
for (i=0; i < BLOCK_SIZE; i++)
pgcurrMB->pred_sample[b8][b4][i][j] = s0; // store DC prediction
break;
case VERT_PRED: // vertical prediction from block above
for(j=0;j<BLOCK_SIZE;j++)
for(i=0;i<BLOCK_SIZE;i++)
pgcurrMB->pred_sample[b8][b4][i][j]=imgY[img_y-1][img_x+i];// store predicted 4x4 block
break;
case HOR_PRED: // horisontal prediction from left block
for(j=0;j<BLOCK_SIZE;j++)
for(i=0;i<BLOCK_SIZE;i++)
pgcurrMB->pred_sample[b8][b4][i][j]=imgY[img_y+j][img_x-1]; // store predicted 4x4 block
break;
case DOWN_RIGHT_PRED:
pgcurrMB->pred_sample[b8][b4][0][3] = (P_L + 2*P_K + P_J + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][2] =
pgcurrMB->pred_sample[b8][b4][1][3] = (P_K + 2*P_J + P_I + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][1] =
pgcurrMB->pred_sample[b8][b4][1][2] =
pgcurrMB->pred_sample[b8][b4][2][3] = (P_J + 2*P_I + P_X + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][0] =
pgcurrMB->pred_sample[b8][b4][1][1] =
pgcurrMB->pred_sample[b8][b4][2][2] =
pgcurrMB->pred_sample[b8][b4][3][3] = (P_I + 2*P_X + P_A + 2) / 4;
pgcurrMB->pred_sample[b8][b4][1][0] =
pgcurrMB->pred_sample[b8][b4][2][1] =
pgcurrMB->pred_sample[b8][b4][3][2] = (P_X + 2*P_A + P_B + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][0] =
pgcurrMB->pred_sample[b8][b4][3][1] = (P_A + 2*P_B + P_C + 2) / 4;
pgcurrMB->pred_sample[b8][b4][3][0] = (P_B + 2*P_C + P_D + 2) / 4;
break;
case DOWN_LEFT_PRED:
pgcurrMB->pred_sample[b8][b4][0][0] = (P_A + P_C + P_I + P_K + 2*(P_B + P_J) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][1][0] =
pgcurrMB->pred_sample[b8][b4][0][1] = (P_B + P_D + P_J + P_L + 2*(P_C + P_K) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][2][0] =
pgcurrMB->pred_sample[b8][b4][1][1] =
pgcurrMB->pred_sample[b8][b4][0][2] = (P_C + P_E + P_K + P_M + 2*(P_D + P_L) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][3][0] =
pgcurrMB->pred_sample[b8][b4][2][1] =
pgcurrMB->pred_sample[b8][b4][1][2] =
pgcurrMB->pred_sample[b8][b4][0][3] = (P_D + P_F + P_L + P_N + 2*(P_E + P_M) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][3][1] =
pgcurrMB->pred_sample[b8][b4][2][2] =
pgcurrMB->pred_sample[b8][b4][1][3] = (P_E + P_G + P_M + P_O + 2*(P_F + P_N) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][3][2] =
pgcurrMB->pred_sample[b8][b4][2][3] = (P_F + P_H + P_N + P_P + 2*(P_G + P_O) + 4) / 8;
pgcurrMB->pred_sample[b8][b4][3][3] = (P_G + P_O + P_H + P_P + 2) / 4;
break;
case VERT_RIGHT_PRED: // 5 make VERT_RIGHT_PRED Prediction
pgcurrMB->pred_sample[b8][b4][0][0] =
pgcurrMB->pred_sample[b8][b4][1][2] = (P_X + P_A + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][0] =
pgcurrMB->pred_sample[b8][b4][2][2] = (P_A + P_B + 1) / 2;
pgcurrMB->pred_sample[b8][b4][2][0] =
pgcurrMB->pred_sample[b8][b4][3][2] = (P_B + P_C + 1) / 2;
pgcurrMB->pred_sample[b8][b4][3][0] = (P_C + P_D + 1) / 2;
pgcurrMB->pred_sample[b8][b4][0][1] =
pgcurrMB->pred_sample[b8][b4][1][3] = (P_I + 2*P_X + P_A + 2) / 4;
pgcurrMB->pred_sample[b8][b4][1][1] =
pgcurrMB->pred_sample[b8][b4][2][3] = (P_X + 2*P_A + P_B + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][1] =
pgcurrMB->pred_sample[b8][b4][3][3] = (P_A + 2*P_B + P_C + 2) / 4;
pgcurrMB->pred_sample[b8][b4][3][1] = (P_B + 2*P_C + P_D + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][2] = (P_X + 2*P_I + P_J + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][3] = (P_I + 2*P_J + P_K + 2) / 4;
break;
case HOR_DOWN_PRED: // 6 make HOR_DOWN_PRED Prediction
pgcurrMB->pred_sample[b8][b4][0][0] =
pgcurrMB->pred_sample[b8][b4][2][1] = (P_X + P_I + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][0] =
pgcurrMB->pred_sample[b8][b4][3][1] = (P_I + 2*P_X + P_A + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][0] = (P_X + 2*P_A + P_B + 2) / 4;
pgcurrMB->pred_sample[b8][b4][3][0] = (P_A + 2*P_B + P_C + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][1] =
pgcurrMB->pred_sample[b8][b4][2][2] = (P_I + P_J + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][1] =
pgcurrMB->pred_sample[b8][b4][3][2] = (P_X + 2*P_I + P_J + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][2] =
pgcurrMB->pred_sample[b8][b4][2][3] = (P_J + P_K + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][2] =
pgcurrMB->pred_sample[b8][b4][3][3] = (P_I + 2*P_J + P_K + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][3] = (P_K + P_L + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][3] = (P_J + 2*P_K + P_L + 2) / 4;
break; // end HOR_DOWN_PRED
case VERT_LEFT_PRED: // 7 make VERT_LEFT_PRED Prediction
pgcurrMB->pred_sample[b8][b4][0][0] = (P_A + P_B + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][0] =
pgcurrMB->pred_sample[b8][b4][0][2] = (P_B + P_C + 1) / 2;
pgcurrMB->pred_sample[b8][b4][2][0] =
pgcurrMB->pred_sample[b8][b4][1][2] = (P_C + P_D + 1) / 2;
pgcurrMB->pred_sample[b8][b4][3][0] =
pgcurrMB->pred_sample[b8][b4][2][2] = (P_D + P_E + 1) / 2;
pgcurrMB->pred_sample[b8][b4][3][2] = (P_E + P_F + 1) / 2;
pgcurrMB->pred_sample[b8][b4][0][1] = (P_A + 2*P_B + P_C + 2) / 4;
pgcurrMB->pred_sample[b8][b4][1][1] =
pgcurrMB->pred_sample[b8][b4][0][3] = (P_B + 2*P_C + P_D + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][1] =
pgcurrMB->pred_sample[b8][b4][1][3] = (P_C + 2*P_D + P_E + 2) / 4;
pgcurrMB->pred_sample[b8][b4][3][1] =
pgcurrMB->pred_sample[b8][b4][2][3] = (P_D + 2*P_E + P_F + 2) / 4;
pgcurrMB->pred_sample[b8][b4][3][3] = (P_E + 2*P_F + P_G + 2) / 4;
break; // end VERT_LEFT_PRED
case HOR_UP_PRED: // 7 make HOR_UP_PRED Prediction
pgcurrMB->pred_sample[b8][b4][0][0] = (P_I + P_J + 1) / 2;
pgcurrMB->pred_sample[b8][b4][1][0] = (P_I + 2*P_J + P_K + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][0] =
pgcurrMB->pred_sample[b8][b4][0][1] = (P_J + P_K + 1) / 2;
pgcurrMB->pred_sample[b8][b4][3][0] =
pgcurrMB->pred_sample[b8][b4][1][1] = (P_J + 2*P_K + P_L + 2) / 4;
pgcurrMB->pred_sample[b8][b4][2][1] =
pgcurrMB->pred_sample[b8][b4][0][2] = (P_K + P_L + 1) / 2;
pgcurrMB->pred_sample[b8][b4][3][1] =
pgcurrMB->pred_sample[b8][b4][1][2] = (P_K + 2*P_L + P_M + 2) / 4;
pgcurrMB->pred_sample[b8][b4][0][3] =
pgcurrMB->pred_sample[b8][b4][2][2] =
pgcurrMB->pred_sample[b8][b4][3][2] =
pgcurrMB->pred_sample[b8][b4][1][3] =
pgcurrMB->pred_sample[b8][b4][2][3] =
pgcurrMB->pred_sample[b8][b4][3][3] = P_L;
break; // end HOR_UP_PRED
default:
printf("Error: illegal prediction mode input: %d\n",predmode);
return SEARCH_SYNC;
break;
}
#if TRACE
for(j=0;j<4;j++)
for(i=0;i<4;i++)
MB_intrapred_Y[((b8>>1)<<3)+((b4>>1)<<2)+j][((b8 &1)<<3)+((b4 &1)<<2)+i] = pgcurrMB->pred_sample[b8][b4][i][j];
#endif
return DECODING_OK;
}
/*!
*************************************************************************
* \brief:
* intra chroma prediction based on 4x4 block
*************************************************************************
*/
void intrapred_chroma_4x4(int mb_x, int mb_y, int b4, int mode)
{
#define CBS 4 // chroma block size
unsigned char edgepixu[20];
#define EU (edgepixu + 10)
unsigned char edgepixv[20];
#define EV (edgepixv + 10)
int hlineU[CBS],vlineU[CBS];
int hlineV[CBS],vlineV[CBS];
int x,y;
int uv;
int u0,v0;
int bx = (b4 &1)<<2;
int by = (b4>>1)<<2;
int img_cx = (mb_x << 3) + bx; // block pel x
int img_cy = (mb_y << 3) + by; // block pel y
//MZ
int mb_available_up = (pgImage->ipredmode[(mb_x<<2)+1][(mb_y<<2)]>=0);
int mb_available_left = (pgImage->ipredmode[(mb_x<<2)][(mb_y<<2)+1] >=0); /// can use frm
int mb_available_up_left = (pgImage->ipredmode[(mb_x<<2)][(mb_y<<2)] >=0);
//
int block_available_up = (b4 ==0||b4==1)?mb_available_up:1;
int block_available_left = (b4 ==0||b4==2)?mb_available_left:1;
int block_available_up_left = (b4==0) ? mb_available_up_left : ((b4==1) ? mb_available_up : ((b4==2) ? mb_available_left : 1 ));
assert(b4>=0 && b4 <=3);
uv = 0;
if (block_available_up)
{
for(x=0;x<CBS;x++) EU[x+1] = imgUV[uv][img_cy-1][img_cx+x];
for(x=0;x<CBS;x++) EU[1+x+CBS] = EU[CBS];
}
if (block_available_left)
{
for(y=0;y<CBS;y++) EU[-1-y] = imgUV[uv][img_cy+y][img_cx-1];
for(y=0;y<CBS;y++) EU[-1-y-CBS] = EU[-CBS];
}
if (block_available_up_left)
EU[0] = imgUV[uv][img_cy-1][img_cx-1];
else
EU[0] = 128;
uv = 1;
if (block_available_up)
{
for(x=0;x<CBS;x++) EV[x+1] = imgUV[uv][img_cy-1][img_cx+x];
for(x=0;x<CBS;x++) EV[1+x+CBS] = EV[CBS];
}
if (block_available_left)
{
for(y=0;y<CBS;y++) EV[-1-y] = imgUV[uv][img_cy+y][img_cx-1];
for(y=0;y<CBS;y++) EV[-1-y-CBS] = EV[-CBS];
}
// picking up chroma r0
if (block_available_up_left)
EV[0] = imgUV[uv][img_cy-1][img_cx-1];
else
EV[0] = 128;
switch (mode)
{
// chroma DC_pred:
case DC_PRED_8:
u0 = v0 = 0;
if (block_available_up && block_available_left)
{
// no edge
u0 = (EU[1] + EU[2] + EU[3] + EU[4] + EU[-1] + EU[-2] + EU[-3] + EU[-4] + 4)/(2*CBS);
v0 = (EV[1] + EV[2] + EV[3] + EV[4] + EV[-1] + EV[-2] + EV[-3] + EV[-4] + 4)/(2*CBS);
}
else if (!block_available_up && block_available_left)
{
// left edge
u0 = (EU[-1] + EU[-2] + EU[-3] + EU[-4] + 2)/CBS;
v0 = (EV[-1] + EV[-2] + EV[-3] + EV[-4] + 2)/CBS;
}
else if (block_available_up && !block_available_left)
{
// upper edge
u0 = (EU[1] + EU[2] + EU[3] + EU[4] + 2)/CBS;
v0 = (EV[1] + EV[2] + EV[3] + EV[4] + 2)/CBS;
}
else //if (!block_available_up && !block_available_left)
{
// top left corner, nothing to predict from
u0 = v0 = 128;
}
for (y=0; y < BLOCK_SIZE; y++)
{
for (x=0; x < BLOCK_SIZE; x++)
{
// store DC prediction
pgcurrMB->pred_sample[4][b4][x][y] = u0;
pgcurrMB->pred_sample[5][b4][x][y] = v0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -