【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了errenc.cpp提供大家参考,希望对大家有所帮助!
/*************************************************************************
This software module was originally developed by
Yoshihiro Kikuchi (TOSHIBA CORPORATION)
Takeshi Nagai (TOSHIBA CORPORATION)
and edited by:
Toshiaki Watanabe (TOSHIBA CORPORATION)
Noboru Yamaguchi (TOSHIBA CORPORATION)
and also edited by
Xuemin Chen (
errenc.cpp为[网学网-网友上传,谢谢支持]。) Next Level System, Inc.
Bob Eifrig (
errenc.cpp为[网学网-网友上传,谢谢支持]。) Next Level Systems, Inc.
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
(ISO/IEC 14496-2)> tools as specified by the <MPEG-4 Video(ISO/IEC 14496-2)
>. ISO/IEC gives users of the <MPEG-4 Video(ISO/IEC 14496-2)> free license
to this software module or modifications thereof for use in hardware or
software products claiming conformance to the <MPEG-4 Video(ISO/IEC 14496-2
)>. 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(ISO/IEC 14496-2)>
conforming products. TOSHIBA CORPORATION 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-4 Video(ISO/IEC
14496-2)> conforming products. This copyright notice must be included in
all copies or derivative works.
Copyright (c)1997.
Revision History:
May 9, 1999: tm5 rate control by DemoGraFX,
errenc.cpp为[网学网-网友上传,谢谢支持]。
*************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream.h>
#include "typeapi.h"
#include "codehead.h"
#include "entropy/bitstrm.hpp"
#include "entropy/entropy.hpp"
#include "entropy/huffman.hpp"
#include "mode.hpp"
#include "global.hpp"
#include "vopses.hpp"
#include "vopseenc.hpp"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
// inline functions
inline Int clog2(Int a) {return ( ((a)<=0) ? 0 : (int) ceil( log10( (double) (a) ) / log10(2.0) ) );}
Void CVideoObjectEncoder::VideoPacketResetVOP(
)
{
m_iVPCounter = m_pbitstrmOut -> getCounter(); // reset coding bits counter
assert(m_iNumMBX>0 && m_iNumMBY>0);
m_numBitsVPMBnum = clog2 (m_iNumMBX * m_iNumMBY); // number of bits for macroblock_number
m_numVideoPacket = 1; // reset number of video packet in a VOP
m_iVPMBnum = 0; // start MB in the 1st VP
}
Void CVideoObjectEncoder::codeVideoPacketHeader (
Int iMBX, Int iMBY, Int QuantScale
)
{
m_iVPMBnum = VPMBnum(iMBX, iMBY);
m_statsVOP.nBitsHead += codeVideoPacketHeader(QuantScale);
}
#if 0 // revised HEC for shape
Int CVideoObjectEncoder::codeVideoPacketHeader (Int QuantScale)
{
#ifdef __TRACE_AND_STATS_
m_pbitstrmOut->trace ("Video_Packet_Header\n");
#endif // __TRACE_AND_STATS_
UInt nBits = 0;
assert(m_iVPMBnum > 0 && m_iVPMBnum < m_iNumMBX * m_iNumMBY);
assert(QuantScale > 0 && QuantScale < 32);
m_pbitstrmOut->flush ();
Int nBitsResyncMarker = NUMBITS_VP_RESYNC_MARKER;
if(m_volmd.bShapeOnly==FALSE)
{
if(m_vopmd.vopPredType == PVOP)
nBitsResyncMarker += (m_vopmd.mvInfoForward.uiFCode - 1);
else if(m_vopmd.vopPredType == BVOP)
nBitsResyncMarker += max(m_vopmd.mvInfoForward.uiFCode, m_vopmd.mvInfoBackward.uiFCode) - 1;
}
m_pbitstrmOut -> putBits (RESYNC_MARKER, nBitsResyncMarker, "resync_marker");
m_pbitstrmOut -> putBits (m_iVPMBnum, m_numBitsVPMBnum, "VPH_macroblock_number");
if(m_volmd.bShapeOnly==FALSE) {
m_pbitstrmOut -> putBits (QuantScale, NUMBITS_VP_QUANTIZER, "VPH_quant_scale");
}
Bool HEC = ((++m_numVideoPacket) == 2); // use HEC in 2nd VP
m_pbitstrmOut -> putBits (HEC, NUMBITS_VP_HEC, "VPH_header_extension_code");
#ifdef __TRACE_AND_STATS_
nBits += nBitsResyncMarker + m_numBitsVPMBnum + NUMBITS_VP_QUANTIZER + NUMBITS_VP_HEC;
#endif // __TRACE_AND_STATS_
if( HEC == TRUE ) {
m_pbitstrmOut -> putBits ((Int) 0xFFFFFFFE, (UInt) m_nBitsModuloBase + 1, "VPH_Modulo_Time_Base");
m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
m_pbitstrmOut -> putBits (m_iVopTimeIncr, m_iNumBitsTimeIncr, "VPH_Time_Incr");
m_pbitstrmOut->putBits ((Int) 1, 1, "Marker"); // marker bit
m_pbitstrmOut -> putBits (m_vopmd.vopPredType, NUMBITS_VP_PRED_TYPE, "VPH_Pred_Type");
#ifdef __TRACE_AND_STATS_
nBits += m_nBitsModuloBase+1 + m_iNumBitsTimeIncr +2 + NUMBITS_VP_PRED_TYPE + NUMBITS_VP_INTRA_DC_SWITCH_THR;
#endif // __TRACE_AND_STATS_
if(m_volmd.bShapeOnly==FALSE) {
m_pbitstrmOut -> putBits (m_vopmd.iIntraDcSwitchThr, NUMBITS_VP_INTRA_DC_SWITCH_THR, "VOP_DC_VLC_Switch");
if(m_vopmd.vopPredType != IVOP) {
m_pbitstrmOut -> putBits (m_vopmd.mvInfoForward.uiFCode, NUMBITS_VOP_FCODE, "VPH_Fcode_Forward");
#ifdef __TRACE_AND_STATS_
nBits += NUMBITS_VOP_FCODE;
#endif // __TRACE_AND_STATS_
if (m_vopmd.vopPredType == BVOP) {
m_pbitstrmOut -> putBits (m_vopmd.mvInfoBackward.uiFCode, NUMBITS_VOP_FCODE, "VOP_Fcode_Backward");
#ifdef __TRACE_AND_STATS_
nBits += NUMBITS_VOP_FCODE;
#endif // __TRACE_AND_STATS_
}
}
}
}
return nBits;
}
#else
Int CVideoObjectEncoder::codeVideoPacketHeader (Int QuantScale)
{
#ifdef __TRACE_AND_STATS_
m_pbitstrmOut->trace ("Video_Packet_Header\n");
#endif // __TRACE_AND_STATS_
UInt nBits = 0;
assert(m_iVPMBnum > 0 && m_iVPMBnum < m_iNumMBX * m_iNumMBY);
assert(QuantScale > 0 && QuantScale < 32);
m_pbitstrmOut->flush ();
Int nBitsResyncMarker = NUMBITS_VP_RESYNC_MARKER;
Bool HEC = ((++m_numVideoPacket) == 2); // use HEC in 2nd VP
if(m_volmd.bShapeOnly==FALSE)
{
if(m_vopmd.vopPredType == PVOP)
nBitsResyncMarker += (m_vopmd.mvInfoForward.uiFCode - 1);
else if(m_vopmd.vopPredType == BVOP)
nBitsResyncMarker += max(m_vopmd.mvInfoForward.uiFCode, m_vopmd.mvInfoBackward.uiFCode) - 1;
}
m_pbitstrmOut -> putBits (RESYNC_MARKER, nBitsResyncMarker, "resync_marker");
if(m_volmd.fAUsage != RECTANGLE) {
m_pbitstrmOut -> putBits (HEC, NUMBITS_VP_HEC, "VPH_header_extension_code");
if (HEC == TRUE && !(m_uiSprite == 1 && m_vopmd.vopPredType == IVOP)) {
m_pbitstrmOut->putBits (m_rctCurrVOPY.width, NUMBITS_VOP_WIDTH, "VPH_VOP_Width");
m_pbit
上一篇:
errdec.cpp
下一篇:
临床前药物安全性评价中毒性病理学新技术的应用