📄 rdopt.c
字号:
{
currMB->b8mode[i] = IPCM;
currMB->b8pdir[i] = -1;
}
currMB->luma_transform_size_8x8_flag = 0;
break;
default:
printf ("Unsupported mode in SetModesAndRefframeForBlocks!\n");
exit (1);
}
#define IS_FW ((b8x8info->best8x8pdir[mode][k]==0 || b8x8info->best8x8pdir[mode][k]==2) && (mode!=P8x8 || b8x8info->best8x8mode[k]!=0 || !bframe))
#define IS_BW ((b8x8info->best8x8pdir[mode][k]==1 || b8x8info->best8x8pdir[mode][k]==2) && (mode!=P8x8 || b8x8info->best8x8mode[k]!=0))
//--- reference frame arrays ---
if (mode==0 || mode==I4MB || mode==I16MB || mode==I8MB)
{
if (bframe)
{
if (!mode) // Direct
{
for (clist = LIST_0; clist <= LIST_1; clist++)
{
for (j = img->block_y; j < img->block_y + 4; j++)
{
memcpy(&enc_picture->motion.ref_idx[clist][j][img->block_x], &direct_ref_idx[clist][j][img->block_x], 4 * sizeof(char));
}
}
}
else // Intra
{
for (clist = LIST_0; clist <= LIST_1; clist++)
{
for (j = img->block_y; j < img->block_y + 4; j++)
{
memset(&enc_picture->motion.ref_idx[clist][j][img->block_x],-1, 4 * sizeof(char));
}
}
}
}
else
{
if (!mode) // Skip
{
for (j = img->block_y; j < img->block_y + 4; j++)
memset(&enc_picture->motion.ref_idx[LIST_0][j][img->block_x],0, 4 * sizeof(char));
}
else // Intra
{
for (j = img->block_y; j < img->block_y + 4; j++)
memset(&enc_picture->motion.ref_idx[LIST_0][j][img->block_x],-1, 4 * sizeof(char));
}
}
}
else
{
if (bframe)
{
if (mode == 1 || mode == 2 || mode == 3)
{
for (block8x8 = 0; block8x8 < 4; block8x8++)
{
for (clist = LIST_0; clist <= LIST_1; clist++)
{
bestref = (clist == LIST_0) ? b8x8info->best8x8l0ref[mode][block8x8] : b8x8info->best8x8l1ref[mode][block8x8];
if ( b8x8info->best8x8pdir[mode][block8x8] == 2)
{
if (b8x8info->bipred8x8me[mode][block8x8])
curref = 0;
else
curref = bestref;
}
else
{
curref = (clist == b8x8info->best8x8pdir[mode][block8x8]) ? bestref : -1;
}
for (block4x4 = 0; block4x4 < 4; block4x4++)
{
block_x = img->block_x + 2 * (block8x8 & 0x01) + (block4x4 & 0x01);
block_y = img->block_y + 2 * (block8x8 >> 1) + (block4x4 >> 1);
enc_picture->motion.ref_idx[clist][block_y][block_x] = curref;
}
}
}
}
else
{
for (j=0;j<4;j++)
{
block_y = img->block_y + j;
for (i=0;i<4;i++)
{
block_x = img->block_x + i;
k = 2*(j >> 1) + (i >> 1);
l = 2*(j & 0x01) + (i & 0x01);
if(mode == P8x8 && b8x8info->best8x8mode[k]==0)
{
enc_picture->motion.ref_idx[LIST_0][block_y][block_x] = direct_ref_idx[LIST_0][block_y][block_x];
enc_picture->motion.ref_idx[LIST_1][block_y][block_x] = direct_ref_idx[LIST_1][block_y][block_x];
}
else
{
enc_picture->motion.ref_idx[LIST_0][block_y][block_x] = (IS_FW ? b8x8info->best8x8l0ref[mode][k] : -1);
enc_picture->motion.ref_idx[LIST_1][block_y][block_x] = (IS_BW ? b8x8info->best8x8l1ref[mode][k] : -1);
}
}
}
}
}
else
{
if (mode == 1)
{
cref[0] = b8x8info->best8x8pdir[mode][0] == 0 ? b8x8info->best8x8l0ref[mode][0] : -1;
j = img->block_y;
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
memset(&enc_picture->motion.ref_idx[LIST_0][j ][img->block_x], cref[0], 4 * sizeof(char));
}
else if (mode == 2)
{
cref[0] = b8x8info->best8x8pdir[mode][0] == 0 ? b8x8info->best8x8l0ref[mode][0] : -1;
j = img->block_y;
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
cref[0] = b8x8info->best8x8pdir[mode][2] == 0 ? b8x8info->best8x8l0ref[mode][2] : -1;
memset(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], cref[0], 4 * sizeof(char));
memset(&enc_picture->motion.ref_idx[LIST_0][j ][img->block_x], cref[0], 4 * sizeof(char));
}
else if (mode == 3)
{
j = img->block_y;
i = img->block_x;
cref[0] = (b8x8info->best8x8pdir[mode][0] == 0) ? b8x8info->best8x8l0ref[mode][0] : -1;
enc_picture->motion.ref_idx[LIST_0][j ][i++] = cref[0];
enc_picture->motion.ref_idx[LIST_0][j ][i++] = cref[0];
cref[0] = (b8x8info->best8x8pdir[mode][1] == 0) ? b8x8info->best8x8l0ref[mode][1] : -1;
enc_picture->motion.ref_idx[LIST_0][j ][i++] = cref[0];
enc_picture->motion.ref_idx[LIST_0][j++][i ] = cref[0];
memcpy(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], &enc_picture->motion.ref_idx[LIST_0][img->block_y][img->block_x], 4 * sizeof(char));
memcpy(&enc_picture->motion.ref_idx[LIST_0][j++][img->block_x], &enc_picture->motion.ref_idx[LIST_0][img->block_y][img->block_x], 4 * sizeof(char));
memcpy(&enc_picture->motion.ref_idx[LIST_0][j ][img->block_x], &enc_picture->motion.ref_idx[LIST_0][img->block_y][img->block_x], 4 * sizeof(char));
}
else
{
for (j=0;j<4;j++)
{
block_y = img->block_y + j;
for (i=0;i<4;i++)
{
block_x = img->block_x + i;
k = 2*(j >> 1) + (i >> 1);
l = 2*(j & 0x01) + (i & 0x01);
enc_picture->motion.ref_idx[LIST_0][block_y][block_x] = (IS_FW ? b8x8info->best8x8l0ref[mode][k] : -1);
}
}
}
}
}
if (bframe)
{
for (clist = LIST_0; clist <= LIST_1; clist++)
{
for (j = img->block_y; j < img->block_y + 4; j++)
for (i = img->block_x; i < img->block_x + 4;i++)
{
cur_ref = (int) enc_picture->motion.ref_idx[clist][j][i];
enc_picture->motion.ref_pic_id [clist][j][i] = (cur_ref>=0
? enc_picture->ref_pic_num[clist + currMB->list_offset][cur_ref]
: -1);
}
}
}
else
{
for (j = img->block_y; j < img->block_y + 4; j++)
for (i = img->block_x; i < img->block_x + 4;i++)
{
cur_ref = (int) enc_picture->motion.ref_idx[LIST_0][j][i];
enc_picture->motion.ref_pic_id [LIST_0][j][i] = (cur_ref>=0
? enc_picture->ref_pic_num[LIST_0 + currMB->list_offset][cur_ref]
: -1);
}
}
#undef IS_FW
#undef IS_BW
}
/*!
*************************************************************************************
* \brief
* Sets Coefficients and reconstruction for an 8x8 block
*************************************************************************************
*/
void SetCoeffAndReconstruction8x8 (Macroblock* currMB)
{
int block, k, j, i, uv;
int cur_ref;
//============= MIXED TRANSFORM SIZES FOR 8x8 PARTITION ==============
//--------------------------------------------------------------------
int l;
int bframe = img->type==B_SLICE;
if (currMB->luma_transform_size_8x8_flag)
{
//============= set mode and ref. frames ==============
for(i = 0;i<4;i++)
{
currMB->b8mode[i] = tr8x8.part8x8mode[i];
currMB->b8pdir[i] = tr8x8.part8x8pdir[i];
currMB->bipred_me[i] = tr8x8.part8x8bipred[i];
}
if (bframe)
{
for (j = 0;j<4;j++)
{
for (i = 0;i<4;i++)
{
k = 2*(j >> 1)+(i >> 1);
l = 2*(j & 0x01)+(i & 0x01);
enc_picture->motion.ref_idx[LIST_0][img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k] & 0x01) == 0) ? tr8x8.part8x8l0ref[k] : - 1;
enc_picture->motion.ref_idx[LIST_1][img->block_y+j][img->block_x+i] = (currMB->b8pdir[k] > 0) ? tr8x8.part8x8l1ref[k] : - 1;
}
}
}
else
{
for (j = 0;j<4;j++)
{
for (i = 0;i<4;i++)
{
k = 2*(j >> 1)+(i >> 1);
l = 2*(j & 0x01)+(i & 0x01);
enc_picture->motion.ref_idx[LIST_0][img->block_y+j][img->block_x+i] = tr8x8.part8x8l0ref[k];
}
}
}
for (j = img->block_y;j<img->block_y + BLOCK_MULTIPLE;j++)
{
for (i = img->block_x;i<img->block_x + BLOCK_MULTIPLE;i++)
{
cur_ref = (int) enc_picture->motion.ref_idx[LIST_0][j][i];
enc_picture->motion.ref_pic_id [LIST_0][j][i] =(cur_ref>=0
? enc_picture->ref_pic_num[LIST_0 + currMB->list_offset][cur_ref]
: -1);
}
}
if (bframe)
{
for (j = img->block_y; j < img->block_y + BLOCK_MULTIPLE; j++)
{
for (i = img->block_x;i<img->block_x + BLOCK_MULTIPLE;i++)
{
cur_ref = (int) enc_picture->motion.ref_idx[LIST_1][j][i];
enc_picture->motion.ref_pic_id [LIST_1][j][i] = (cur_ref>=0
? enc_picture->ref_pic_num[LIST_1 + currMB->list_offset][cur_ref]
: -1);
}
}
}
//====== set the mv's for 8x8 partition with transform size 8x8 ======
//save the mv data for 4x4 transform
StoreMV8x8(1);
//set new mv data for 8x8 transform
RestoreMV8x8(0);
//============= get pre-calculated data ==============
//restore coefficients from 8x8 transform
memcpy (img->cofAC[0][0][0],cofAC8x8ts[0][0][0][0], 4 * 4 * 2 * 65 * sizeof(int));
if (img->P444_joined)
{
for (uv=0; uv<2; uv++)
{
for (block = 0; block<4; block++)
{
memcpy (img->cofAC[4+block+uv*4][0][0],cofAC8x8ts[uv + 1][block][0][0], 4 * 2 * 65 * sizeof(int));
}
}
}
//restore reconstruction
if (cnt_nonz8_8x8ts <= _LUMA_8x8_COEFF_COST_ &&
((currMB->qp_scaled[0])!=0 || img->lossless_qpprime_flag==0) &&
(img->type!=SP_SLICE))// modif ES added last condition (we probably never go there so is the next modification useful ? check)
{
currMB->cbp = 0;
currMB->cbp_blk = 0;
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy(&enc_picture->imgY[img->pix_y+j][img->pix_x], tr8x8.mpr8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
}
if(img->type==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator ))
{
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy(&lrec[img->pix_y+j][img->pix_x],tr8x8.lrec[j], MB_BLOCK_SIZE * sizeof(int));
}
}
memset( img->cofAC[0][0][0], 0, 4 * 4 * 2 * 65 * sizeof(int));
if(img->P444_joined)
{
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy(&enc_picture->imgUV[0][img->pix_y+j][img->pix_x], tr8x8.mpr8x8CbCr[0][j], MB_BLOCK_SIZE * sizeof(imgpel));
memcpy(&enc_picture->imgUV[1][img->pix_y+j][img->pix_x], tr8x8.mpr8x8CbCr[1][j], MB_BLOCK_SIZE * sizeof(imgpel));
}
for (uv=0; uv<2; uv++)
{
for (block = 0; block<4; block++)
{
memset( img->cofAC[4+block+uv*4][0][0], 0, 4 * 2 * 65 * sizeof(int));
}
}
}
}
else
{
currMB->cbp = cbp8_8x8ts;
currMB->cbp_blk = cbp_blk8_8x8ts;
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy (&enc_picture->imgY[img->pix_y+j][img->pix_x],tr8x8.rec_mbY8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
}
if(img->type==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator))
{
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy (&lrec[img->pix_y+j][img->pix_x],tr8x8.lrec[j], MB_BLOCK_SIZE * sizeof(int));
}
}
if (img->P444_joined)
{
cmp_cbp[1] = cmp_cbp[2] = cbp8_8x8ts;
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy (&enc_picture->imgUV[0][img->pix_y+j][img->pix_x],tr8x8.rec_mb8x8_cr[0][j], MB_BLOCK_SIZE * sizeof(imgpel));
memcpy (&enc_picture->imgUV[1][img->pix_y+j][img->pix_x],tr8x8.rec_mb8x8_cr[1][j], MB_BLOCK_SIZE * sizeof(imgpel));
}
}
}
}
else
{
//============= get pre-calculated data ==============
//---------------------------------------------------
//--- restore coefficients ---
memcpy (img->cofAC[0][0][0],cofAC8x8[0][0][0], (4+img->num_blk8x8_uv) * 4 * 2 * 65 * sizeof(int));
if (img->P444_joined)
{
for (block = 0; block<4; block++)
{
memcpy (img->cofAC[block+4][0][0],cofAC8x8CbCr[0][block][0][0], 4 * 2 * 65 * sizeof(int));
memcpy (img->cofAC[block+8][0][0],cofAC8x8CbCr[1][block][0][0], 4 * 2 * 65 * sizeof(int));
}
}
if (cnt_nonz_8x8<=5 && img->type!=SP_SLICE &&
((currMB->qp_scaled[0])!=0 || img->lossless_qpprime_flag==0))
{
currMB->cbp = 0;
currMB->cbp_blk = 0;
for (j = 0; j < MB_BLOCK_SIZE; j++)
{
memcpy (&enc_picture->imgY[img->pix_y+j][img->pix_x],tr4x4.mpr8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
}
if(img->type ==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -