📄 mcenc.cpp
字号:
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Bruce Lin (blin@microsoft.com), Microsoft Corporation
Simon Winder (swinder@microsoft.com), Microsoft Corporation
(date: June, 1997)
and edited by
Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
and also edited by
Mathias Wien (wien@ient.rwth-aachen.de) RWTH Aachen / Robert BOSCH GmbH
and also edited by
Yoshinori Suzuki (Hitachi, Ltd.)
and also edited by
Hideaki Kimata (NTT)
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Microsoft retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Module Name:
mcenc.cpp
Abstract:
Motion compensation routines for encoder.
Revision History:
Dec 20, 1997: Interlaced tools added by NextLevel Systems
Feb.16, 1999: add Quarter Sample
Mathias Wien (wien@ient.rwth-aachen.de)
Feb 23, 1999: GMC added by Yoshinori Suzuki (Hitachi, Ltd.)
Aug.24, 1999: NEWPRED added by Hideaki Kimata (NTT)
*************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream.h>
#include "typeapi.h"
#include "codehead.h"
#include "global.hpp"
#include "entropy/bitstrm.hpp"
#include "entropy/entropy.hpp"
#include "entropy/huffman.hpp"
#include "mode.hpp"
#include "vopses.hpp"
#include "vopseenc.hpp"
// NEWPRED
#include "newpred.hpp"
// ~NEWPRED
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
#define OFFSET_BLK1 8
#define OFFSET_BLK2 128
#define OFFSET_BLK3 136
Void CVideoObjectEncoder::motionCompMBYEnc (
const CMotionVector* pmv, const CMBMode* pmbmd,
Int imbX, Int imbY,
CoordI x, CoordI y,
CRct *prctMVLimit
)
{
// should use functions in ./sys/mc.cpp:
motionCompMB (m_ppxlcPredMBY, m_pvopcRefQ0->pixelsY (),
pmv, pmbmd,
imbX, imbY,
x, y,
FALSE, FALSE,
&m_rctRefVOPY0
);
if(m_volmd.fAUsage == EIGHT_BIT) {
for(Int iAuxComp=0;iAuxComp<m_volmd.iAuxCompCount;iAuxComp++) { // MAC (SB) 29-Nov-99
motionCompMB (
m_ppxlcPredMBA[iAuxComp], m_pvopcRefQ0->pixelsA (iAuxComp),
pmv, pmbmd,
imbX, imbY,
x, y,
FALSE, TRUE,
&m_rctRefVOPY0
);
}
}
//
// if (!m_volmd.bAdvPredDisable && !pmbmd -> m_bMCSEL && !pmbmd->m_bFieldMV) { // GMC
// motionCompOverLapEncY (
// pmv, pmbmd,
// (imbX == 0), (imbX == m_iNumMBX - 1), (imbY == 0),
// x, y,
// prctMVLimit
// );
// }
// else {
// if (!pmbmd -> m_bhas4MVForward && !pmbmd -> m_bFieldMV && !pmbmd -> m_bMCSEL) // ~GMC
// motionCompEncY (
// m_pvopcRefQ0->pixelsY (),
// m_puciRefQZoom0->pixels (),
// m_ppxlcPredMBY, MB_SIZE, pmv, x, y,
// prctMVLimit
// );
// // INTERLACE
// else if (pmbmd -> m_bFieldMV) {
// const CMotionVector* pmvTop = pmv + 5 + pmbmd->m_bForwardTop;
// motionCompYField(m_ppxlcPredMBY,
// m_pvopcRefQ0->pixelsY () + pmbmd->m_bForwardTop * m_iFrameWidthY,
// 2*x + pmvTop->m_vctTrueHalfPel.x, 2*y + pmvTop->m_vctTrueHalfPel.y);
// const CMotionVector* pmvBottom = pmv + 7 + pmbmd->m_bForwardBottom;
// motionCompYField(m_ppxlcPredMBY + MB_SIZE,
// m_pvopcRefQ0->pixelsY () + pmbmd->m_bForwardBottom * m_iFrameWidthY,
// 2*x + pmvBottom->m_vctTrueHalfPel.x, 2*y + pmvBottom->m_vctTrueHalfPel.y);
// }
// // ~INTERLACE
// // GMC
// else if (pmbmd -> m_bMCSEL) {
// FindGlobalPredForGMC (x,y,m_ppxlcPredMBY, m_pvopcRefQ0->pixelsY ());
// }
// // ~GMC
// else {
// const CMotionVector* pmv8 = pmv;
// pmv8++;
// CoordI blkX = x + BLOCK_SIZE;
// CoordI blkY = y + BLOCK_SIZE;
// motionCompEncY (
// m_pvopcRefQ0->pixelsY (),
// m_puciRefQZoom0->pixels (),
// m_ppxlcPredMBY,
// BLOCK_SIZE, pmv8, x, y,
// prctMVLimit
// );
// pmv8++;
// motionCompEncY (
// m_pvopcRefQ0->pixelsY (),
// m_puciRefQZoom0->pixels (),
// m_ppxlcPredMBY + OFFSET_BLK1,
// BLOCK_SIZE, pmv8, blkX, y,
// prctMVLimit
// );
// pmv8++;
// motionCompEncY (
// m_pvopcRefQ0->pixelsY (),
// m_puciRefQZoom0->pixels (),
// m_ppxlcPredMBY + OFFSET_BLK2,
// BLOCK_SIZE, pmv8, x, blkY,
// prctMVLimit
// );
// pmv8++;
// motionCompEncY (
// m_pvopcRefQ0->pixelsY (),
// m_puciRefQZoom0->pixels (),
// m_ppxlcPredMBY + OFFSET_BLK3,
// BLOCK_SIZE, pmv8, blkX, blkY,
// prctMVLimit
// );
// }
// }
// if(m_volmd.fAUsage == EIGHT_BIT)
// motionCompMBAEnc (
// pmv, pmbmd,
// m_ppxlcPredMBA,
// m_pvopcRefQ0,
// x, y,
// m_vopmd.iRoundingControl,
// prctMVLimit
// );
}
Void CVideoObjectEncoder::motionCompMBAEnc (
const CMotionVector* pmv, const CMBMode* pmbmd,
PixelC **pppxlcPredMBA,
CVOPU8YUVBA* pvopcRefQ,
CoordI x, CoordI y,
Int iRoundingControl,
CRct *prctMVLimit,
Int direction, //12.22.98
Int iAuxComp
)
{
if (!pmbmd -> m_bhas4MVForward && !pmbmd -> m_bFieldMV) //12.22.98
// GMC
{
if (pmbmd -> m_bMCSEL)
FindGlobalPredForGMC (x,y,pppxlcPredMBA[iAuxComp], pvopcRefQ->pixelsA (iAuxComp));
else{
// ~GMC
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (
pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp),
MB_SIZE,
x * 4 + pmv->trueMVHalfPel ().x,
y * 4 + pmv->trueMVHalfPel ().y ,
iRoundingControl,
prctMVLimit
);
else
motionComp (
pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp),
MB_SIZE,
x * 2 + pmv->trueMVHalfPel ().x,
y * 2 + pmv->trueMVHalfPel ().y ,
iRoundingControl,
prctMVLimit
);
// GMC
}
}
// ~GMC
// INTERLACE 12.22.98
else if (pmbmd -> m_bFieldMV) {
Int itmpref1,itmpref2;
itmpref1=pmbmd->m_bForwardTop;
itmpref2=pmbmd->m_bForwardBottom;
if(m_vopmd.vopPredType==BVOP&&direction)
{
itmpref1=pmbmd->m_bBackwardTop;
itmpref2=pmbmd->m_bBackwardBottom;
}
const CMotionVector* pmvTop,*pmvBottom;
if(m_vopmd.vopPredType==BVOP)
pmvTop = pmv + 1 + itmpref1;
else
pmvTop = pmv + 5 + itmpref1;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp) + itmpref1 * m_iFrameWidthY,0,
4*x + pmvTop->trueMVHalfPel ().x,
4*y + pmvTop->trueMVHalfPel ().y,
iRoundingControl, prctMVLimit
);
else
motionCompYField(pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp) + itmpref1 * m_iFrameWidthY,
2*x + pmvTop->trueMVHalfPel ().x, 2*y + pmvTop->trueMVHalfPel ().y,
prctMVLimit); // added by Y.Suzuki for the extended bounding box support
if(m_vopmd.vopPredType==BVOP)
pmvBottom = pmv + 3 + itmpref2;
else
pmvBottom = pmv + 7 + itmpref2;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (pppxlcPredMBA[iAuxComp] + MB_SIZE,
pvopcRefQ->pixelsA (iAuxComp) + itmpref2 * m_iFrameWidthY,0,
4*x + pmvBottom->trueMVHalfPel ().x,
4*y + pmvBottom->trueMVHalfPel ().y,
iRoundingControl, prctMVLimit
);
else
motionCompYField(pppxlcPredMBA[iAuxComp] + MB_SIZE,
pvopcRefQ->pixelsA (iAuxComp) + itmpref2 * m_iFrameWidthY,
2*x + pmvBottom->trueMVHalfPel ().x, 2*y + pmvBottom->trueMVHalfPel ().y,
prctMVLimit); // added by Y.Suzuki for the extended bounding box support
}
// ~INTERLACE 12.22.98
else {
const CMotionVector* pmv8 = pmv;
pmv8++;
CoordI blkX = x + BLOCK_SIZE;
CoordI blkY = y + BLOCK_SIZE;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (
pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
x * 4 + pmv8->trueMVHalfPel ().x,
y * 4 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
else
motionComp (
pppxlcPredMBA[iAuxComp],
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
x * 2 + pmv8->trueMVHalfPel ().x,
y * 2 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
pmv8++;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK1,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
blkX * 4 + pmv8->trueMVHalfPel ().x,
y * 4 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
else
motionComp (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK1,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
blkX * 2 + pmv8->trueMVHalfPel ().x,
y * 2 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
pmv8++;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK2,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
x * 4 + pmv8->trueMVHalfPel ().x,
blkY * 4 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
else
motionComp (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK2,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
x * 2 + pmv8->trueMVHalfPel ().x,
blkY * 2 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
pmv8++;
if (m_volmd.bQuarterSample) // Quarter sample
motionCompQuarterSample (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK3,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
blkX * 4 + pmv8->trueMVHalfPel ().x,
blkY * 4 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
else
motionComp (
pppxlcPredMBA[iAuxComp] + OFFSET_BLK3,
pvopcRefQ->pixelsA (iAuxComp),
BLOCK_SIZE,
blkX * 2 + pmv8->trueMVHalfPel ().x,
blkY * 2 + pmv8->trueMVHalfPel ().y,
iRoundingControl,
prctMVLimit
);
}
}
// added for BVOP direct mode , mwi
Void CVideoObjectEncoder::motionCompMBAEncDirect (
const CMotionVector* pmv, const CMBMode* pmbmd,
PixelC **pppxlcPredMBA,
CVOPU8YUVBA* pvopcRefQ,
CoordI x, CoordI y,
Int iRoundingControl,
CRct *prctMVLimit,
Int iAuxComp
)
{
const CMotionVector* pmv8 = pmv;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -