📄 shape.cpp
字号:
ppxlcSrcLeft2 += BAB_BORDER*m_iFrameWidthY; ppxlcDstLeft += BAB_BORDER*TOTAL_BAB_SIZE; for (iPixel = BAB_BORDER; iPixel < TOTAL_BAB_SIZE; iPixel++) { if (!m_bVPNoLeft) { *ppxlcDstLeft = *ppxlcSrcLeft1; *(ppxlcDstLeft + 1) = *ppxlcSrcLeft2; } else { *ppxlcDstLeft = (PixelC) 0; *(ppxlcDstLeft + 1) = (PixelC) 0; } ppxlcSrcLeft1 += m_iFrameWidthY; ppxlcSrcLeft2 += m_iFrameWidthY; ppxlcDstLeft += TOTAL_BAB_SIZE; //last two values of left border will be over written after the loop } //repeat pad the left border (this will be done again in right bottom border; improve in the future) if (!m_bVPNoLeft) { Int iLastValidSrcLeft1 = *(ppxlcSrcLeft1 - (BAB_BORDER+1) * m_iFrameWidthY); Int iLastValidSrcLeft2 = *(ppxlcSrcLeft2 - (BAB_BORDER+1) * m_iFrameWidthY); for (iPixel = 0; iPixel < BAB_BORDER; iPixel++) { ppxlcDstLeft -= TOTAL_BAB_SIZE; *ppxlcDstLeft = iLastValidSrcLeft1; *(ppxlcDstLeft + 1) = iLastValidSrcLeft2; } }// End Toshiba(1997-11-14)}Void CVideoObject::subsampleLeftTopBorderFromVOP (PixelC* ppxlcSrc, PixelC* ppxlcDst){ PixelC* ppxlcSrcTop1 = ppxlcSrc - BAB_BORDER * m_iFrameWidthY - BAB_BORDER; PixelC* ppxlcSrcTop2 = ppxlcSrcTop1 + m_iFrameWidthY; PixelC* ppxlcSrcLft1 = ppxlcSrcTop1; PixelC* ppxlcSrcLft2 = ppxlcSrcLft1 + 1; PixelC* ppxlcDstTop1 = ppxlcDst; PixelC* ppxlcDstTop2 = ppxlcDst + m_iWidthCurrBAB; PixelC* ppxlcDstLft1 = ppxlcDst; PixelC* ppxlcDstLft2 = ppxlcDst + 1; Int iThresh = (m_iInverseCR == 2) ? 0 : opaqueValue; CoordI iPixel, iPixelSub, iSampleInterval; // Modified for error resilient mode by Toshiba(1997-11-14) for (iPixelSub = BAB_BORDER, iSampleInterval = BAB_BORDER; iPixelSub < m_iWidthCurrBAB - BAB_BORDER; iPixelSub++, iSampleInterval += m_iInverseCR) { //get each subsample Int iTempSumTop1 = 0, iTempSumTop2 = 0; Int iTempSumLft1 = 0, iTempSumLft2 = 0; for (iPixel = 0; iPixel < m_iInverseCR; iPixel++) { iTempSumTop1 += ppxlcSrcTop1 [iSampleInterval + iPixel]; iTempSumTop2 += ppxlcSrcTop2 [iSampleInterval + iPixel]; iTempSumLft1 += ppxlcSrcLft1 [(iSampleInterval + iPixel) * m_iFrameWidthY]; iTempSumLft2 += ppxlcSrcLft2 [(iSampleInterval + iPixel) * m_iFrameWidthY]; } if (!m_bVPNoTop) { ppxlcDstTop1 [iPixelSub] = (iTempSumTop1 > iThresh) ? opaqueValue : transpValue; ppxlcDstTop2 [iPixelSub] = (iTempSumTop2 > iThresh) ? opaqueValue : transpValue; } else { ppxlcDstTop1 [iPixelSub] = 0; ppxlcDstTop2 [iPixelSub] = 0; } if (!m_bVPNoLeft) { ppxlcDstLft1 [iPixelSub * m_iWidthCurrBAB] = (iTempSumLft1 > iThresh) ? opaqueValue : transpValue; ppxlcDstLft2 [iPixelSub * m_iWidthCurrBAB] = (iTempSumLft2 > iThresh) ? opaqueValue : transpValue; } else { ppxlcDstLft1 [iPixelSub * m_iWidthCurrBAB] = 0; ppxlcDstLft2 [iPixelSub * m_iWidthCurrBAB] = 0; } } //boundary conditions 0, 1, 18, 19 CoordI iBorder; for (iBorder = 0; iBorder < BAB_BORDER; iBorder++) { if (!m_bVPNoLeftTop) { ppxlcDstTop1 [iBorder] = ppxlcSrcTop1 [iBorder]; ppxlcDstTop2 [iBorder] = ppxlcSrcTop2 [iBorder]; } else { ppxlcDstTop1 [iBorder] = 0; ppxlcDstTop2 [iBorder] = 0; } if (!m_bVPNoRightTop) { ppxlcDstTop1 [m_iWidthCurrBAB - 1 - iBorder] = ppxlcSrcTop1 [TOTAL_BAB_SIZE - 1 - iBorder]; ppxlcDstTop2 [m_iWidthCurrBAB - 1 - iBorder] = ppxlcSrcTop2 [TOTAL_BAB_SIZE - 1 - iBorder]; } else { ppxlcDstTop1 [m_iWidthCurrBAB - 1 - iBorder] = 0; ppxlcDstTop2 [m_iWidthCurrBAB - 1 - iBorder] = 0; } } // End Toshiba(1997-11-14) //repeat pad left-bottom corner ppxlcDstLft1 [(m_iWidthCurrBAB - 1) * m_iWidthCurrBAB] = ppxlcDstLft1 [(m_iWidthCurrBAB - 2) * m_iWidthCurrBAB] = ppxlcDstLft1 [(m_iWidthCurrBAB - 3) * m_iWidthCurrBAB]; ppxlcDstLft2 [(m_iWidthCurrBAB - 1) * m_iWidthCurrBAB] = ppxlcDstLft2 [(m_iWidthCurrBAB - 2) * m_iWidthCurrBAB] = ppxlcDstLft2 [(m_iWidthCurrBAB - 3) * m_iWidthCurrBAB];}Void CVideoObject::makeRightBottomBorder (PixelC* ppxlcSrc, Int iWidth){ Int i; PixelC* ppxlcDst = ppxlcSrc + BAB_BORDER * iWidth + iWidth - BAB_BORDER; //make right border for (i = 0; i < iWidth - 2*BAB_BORDER; i++) { *ppxlcDst = *(ppxlcDst - 1); *(ppxlcDst + 1) = *ppxlcDst; ppxlcDst += iWidth; } ppxlcDst = ppxlcSrc + (iWidth - BAB_BORDER) * iWidth; //make bottom border for (i = 0; i < iWidth; i++) { *ppxlcDst = *(ppxlcDst - iWidth); *(ppxlcDst + iWidth) = *ppxlcDst; ppxlcDst++; }}//OBSS_SAIT_991015Void CVideoObject::makeRightBottomBorder (PixelC* ppxlcDst, Int iDstWidth, PixelC* ppxlcSrc, Int iSrcWidth){ Int i; PixelC* ppxlcDstOrg = ppxlcDst; PixelC* ppxlcSrcOrg = ppxlcSrc; ppxlcDst += (BAB_BORDER * iDstWidth + iDstWidth - BAB_BORDER); //make right border ppxlcSrc += MB_SIZE; for (i = 0; i < iDstWidth - 2*BAB_BORDER; i++) { if(!m_bVPNoRight){ *ppxlcDst = *(ppxlcSrc); *(ppxlcDst + 1) = *(ppxlcSrc+1); } else{ *ppxlcDst = 0; *(ppxlcDst + 1) = 0; } ppxlcDst += iDstWidth; ppxlcSrc += iSrcWidth; } ppxlcDst += (BAB_BORDER-iDstWidth); ppxlcSrc -= (MB_SIZE + 2 ); for (i = 0; i < BAB_BORDER; i++) { if(!m_bVPNoLeft && !m_bVPNoBottom){ *ppxlcDst = *(ppxlcSrc); *(ppxlcDst + iDstWidth) = *(ppxlcSrc + iSrcWidth); } else { *ppxlcDst = 0; *(ppxlcDst + iDstWidth) = 0; } ppxlcDst++;ppxlcSrc++; } for (i = BAB_BORDER; i < iDstWidth-BAB_BORDER; i++) { if(!m_bVPNoBottom){ *ppxlcDst = *ppxlcSrc; *(ppxlcDst + iDstWidth) = *(ppxlcSrc + iSrcWidth); } else{ *ppxlcDst = 0; *(ppxlcDst + iDstWidth) = 0; } ppxlcDst++; ppxlcSrc++; } if(!m_bVPNoRight && !m_bVPNoBottom){ *ppxlcDst = *(ppxlcSrc); *(ppxlcDst + iDstWidth) = *(ppxlcSrc + iSrcWidth); *(ppxlcDst+1) = *(ppxlcSrc+1); *(ppxlcDst+1 + iDstWidth) = *(ppxlcSrc+1 + iSrcWidth); } else { *ppxlcDst = 0; *(ppxlcDst + iDstWidth) = 0; *(ppxlcDst+1) = 0; *(ppxlcDst+1 + iDstWidth) = 0; } ppxlcDst = ppxlcDstOrg; ppxlcSrc = ppxlcSrcOrg;}Int CVideoObject::contextSIHorizontal (const PixelC* ppxlcSrc, Int iUpperSkip, Int iBottomSkip){ Int iContext = 0, i; static Int rgiNeighbourIndx [7]; rgiNeighbourIndx [0] = m_iWidthCurrBAB*iBottomSkip+1; rgiNeighbourIndx [1] = m_iWidthCurrBAB*iBottomSkip; rgiNeighbourIndx [2] = m_iWidthCurrBAB*iBottomSkip-1; rgiNeighbourIndx [3] = -1; rgiNeighbourIndx [4] = -m_iWidthCurrBAB*iUpperSkip+1; rgiNeighbourIndx [5] = -m_iWidthCurrBAB*iUpperSkip; rgiNeighbourIndx [6] = -m_iWidthCurrBAB*iUpperSkip-1; for (i = 0; i < 7; i++) iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i; assert (iContext >= 0 && iContext < 128); return iContext; }Int CVideoObject::contextSIVertical (const PixelC* ppxlcSrc, Int iRightSkip, Int iLeftSkip, Int iUpperSkip, Int iBottomSkip){ Int iContext = 0, i; static Int rgiNeighbourIndx [7]; rgiNeighbourIndx [0] = m_iWidthCurrBAB*iBottomSkip+iRightSkip; rgiNeighbourIndx [1] = m_iWidthCurrBAB*iBottomSkip-iLeftSkip; rgiNeighbourIndx [2] = 1*iRightSkip; rgiNeighbourIndx [3] = -1*iLeftSkip; rgiNeighbourIndx [4] = -iUpperSkip*m_iWidthCurrBAB+iRightSkip; rgiNeighbourIndx [5] = -iUpperSkip*m_iWidthCurrBAB; rgiNeighbourIndx [6] = -iUpperSkip*m_iWidthCurrBAB-iLeftSkip; for (i = 0; i < 7; i++) iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i; assert (iContext >= 0 && iContext < 128); return iContext;}//for decide st_orderInt CVideoObject::decideScanOrder(const PixelC* ppxlPred){ Int scan_order; Int num_right=0, num_bottom=0; const PixelC* ppxlSrc = ppxlPred + MC_BAB_SIZE * MC_BAB_BORDER + MC_BAB_BORDER; for(Int j=1;j<MB_SIZE;j+=2){ for(Int i=1;i<MB_SIZE;i+=2){ if( *(ppxlSrc+j*MC_BAB_SIZE + i) != *(ppxlSrc+j*MC_BAB_SIZE + i-2)) num_right++; if( *(ppxlSrc+j*MC_BAB_SIZE + i) != *(ppxlSrc+(j-2)*MC_BAB_SIZE + i)) num_bottom++; } } if(num_bottom <= num_right) scan_order = 0; else scan_order = 1; return(scan_order);}Void CVideoObject::VerticalScanning(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=0,j=0, prev,next,current; Int skip_upper=0, skip_bottom=0, skip_hor=0, skip_left=0, skip_right=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=1; const PixelC* smb_data = ppxlcSrcRow; i=0; while(*(HorSamplingChk+i) == 1) i++; while(*(HorSamplingChk+i) == 0) i++; int tmp = i; if (residual_scanning_hor) { start_v = 0; start_h = 0; h_scan_freq=1<<num_loop_hor; v_scan_freq=1<<num_loop_ver; skip_hor = 1<<num_loop_hor; if( tmp-(1<<num_loop_hor) >= 0 ) start_h = tmp-(1<<num_loop_hor); else if( tmp+(1<<num_loop_hor) <= MB_SIZE-1) start_h = tmp+(1<<(num_loop_hor)) ; else printf("Out of Sampling Ratio\n"); i=0; while(*(VerSamplingChk+i) == 0) i++; start_v = i; for(j=start_h;j<(width-4);j+=h_scan_freq){ if( *(HorSamplingChk+j) == 1) continue; skip_upper = start_v+1; for(i=start_v;i<(height-4);i+=v_scan_freq){ if( *(VerSamplingChk+i) == 1) { if ( i+v_scan_freq >15) skip_bottom = MB_SIZE+1-i; else { if( *(VerSamplingChk+i+v_scan_freq) == 0){ if (i+v_scan_freq*2 >15) skip_bottom = MB_SIZE+1-i; else skip_bottom = v_scan_freq*2; } else skip_bottom = v_scan_freq; } } else continue; current=(*(smb_data+i*width+j) == MPEG4_OPAQUE ); if(j-h_scan_freq < -2) prev=(*(smb_data+i*width - 2) == MPEG4_OPAQUE ); else prev=(*(smb_data+i*width+j-h_scan_freq) == MPEG4_OPAQUE ); if(j+h_scan_freq > 17) next=(*(smb_data+i*width+17) == MPEG4_OPAQUE ); else next=(*(smb_data+i*width+j+h_scan_freq) == MPEG4_OPAQUE ); if ( j+skip_hor >15) skip_right = MB_SIZE+1-j; else skip_right = skip_hor; if ( j-skip_hor <0) skip_left = j+2; else skip_left = skip_hor; type_id = contextSIVertical( smb_data+i*width+j,skip_right, skip_left ,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++; if(skip_bottom == v_scan_freq) skip_upper = v_scan_freq; else skip_upper = v_scan_freq*2; } } } i=0; while(*(HorSamplingChk+i) == 1) i++; while(*(HorSamplingChk+i) == 0) i++; if(i>start_h && residual_scanning_hor) tmp = start_h; else tmp = i; while (num_loop_hor >0){ start_v = 0; start_h = 0; h_scan_freq=1<<num_loop_hor; v_scan_freq=1<<num_loop_ver; skip_hor = 1<<(num_loop_hor-1); if( tmp-(1<<(num_loop_hor-1)) >= 0 ) tmp = start_h = tmp-(1<<(num_loop_hor-1)); else start_h = tmp+(1<<(num_loop_hor-1)) ; i=0; while(*(VerSamplingChk+i) == 0) i++; start_v = i; for(j=start_h;j<(width-4);j+=h_scan_freq){ skip_upper = start_v+1; for(i=start_v;i<(height-4);i+=v_scan_freq){ if( *(VerSamplingChk+i) == 1) { if ( i+v_scan_freq >15) skip_bottom = MB_SIZE+1-i; else { if( *(VerSamplingChk+i+v_scan_freq) == 0){ if (i+v_scan_freq*2 >15) skip_bottom = MB_SIZE+1-i; else skip_bottom = v_scan_freq*2; } else skip_bottom = v_scan_freq; } } else continue; current=(*(smb_data+i*width+j) == MPEG4_OPAQUE ); if(j-(1<<(num_loop_hor-1)) < -2) prev=(*(smb_data+i*width-2) == MPEG4_OPAQUE ); else prev=(*(smb_data+i*width+j-(1<<(num_loop_hor-1))) == MPEG4_OPAQUE ); if(j+(1<<(num_loop_hor-1)) > 17) next=(*(smb_data+i*width+17) == MPEG4_OPAQUE ); else next=(*(smb_data+i*width+j+(1<<(num_loop_hor-1))) == MPEG4_OPAQUE ); if ( j+skip_hor >15) skip_right = MB_SIZE+1-j; else skip_right = skip_hor; if ( j-skip_hor <0) skip_left = j+2; else skip_left = skip_hor; type_id = contextSIVertical( smb_data+i*width+j,skip_right,skip_left,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){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -