📄 macroblock.c
字号:
if (input->symbol_mode == CABAC)
{
eep = &(dataPart->ee_cabac);
eep->Elow = eep->ElowS;
eep->Erange = eep->ErangeS;
eep->Ebuffer = eep->EbufferS;
eep->Ebits_to_go = eep->Ebits_to_goS;
eep->Ebits_to_follow = eep->Ebits_to_followS;
eep->Ecodestrm = eep->EcodestrmS;
eep->Ecodestrm_len = eep->Ecodestrm_lenS;
eep->C = eep->CS;
eep->E = eep->ES;
}
}
}
if(*end_of_slice == TRUE && skip == TRUE) //! TO 4.11.2001 Skip MBs at the end of this slice
{
//! only for Slice Mode 2 or 3
// If we still have to write the skip, let's do it!
if(img->cod_counter && *recode_macroblock == TRUE) //! MB that did not fit in this slice
{
// If recoding is true and we have had skip,
// we have to reduce the counter in case of recoding
img->cod_counter--;
if(img->cod_counter)
{
currSE->value1 = img->cod_counter;
currSE->value2 = 0;
currSE->mapping = ue_linfo;
currSE->type = SE_MBTYPE;
dataPart = &(currSlice->partArr[partMap[currSE->type]]);
dataPart->writeSyntaxElement( currSE, dataPart);
rlc_bits=currSE->len;
currMB->bitcounter[BITS_MB_MODE]+=rlc_bits;
img->cod_counter = 0;
}
}
else //! MB that did not fit in this slice anymore is not a Skip MB
{
dataPart = &(currSlice->partArr[partMap[SE_MBTYPE]]);
currStream = dataPart->bitstream;
// update the bitstream
currStream->bits_to_go = currStream->bits_to_go_skip;
currStream->byte_pos = currStream->byte_pos_skip;
currStream->byte_buf = currStream->byte_buf_skip;
// update the statistics
img->cod_counter = 0;
skip = FALSE;
}
}
//! TO 4.11.2001 Skip MBs at the end of this slice for Slice Mode 0 or 1
if(*end_of_slice == TRUE && img->cod_counter && !use_bitstream_backing)
{
currSE->value1 = img->cod_counter;
currSE->value2 = 0;
currSE->mapping = ue_linfo;
currSE->type = SE_MBTYPE;
dataPart = &(currSlice->partArr[partMap[currSE->type]]);
dataPart->writeSyntaxElement( currSE, dataPart);
currMB->currSEnr ++;
#if TRACE
snprintf(currSE->tracestring, TRACESTRING_SIZE, "Final MB runlength = %3d",img->cod_counter);
#endif
rlc_bits=currSE->len;
currMB->bitcounter[BITS_MB_MODE]+=rlc_bits;
img->cod_counter = 0;
}
}
/*!
*****************************************************************************
*
* \brief
* For Slice Mode 2: Checks if one partition of one slice exceeds the
* allowed size
*
* \return
* FALSE if all Partitions of this slice are smaller than the allowed size
* TRUE is at least one Partition exceeds the limit
*
* \par Side effects
* none
*
* \date
* 4 November 2001
*
* \author
* Tobias Oelbaum drehvial@gmx.net
*****************************************************************************/
int slice_too_big(int rlc_bits)
{
Slice *currSlice = img->currentSlice;
DataPartition *dataPart;
Bitstream *currStream;
EncodingEnvironmentPtr eep;
int i;
int size_in_bytes;
//! UVLC
if (input->symbol_mode == UVLC)
{
for (i=0; i<currSlice->max_part_nr; i++)
{
dataPart = &(currSlice->partArr[i]);
currStream = dataPart->bitstream;
size_in_bytes = currStream->byte_pos /*- currStream->tmp_byte_pos*/;
if (currStream->bits_to_go < 8)
size_in_bytes++;
if (currStream->bits_to_go < rlc_bits)
size_in_bytes++;
if(size_in_bytes > input->slice_argument)
return TRUE;
}
}
//! CABAC
if (input->symbol_mode ==CABAC)
{
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;
}
static pel_t *(*get_line) (pel_t**, int, int, int, int);
/*!
************************************************************************
* \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
short* mv, //!< motion vector
short ref, //!< reference frame
StorablePicture **list //!< reference picture list
)
{
pel_t** ref_pic = list[ref]->imgY_ups;
int j0 = (pic_pix_y << 2) + mv[1] + IMG_PAD_SIZE_TIMES4;
int i0 = (pic_pix_x << 2) + mv[0] + IMG_PAD_SIZE_TIMES4;
int j;
pel_t *ref_line;
int img_width =((list[ref]->size_x + 2*IMG_PAD_SIZE - 1)<<2);
int img_height=((list[ref]->size_y + 2*IMG_PAD_SIZE - 1)<<2);
if ((i0 > 0) && (i0 < img_width - 4*BLOCK_SIZE - 1) && (j0 > 0) && (j0 < img_height - 4*BLOCK_SIZE - 1))
get_line = FastLine4X;
else
get_line = UMVLine4X;
for (j = j0; j < j0 + MB_BLOCK_SIZE; j+=BLOCK_SIZE)
{
ref_line = get_line (ref_pic, j, i0, img_height, img_width);
*mpred++ = *ref_line;
*mpred++ = *(ref_line + 4);
*mpred++ = *(ref_line + 8);
*mpred++ = *(ref_line + 12);
}
}
/*!
************************************************************************
* \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] //!< target block
)
{
*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 p_dir, //!< prediction direction (0=list0, 1=list1, 2=bipred)
int fw_mode, //!< list0 prediction mode (1-7, 0=DIRECT if bw_mode=0)
int bw_mode, //!< list1 prediction mode (1-7, 0=DIRECT if fw_mode=0)
short fw_ref_idx, //!< reference frame for list0 prediction (-1: Intra4x4 pred. with fw_mode)
short bw_ref_idx //!< reference frame for list1 prediction
)
{
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_opix_x = img->opix_x + block_x;
int pic_opix_y = img->opix_y + block_y;
int bx = block_x >> 2;
int by = block_y >> 2;
int* fpred = fw_pred;
int* bpred = bw_pred;
Macroblock* currMB = &img->mb_data[img->current_mb_nr];
int apply_weights = ( (active_pps->weighted_pred_flag && (img->type== P_SLICE || img->type == SP_SLICE)) ||
(active_pps->weighted_bipred_idc && (img->type== B_SLICE)));
short**** mv_array = img->all_mv[by][bx];
if (currMB->bi_pred_me && fw_ref_idx == 0 && bw_ref_idx == 0 && p_dir == 2 && fw_mode==1 && bw_mode==1)
{
mv_array = currMB->bi_pred_me == 1? img->bipred_mv1[by][bx] : img->bipred_mv2[by][bx];
}
if ((p_dir==0)||(p_dir==2))
{
OneComponentLumaPrediction4x4 (fw_pred, pic_opix_x, pic_opix_y, mv_array[LIST_0][fw_ref_idx][fw_mode], fw_ref_idx, listX[0+currMB->list_offset]);
}
if ((p_dir==1)||(p_dir==2))
{
OneComponentLumaPrediction4x4 (bw_pred, pic_opix_x, pic_opix_y, mv_array[LIST_1][bw_ref_idx][bw_mode], bw_ref_idx, listX[1+currMB->list_offset]);
}
if (apply_weights)
{
if (p_dir==2)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = 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 (p_dir==0)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = clip1a(((wp_weight[0][fw_ref_idx][0] * *fpred++ + wp_luma_round) >> luma_log_weight_denom) +
wp_offset[0][fw_ref_idx][0] );
}
else // p_dir==1
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = 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 (p_dir==2)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = (*fpred++ + *bpred++ + 1) >> 1;
}
else if (p_dir==0)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = *fpred++;
}
else // p_dir==1
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = *bpred++;
}
}
}
/*!
************************************************************************
* \brief
* Predict one 4x4 Luma block
************************************************************************
*/
void LumaPrediction4x4Bi ( int block_x, //!< relative horizontal block coordinate of 4x4 block
int block_y, //!< relative vertical block coordinate of 4x4 block
int p_dir, //!< prediction direction (0=list0, 1=list1, 2=bidir)
int fw_mode, //!< list0 prediction mode (1-7, 0=DIRECT if bw_mode=0)
int bw_mode, //!< list1 prediction mode (1-7, 0=DIRECT if fw_mode=0)
short fw_ref_idx, //!< reference frame for list0 prediction (-1: Intra4x4 pred. with fw_mode)
short bw_ref_idx, //!< reference frame for list1 prediction
int list //!< current list for prediction.
)
{
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_opix_x = img->opix_x + block_x;
int pic_opix_y = img->opix_y + block_y;
int bx = block_x >> 2;
int by = block_y >> 2;
int* fpred = fw_pred;
int* bpred = bw_pred;
Macroblock* currMB = &img->mb_data[img->current_mb_nr];
int apply_weights = ( (active_pps->weighted_pred_flag && (img->type == P_SLICE || img->type == SP_SLICE)) ||
(active_pps->weighted_bipred_idc && (img->type == B_SLICE)));
short ****mv_array = list ? img->bipred_mv1[by][bx] : img->bipred_mv2[by][bx];
if ((p_dir==0)||(p_dir==2))
{
OneComponentLumaPrediction4x4 (fw_pred, pic_opix_x, pic_opix_y, mv_array[LIST_0][fw_ref_idx][fw_mode], fw_ref_idx, listX[0+currMB->list_offset]);
}
if ((p_dir==1)||(p_dir==2))
{
OneComponentLumaPrediction4x4 (bw_pred, pic_opix_x, pic_opix_y, mv_array[LIST_1][bw_ref_idx][bw_mode], bw_ref_idx, listX[1+currMB->list_offset]);
}
if (apply_weights)
{
if (p_dir==2)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = 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 (p_dir==0)
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = clip1a(((wp_weight[0][fw_ref_idx][0] * *fpred++ + wp_luma_round) >> luma_log_weight_denom) +
wp_offset[0][fw_ref_idx][0] );
}
else // p_dir==1
{
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++)
img->mpr[j][i] = clip1a(((wp_weight[1][bw_ref_idx][0] * *bpred++ + wp_luma_round) >> luma_log_weight_denom)
+ wp_offset[1][bw_ref_idx][0] );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -