macroblock.c
来自「h.264标准和jm」· C语言 代码 · 共 1,891 行 · 第 1/5 页
C
1,891 行
for (i=0; i<currSlice->max_part_nr; i++)
{
dataPart= &(currSlice->partArr[i]);
eep = &(dataPart->ee_cabac);
if( arienco_bits_written(eep) > (input->slice_argument*8))
return TRUE;
}
}
return FALSE;
}
/*!
************************************************************************
* \brief
* Checks the availability of neighboring macroblocks of
* the current macroblock for prediction and context determination;
* marks the unavailable MBs for intra prediction in the
* ipredmode-array by -1. Only neighboring MBs in the causal
* past of the current MB are checked.
************************************************************************
*/
/*
void CheckAvailabilityOfNeighbors()
{
int i,j;
const int mb_width = img->width/MB_BLOCK_SIZE;
const int mb_nr = img->current_mb_nr;
Macroblock *currMB = &img->mb_data[mb_nr];
int pix_y = img->pix_y; // For MB level Frame/field coding
int block_y = img->block_y; // For MB level Frame/field coding
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode)
{
pix_y = img->field_pix_y;
block_y = img->field_block_y;
}
// mark all neighbors as unavailable
for (i=0; i<3; i++)
for (j=0; j<3; j++)
{
img->mb_data[mb_nr].mb_available[i][j]=NULL;
}
img->mb_data[mb_nr].mb_available[1][1]=currMB; // current MB
// Check MB to the left
if(img->pix_x >= MB_BLOCK_SIZE)
{
int remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-1].slice_nr;
// upper blocks
if (remove_prediction || (input->UseConstrainedIntraPred && img->intra_block[mb_nr-1][1]==0))
{
img->ipredmode[img->block_x][img->block_y+1] = -1;
img->ipredmode[img->block_x][img->block_y+2] = -1;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode) // GB
{
if(img->top_field)
{
img->ipredmode_top[img->block_x][block_y+1] = -1;
img->ipredmode_top[img->block_x][block_y+2] = -1;
}
else
{
img->ipredmode_bot[img->block_x][block_y+1] = -1;
img->ipredmode_bot[img->block_x][block_y+2] = -1;
}
}
}
// lower blocks
if (remove_prediction || (input->UseConstrainedIntraPred && img->intra_block[mb_nr-1][3]==0))
{
img->ipredmode[img->block_x][img->block_y+3] = -1;
img->ipredmode[img->block_x][img->block_y+4] = -1;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode) //GB
{
if(img->top_field)
{
img->ipredmode_top[img->block_x][block_y+3] = -1;
img->ipredmode_top[img->block_x][block_y+4] = -1;
}
else
{
img->ipredmode_bot[img->block_x][block_y+3] = -1;
img->ipredmode_bot[img->block_x][block_y+4] = -1;
}
}
}
if (!remove_prediction)
{
currMB->mb_available[1][0]=&(img->mb_data[mb_nr-1]);
}
}
// Check MB above
if(pix_y >= MB_BLOCK_SIZE) // wrong for MBAFF
//if(img->pix_y >= MB_BLOCK_SIZE)
{
int remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-mb_width].slice_nr;
// upper blocks
if (remove_prediction || (input->UseConstrainedIntraPred && img->intra_block[mb_nr-mb_width][2]==0))
{
img->ipredmode[img->block_x+1][img->block_y] = -1;
img->ipredmode[img->block_x+2][img->block_y] = -1;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode) //GB
{
if(img->top_field)
{
img->ipredmode_top[img->block_x+1][block_y] = -1;
img->ipredmode_top[img->block_x+2][block_y] = -1;
}
else
{
img->ipredmode_bot[img->block_x+1][block_y] = -1;
img->ipredmode_bot[img->block_x+2][block_y] = -1;
}
}
}
// lower blocks
if (remove_prediction || (input->UseConstrainedIntraPred && img->intra_block[mb_nr-mb_width][3]==0))
{
img->ipredmode[img->block_x+3][img->block_y] = -1;
img->ipredmode[img->block_x+4][img->block_y] = -1;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode) //GB
{
if(img->top_field)
{
img->ipredmode_top[img->block_x+3][block_y] = -1;
img->ipredmode_top[img->block_x+4][block_y] = -1;
}
else
{
img->ipredmode_bot[img->block_x+3][block_y] = -1;
img->ipredmode_bot[img->block_x+4][block_y] = -1;
}
}
}
if (!remove_prediction)
{
currMB->mb_available[0][1]=&(img->mb_data[mb_nr-mb_width]);
}
}
// Check MB left above
if(img->pix_x >= MB_BLOCK_SIZE && img->pix_y >= MB_BLOCK_SIZE )
{
int remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-mb_width-1].slice_nr;
if (remove_prediction || (input->UseConstrainedIntraPred && img->intra_block[mb_nr-mb_width-1][3]==0))
{
img->ipredmode[img->block_x][img->block_y] = -1;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode) //GB
{
if(img->top_field)
{
img->ipredmode_top[img->block_x][block_y] = -1;
}
else
{
img->ipredmode_bot[img->block_x][block_y] = -1;
}
}
}
if (!remove_prediction)
{
currMB->mb_available[0][0]=&(img->mb_data[mb_nr-mb_width-1]);
}
}
// Check MB right above
if(pix_y >= MB_BLOCK_SIZE && img->pix_x < (img->width-MB_BLOCK_SIZE ))
{
if(currMB->slice_nr == img->mb_data[mb_nr-mb_width+1].slice_nr)
currMB->mb_available[0][2]=&(img->mb_data[mb_nr-mb_width+1]);
}
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive)
currMB->mb_available[0][2] = NULL; // set the prediction from top right MB to zero
}
*/
/*!
************************************************************************
* \brief
* Predict one component of a 4x4 Luma block
************************************************************************
*/
void
OneComponentLumaPrediction4x4 (int* mpred, // --> array of prediction values (row by row)
int pic_pix_x, // <-- absolute horizontal coordinate of 4x4 block
int pic_pix_y, // <-- absolute vertical coordinate of 4x4 block
int* mv, // <-- motion vector
int ref, // <-- reference frame
StorablePicture **list)
{
int incr;
pel_t** ref_pic;
int pix_add = 4;
int j0 = (pic_pix_y << 2) + mv[1], j1=j0+pix_add, j2=j1+pix_add, j3=j2+pix_add;
int i0 = (pic_pix_x << 2) + mv[0], i1=i0+pix_add, i2=i1+pix_add, i3=i2+pix_add;
pel_t (*get_pel) (pel_t**, int, int) = UMVPelY_14;
// Tian Dong: PLUS1, June 06, 2002
incr = (ref==-1 ? (!img->fld_type&&enc_picture!=enc_frame_picture): direct_mode ? (!img->fld_type&&enc_picture!=enc_frame_picture) : (enc_picture!=enc_frame_picture)) ;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive)
incr = (ref==-1 ? (img->top_field&&img->field_mode): direct_mode ? (img->top_field&&img->field_mode):img->field_mode);
ref_pic = list[ref]->imgY_ups;
*mpred++ = get_pel (ref_pic, j0, i0);
*mpred++ = get_pel (ref_pic, j0, i1);
*mpred++ = get_pel (ref_pic, j0, i2);
*mpred++ = get_pel (ref_pic, j0, i3);
*mpred++ = get_pel (ref_pic, j1, i0);
*mpred++ = get_pel (ref_pic, j1, i1);
*mpred++ = get_pel (ref_pic, j1, i2);
*mpred++ = get_pel (ref_pic, j1, i3);
*mpred++ = get_pel (ref_pic, j2, i0);
*mpred++ = get_pel (ref_pic, j2, i1);
*mpred++ = get_pel (ref_pic, j2, i2);
*mpred++ = get_pel (ref_pic, j2, i3);
*mpred++ = get_pel (ref_pic, j3, i0);
*mpred++ = get_pel (ref_pic, j3, i1);
*mpred++ = get_pel (ref_pic, j3, i2);
*mpred++ = get_pel (ref_pic, j3, i3);
}
/*!
************************************************************************
* \brief
* copy foward/backward prediction values of one component of a 4x4 Luma block
************************************************************************
*/
void
copyblock4x4 (int* mpred, // --> array of prediction values (row by row)
int block[BLOCK_SIZE][BLOCK_SIZE])
{
*mpred++ = block[0][0];
*mpred++ = block[1][0];
*mpred++ = block[2][0];
*mpred++ = block[3][0];
*mpred++ = block[0][1];
*mpred++ = block[1][1];
*mpred++ = block[2][1];
*mpred++ = block[3][1];
*mpred++ = block[0][2];
*mpred++ = block[1][2];
*mpred++ = block[2][2];
*mpred++ = block[3][2];
*mpred++ = block[0][3];
*mpred++ = block[1][3];
*mpred++ = block[2][3];
*mpred++ = block[3][3];
}
/*!
************************************************************************
* \brief
* Predict one 4x4 Luma block
************************************************************************
*/
void
LumaPrediction4x4 (int block_x, // <-- relative horizontal block coordinate of 4x4 block
int block_y, // <-- relative vertical block coordinate of 4x4 block
int fw_mode, // <-- forward prediction mode (1-7, 0=DIRECT if bw_mode=0)
int bw_mode, // <-- backward prediction mode (1-7, 0=DIRECT if fw_mode=0)
int fw_ref, // <-- reference frame for forward prediction (-1: Intra4x4 pred. with fw_mode)
int bw_ref )
{
static int fw_pred[16];
static int bw_pred[16];
int i, j;
int block_x4 = block_x+4;
int block_y4 = block_y+4;
int pic_pix_x = img->pix_x + block_x;
int pic_pix_y = img->pix_y + block_y;
int bx = block_x >> 2;
int by = block_y >> 2;
int* fpred = fw_pred;
int* bpred = bw_pred;
int direct = (fw_mode == 0 && bw_mode == 0 && (img->type == B_SLICE));
int skipped = (fw_mode == 0 && bw_mode == 0 && (img->type != B_SLICE));
int *****fmv_array = img->all_mv; // For MB level frame/field coding
int *****bmv_array = img->all_bmv; // For MB level frame/field coding
int apply_weights = ( (input->WeightedPrediction && (img->type == P_SLICE || img->type == SP_SLICE)) ||
(input->WeightedBiprediction && (img->type == B_SLICE)));
int fw_ref_idx, bw_ref_idx;
if(input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->field_mode)
{
if(img->top_field)
{
pic_pix_y = img->field_pix_y + block_y;
fmv_array = img->all_mv_top;
bmv_array = img->all_bmv_top;
}
else
{
pic_pix_y = img->field_pix_y + block_y;
fmv_array = img->all_mv_bot;
bmv_array = img->all_bmv_bot;
}
}
if (input->direct_type && direct)
{
fw_ref= fwdir_refFrArr[pic_pix_y>>2][pic_pix_x>>2];
bw_ref= bwdir_refFrArr[pic_pix_y>>2][pic_pix_x>>2];
}
if (img->type == B_SLICE && img->nal_reference_idc>0)
{
fw_ref_idx = fw_ref;
bw_ref_idx = (bw_ref < 2) ? 1-bw_ref : bw_ref;
}
else
{
fw_ref_idx = fw_ref;
bw_ref_idx = bw_ref;
}
direct_mode = direct && input->direct_type==0;
if (fw_mode ||(direct && (!input->direct_type || fw_ref !=-1) )|| skipped)
{
OneComponentLumaPrediction4x4 (fw_pred, pic_pix_x, pic_pix_y, fmv_array [bx][by][fw_ref][fw_mode], fw_ref,listX[0]);
}
if (bw_mode || (direct && (!input->direct_type || bw_ref !=-1) ))
{
if (input->InterlaceCodingOption && bw_ref<0)
{
bw_ref = 0;
}
OneComponentLumaPrediction4x4 (bw_pred, pic_pix_x, pic_pix_y, bmv_array [bx][by][bw_ref][bw_mode], bw_ref,listX[1]);
}
if (apply_weights)
{
if (direct || (fw_mode && bw_mode))
{
if (input->direct_type && direct)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
if (fw_ref ==-1)
img->mpr[i][j] = clip1a(((wp_weight[1][bw_ref_idx][0] * *bpred++ + wp_luma_round) >> luma_log_weight_denom) + wp_offset[1][bw_ref_idx][0]);
else if (bw_ref ==-1 )
img->mpr[i][j] = clip1a(((wp_weight[0][fw_ref_idx][0] * *fpred++ + wp_luma_round) >> luma_log_weight_denom) + wp_offset[0][fw_ref_idx][0] );
else
img->mpr[i][j] = clip1a(((wbp_weight[0][fw_ref_idx][bw_ref_idx][0] * *fpred++ + wbp_weight[1][fw_ref_idx][bw_ref_idx][0] * *bpred++ + 2*wp_luma_round) >> (luma_log_weight_denom + 1)) + ((wp_offset[0][fw_ref_idx][0] + wp_offset[1][bw_ref_idx][0] + 1)>>1));
}
else
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[i][j] = clip1a(((wbp_weight[0][fw_ref_idx][bw_ref_idx][0] * *fpred++ + wbp_weight[1][fw_ref_idx][bw_ref_idx][0] * *bpred++ + 2*wp_luma_round) >> (luma_log_weight_denom + 1)) + ((wp_offset[0][fw_ref_idx][0] + wp_offset[1][bw_ref_idx][0] + 1)>>1));
}
else if (img->type == B_SLICE && img->nal_reference_idc>0)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[i][j] = clip1a((wbp_weight[0][fw_ref_idx][bw_ref_idx][0] * *fpred++ + wbp_weight[1][fw_ref_idx][bw_ref_idx][0] * *bpred++ + wp_offset[0][fw_ref_idx][0] + wp_offset[1][bw_ref_idx][0] + 2*wp_luma_round) >> (luma_log_weight_denom + 1));
}
else if (fw_mode || skipped)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[i][j] = clip1a((wp_weight[0][fw_ref_idx][0] * *fpred++ + wp_offset[0][fw_ref_idx][0] + wp_luma_round) >> luma_log_weight_denom);
}
else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?