📄 shape.cpp
字号:
type_id_mis[match_cnt][0]=type_id;
type_id_mis[match_cnt][1]=2+current;
type_id_mis[match_cnt][2]=i;
type_id_mis[match_cnt][3]=j;
xor_cnt++;
match_cnt++;
}
sample_cnt++;
if(skip_bottom == v_scan_freq) skip_upper = v_scan_freq;
else skip_upper = v_scan_freq*2;
}
}
num_loop_hor--;
}
*no_mismatch=mismatch_cnt;
*no_match=match_cnt;
*no_xor=xor_cnt;
}
Void CVideoObject::HorizontalScanning(Int *no_mismatch, Int *no_match, Int *no_xor, Int type_id_mis[256][4], Int num_loop_hor, Int num_loop_ver, Bool residual_scanning_hor, Bool residual_scanning_ver, Bool* HorSamplingChk, Bool* VerSamplingChk)
{
const PixelC* ppxlcSrcRow = m_rgpxlcCaeSymbol + m_iWidthCurrBAB * BAB_BORDER + BAB_BORDER;
Int i,j,prev,next,current;
Int skip_ver=0, skip_upper=0, skip_bottom=0;
Int start_v=0,start_h=0;
Int type_id=0, mismatch_cnt=0, match_cnt=0, sample_cnt=0, xor_cnt=0;
Int width = 20, height = 20;
Int h_scan_freq=1, v_scan_freq=2;
const PixelC* smb_data = ppxlcSrcRow;
i=0;
while (*(VerSamplingChk+i) == 1) i++;
while(*(VerSamplingChk+i) == 0) i++;
int tmp = i;
if ( residual_scanning_ver) {
start_h = 0;
start_v = 0;
v_scan_freq=1<<num_loop_ver;
h_scan_freq=1;
skip_ver = v_scan_freq;
if( tmp-(1<<num_loop_ver) >= 0 ) start_v = tmp-(1<<num_loop_ver);
else if( tmp+(1<<num_loop_ver) <= MB_SIZE-1 ) start_v = tmp+(1<<(num_loop_ver)) ;
else printf("Out of Sampling Ratio\n");
for(i=start_v;i<(height-4);i+=v_scan_freq){
if( *(VerSamplingChk+i) == 1) continue;
for(j=start_h;j<(width-4);j+=h_scan_freq){
current=(*(smb_data+i*width+j) == OPAQUE);
if(i-v_scan_freq < -2) prev=(*(smb_data+(-2)*width+j) == OPAQUE);
else prev=(*(smb_data+(i-v_scan_freq)*width+j) == OPAQUE);
if(i+v_scan_freq > 17) next=(*(smb_data+(17)*width+j) == OPAQUE);
else next=(*(smb_data+(i+v_scan_freq)*width+j) == OPAQUE);
if ( i+skip_ver >15) skip_bottom = MB_SIZE+1-i;
else skip_bottom = skip_ver;
if ( i-skip_ver <0) skip_upper = i+2;
else skip_upper = skip_ver;
type_id = contextSIHorizontal(smb_data+i*width+j,skip_upper, skip_bottom);
if(prev==next){
type_id_mis[match_cnt][0]=type_id;
type_id_mis[match_cnt][1]=current;
type_id_mis[match_cnt][2]=i;
type_id_mis[match_cnt][3]=j;
if(prev!=current) mismatch_cnt++;
match_cnt++;
}
if(prev!=next){
type_id_mis[match_cnt][0]=type_id;
type_id_mis[match_cnt][1]=2+current;
type_id_mis[match_cnt][2]=i;
type_id_mis[match_cnt][3]=j;
xor_cnt++;
match_cnt++;
}
sample_cnt++;
}
}
}
i=0;
while (*(VerSamplingChk+i) == 1) i++;
while(*(VerSamplingChk+i) == 0) i++;
if(i>start_v && residual_scanning_ver) tmp = start_v;
else tmp = i;
while (num_loop_ver > 0) {
start_h = 0;
start_v = 0;
v_scan_freq=1<<num_loop_ver;
h_scan_freq=1;
if( tmp-(1<<(num_loop_ver-1)) >= 0 ) tmp = start_v = tmp-(1<<(num_loop_ver-1));
else start_v = tmp+(1<<(num_loop_ver-1)) ;
skip_ver = 1<<(num_loop_ver-1);
for(i=start_v;i<(height-4);i+=v_scan_freq){
for(j=start_h;j<(width-4);j+=h_scan_freq){
current=(*(smb_data+i*width+j) == OPAQUE);
if(i-skip_ver < -2) prev=(*(smb_data+(-2)*width+j) == OPAQUE);
else prev=(*(smb_data+(i-skip_ver)*width+j) == OPAQUE);
if(i+skip_ver > 17) next=(*(smb_data+(17)*width+j) == OPAQUE);
else next=(*(smb_data+(i+skip_ver)*width+j) == OPAQUE);
if(i - skip_ver < 0) skip_upper = i +2;
else skip_upper = skip_ver;
if(i + skip_ver > 15) skip_bottom = MB_SIZE+1 - i ;
else skip_bottom = skip_ver;
type_id = contextSIHorizontal(smb_data+i*width+j,skip_upper,skip_bottom);
if(prev==next){
type_id_mis[match_cnt][0]=type_id;
type_id_mis[match_cnt][1]=current;
type_id_mis[match_cnt][2]=i;
type_id_mis[match_cnt][3]=j;
if(prev!=current) mismatch_cnt++;
match_cnt++;
}
if(prev!=next){
type_id_mis[match_cnt][0]=type_id;
type_id_mis[match_cnt][1]=2+current;
type_id_mis[match_cnt][2]=i;
type_id_mis[match_cnt][3]=j;
xor_cnt++;
match_cnt++;
}
sample_cnt++;
}
}
num_loop_ver--;
}
*no_mismatch=mismatch_cnt;
*no_match=match_cnt;
*no_xor=xor_cnt;
}
//~OBSS_SAIT_991015
Int CVideoObject::contextIntra (const PixelC* ppxlcSrc)
{
Int iContext = 0, i;
static Int rgiNeighbourIndx [10];
rgiNeighbourIndx [0] = -1;
rgiNeighbourIndx [1] = -2;
rgiNeighbourIndx [2] = -m_iWidthCurrBAB + 2;
rgiNeighbourIndx [3] = -m_iWidthCurrBAB + 1;
rgiNeighbourIndx [4] = -m_iWidthCurrBAB;
rgiNeighbourIndx [5] = -m_iWidthCurrBAB - 1;
rgiNeighbourIndx [6] = -m_iWidthCurrBAB - 2;
rgiNeighbourIndx [7] = -2 * m_iWidthCurrBAB + 1;
rgiNeighbourIndx [8] = -2 * m_iWidthCurrBAB;
rgiNeighbourIndx [9] = -2 * m_iWidthCurrBAB - 1;
for (i = 0; i < 10; i++)
iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == OPAQUE) << i;
assert (iContext >= 0 && iContext < 1024);
return iContext;
}
Int CVideoObject::contextIntraTranspose (const PixelC* ppxlcSrc)
{
Int iContext = 0, i;
static Int rgiNeighbourIndx [10];
rgiNeighbourIndx [0] = -m_iWidthCurrBAB;
rgiNeighbourIndx [1] = -2 * m_iWidthCurrBAB;
rgiNeighbourIndx [2] = -1 + 2 * m_iWidthCurrBAB;
rgiNeighbourIndx [3] = -1 + m_iWidthCurrBAB;
rgiNeighbourIndx [4] = -1;
rgiNeighbourIndx [5] = -m_iWidthCurrBAB - 1;
rgiNeighbourIndx [6] = -1 - 2 * m_iWidthCurrBAB;
rgiNeighbourIndx [7] = -2 + m_iWidthCurrBAB;
rgiNeighbourIndx [8] = -2;
rgiNeighbourIndx [9] = -2 - m_iWidthCurrBAB;
for (i = 0; i < 10; i++)
iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == OPAQUE) << i;
assert (iContext >= 0 && iContext < 1024);
return iContext;
}
Int CVideoObject::contextInter (const PixelC* ppxlcSrc, const PixelC* ppxlcPred)
{
Int i, iContext = 0;
static Int rgiNeighbourIndx [9];
Int iSizePredBAB = m_iWidthCurrBAB - 2*BAB_BORDER + 2*MC_BAB_BORDER;
rgiNeighbourIndx [0] = -1;
rgiNeighbourIndx [1] = -m_iWidthCurrBAB + 1;
rgiNeighbourIndx [2] = -m_iWidthCurrBAB;
rgiNeighbourIndx [3] = -m_iWidthCurrBAB - 1;
rgiNeighbourIndx [4] = iSizePredBAB;
rgiNeighbourIndx [5] = 1;
rgiNeighbourIndx [6] = 0;
rgiNeighbourIndx [7] = -1;
rgiNeighbourIndx [8] = -iSizePredBAB;
for (i = 0; i < 4; i++) {
iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == OPAQUE) << i;
}
for (i = 4; i < 9; i++) {
iContext += (ppxlcPred [rgiNeighbourIndx [i]] == OPAQUE) << i;
}
assert (iContext >= 0 && iContext < 1024);
return iContext;
}
Int CVideoObject::contextInterTranspose (const PixelC* ppxlcSrc, const PixelC* ppxlcPred)
{
Int i, iContext = 0;
static Int rgiNeighbourIndx [9];
Int iSizePredBAB = m_iWidthCurrBAB - 2*BAB_BORDER + 2*MC_BAB_BORDER;
rgiNeighbourIndx [0] = -m_iWidthCurrBAB;
rgiNeighbourIndx [1] = m_iWidthCurrBAB - 1;
rgiNeighbourIndx [2] = -1;
rgiNeighbourIndx [3] = -m_iWidthCurrBAB - 1;
rgiNeighbourIndx [4] = 1;
rgiNeighbourIndx [5] = iSizePredBAB;
rgiNeighbourIndx [6] = 0;
rgiNeighbourIndx [7] = -iSizePredBAB;
rgiNeighbourIndx [8] = -1;
for (i = 0; i < 4; i++)
iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == OPAQUE) << i;
for (i = 4; i < 9; i++)
iContext += (ppxlcPred [rgiNeighbourIndx [i]] == OPAQUE) << i;
assert (iContext >= 0 && iContext < 1024);
return iContext;
}
Void CVideoObject::copyReconShapeToMbAndRef (
PixelC* ppxlcDstMB,
PixelC* ppxlcRefFrm, PixelC pxlcSrc
)
{
pxlcmemset (ppxlcDstMB, pxlcSrc, MB_SQUARE_SIZE); // Modified by swinder
for (Int i = 0; i < MB_SIZE; i++) {
pxlcmemset (ppxlcRefFrm, pxlcSrc, MB_SIZE);
ppxlcRefFrm += m_iFrameWidthY;
}
}
Void CVideoObject::copyReconShapeUVToRef (
PixelC* ppxlcRefFrm, const PixelC* ppxlcSrc)
{
for (Int i = 0; i < BLOCK_SIZE; i++) {
memcpy (ppxlcRefFrm, ppxlcSrc, BLOCK_SIZE*sizeof(PixelC));
ppxlcRefFrm += m_iFrameWidthUV;
ppxlcSrc += BLOCK_SIZE;
}
}
Void CVideoObject::copyReconShapeToMbAndRef (
PixelC* ppxlcDstMB,
PixelC* ppxlcRefFrm,
const PixelC* ppxlcSrc, Int iSrcWidth, Int iBorder
)
{
Int iUnit = sizeof(PixelC); // NBIT: for memcpy
ppxlcSrc += iSrcWidth * iBorder + iBorder;
for (Int i = 0; i < MB_SIZE; i++) {
memcpy (ppxlcDstMB, ppxlcSrc, MB_SIZE*iUnit);
memcpy (ppxlcRefFrm, ppxlcSrc, MB_SIZE*iUnit);
ppxlcRefFrm += m_iFrameWidthY;
ppxlcDstMB += MB_SIZE;
ppxlcSrc += iSrcWidth;
}
}
CMotionVector CVideoObject::findShapeMVP (
const CMotionVector* pmv, const CMotionVector* pmvBY,
const CMBMode* pmbmd,
Int iMBX, Int iMBY
) const
{
CMotionVector mvRet;
// try shape vector first
Bool bLeftBndry, bRightBndry, bTopBndry;
Int iMBnum = VPMBnum(iMBX, iMBY);
bLeftBndry = bVPNoLeft(iMBnum, iMBX);
bTopBndry = bVPNoTop(iMBnum);
bRightBndry = bVPNoRightTop(iMBnum, iMBX);
//OBSS_SAIT_991015
if (iMBX==0 && iMBY==0) {
mvRet.iMVX = mvRet.iMVY = mvRet.iHalfX =mvRet.iHalfY = 0;
}
else mvRet = *(pmvBY - 1);
/* !!!
mvRet = *(pmvBY - 1);
*/
//~OBSS_SAIT_991015
// Modified for error resilient mode by Toshiba(1997-11-14)
// if ((iMBX > 0) && ((pmbmd - 1)->m_shpmd == INTER_CAE_MVDZ ||
if (!bLeftBndry && ((pmbmd - 1)->m_shpmd == INTER_CAE_MVDZ ||
(pmbmd - 1)->m_shpmd == INTER_CAE_MVDNZ ||
(pmbmd - 1)->m_shpmd == MVDZ_NOUPDT ||
(pmbmd - 1)->m_shpmd == MVDNZ_NOUPDT))
return mvRet;
if (iMBY > 0) {
mvRet = *(pmvBY - m_iNumMBX);
// Modified for error resilient mode by Toshiba(1997-11-14)
// if ((pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDZ ||
if (!bTopBndry && ((pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDZ ||
(pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDNZ ||
(pmbmd - m_iNumMBX)->m_shpmd == MVDZ_NOUPDT ||
(pmbmd - m_iNumMBX)->m_shpmd == MVDNZ_NOUPDT
// Modified for error resilient mode by Toshiba(1997-11-14)
// )
))
return mvRet;
mvRet = *(pmvBY - m_iNumMBX + 1);
// Modified for error resilient mode by Toshiba(1997-11-14)
// if ((iMBX < m_iNumMBX - 1) && ((pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDZ ||
if (!bRightBndry && ((pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDZ ||
(pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDNZ ||
(pmbmd - m_iNumMBX + 1)->m_shpmd == MVDZ_NOUPDT ||
(pmbmd - m_iNumMBX + 1)->m_shpmd == MVDNZ_NOUPDT)
)
return mvRet;
}
// try texture vector then; truncate half pel
if(m_volmd.bShapeOnly==FALSE && (m_vopmd.vopPredType==PVOP || (m_uiSprite == 2 && m_vopmd.vopPredType==SPRITE))) // GMC
{
Int iSubDim;
if (m_volmd.bQuarterSample) // Quarter sample
iSubDim = 4;
else
iSubDim = 2;
// Modified for error resilient mode by Toshiba(1997-11-14)
// if (iMBX != 0 && validBlock (pmbmd - 1, gIndexOfCandBlk [1] [0]))
if (!bLeftBndry && validBlock (pmbmd, pmbmd - 1, gIndexOfCandBlk [1] [0]))
// GMC
if(!((pmbmd-1)->m_bMCSEL)){
// ~GMC
return CMotionVector ((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0])->m_vctTrueHalfPel.x / iSubDim,
(pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0])->m_vctTrueHalfPel.y / iSubDim);
// GMC
}else{
return CMotionVector ();
}
// ~GMC
if (iMBY != 0) {
// Modified for error resilient mode by Toshiba(1997-11-14)
// if (validBlock (pmbmd - m_iNumMBX, gIndexOfCandBlk [1] [1]))
if (!bTopBndry && validBlock (pmbmd, pmbmd - m_iNumMBX, gIndexOfCandBlk [1] [1]))
// GMC
if(!((pmbmd-m_iNumMBX)->m_bMCSEL)){
// ~GMC
return CMotionVector ((pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1])->m_vctTrueHalfPel.x / iSubDim,
(pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1])->m_vctTrueHalfPel.y / iSubDim);
// GMC
}else{
return CMotionVector ();
}
// ~GMC
// Modified for error resilient mode by Toshiba(1997-11-14)
// if (iMBX < m_iNumMBX - 1 && validBlock (pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))
if (!bRightBndry && validBlock (pmbmd, pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))
// GMC
if(!((pmbmd-m_iNumMBX + 1)->m_bMCSEL)){
// ~GMC
return CMotionVector ((pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2])->m_vctTrueHalfPel.x / iSubDim,
(pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2])->m_vctTrueHalfPel.y / iSubDim);
// GMC
}else{
return CMotionVector ();
}
// ~GMC
}
}
return CMotionVector ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -