【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-countbit.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
////////////////////////////////////////////////////////////////////////////
//
//
// Project : VideoNet version 1.1.
// Description : Peer to Peer Video Conferencing over the LAN.
// Author : Nagareshwar Y Talekar ( nsry2002@yahoo.co.in)
// Date : 15-6-2004.
//
// I have converted origional fast h.263 encoder library from C to C++
// so that it can be integrated into any windows application easily.
// I have removed some of unnecessary codes/files from the
// fast h263 library.Also moved definitions and declarations
// in their proper .h and .cpp files.
//
// File description :
// Name : countbit.cpp
//
//
/////////////////////////////////////////////////////////////////////////////
/*************************************************
* libr263: fast H.263 encoder library
*
* Copyright (C) 1996, Roalt Aalmoes, Twente University
* SPA multimedia group
*
* Based on Telenor TMN 1.6 encoder (Copyright (C) 1995, Telenor R&D)
* created by Karl Lillevold
*
* Author encoder: Roalt Aalmoes, <aalmoes@huygens.nl>
*
* Date: 31-07-96
**************************************************/
/**********************************************************************
*
* Name: CountBitsMB
* Description: counts bits used for MB info
*
* Input: Mode, COD, CBP, Picture and Bits structures
* Returns:
* Side effects:
*
* Date: 941129 Author: Karl.Lillevold@nta.no
*
***********************************************************************/
#include "countbit.h"
void CountBitsMB(int Mode, int COD, int CBP, int CBPB, Pict *pic, Bits *bits)
{
extern EHUFF *vlc_cbpy, *vlc_cbpcm, *vlc_cbpcm_intra;
int cbpy, cbpcm, length;
/* COD */
if (Global::trace) {
fprintf(Global::tf,"MB-nr: %d",pic->MB);
if (pic->picture_coding_type == PCT_INTER)
fprintf(Global::tf," COD: %d\n",COD);
}
if (pic->picture_coding_type == PCT_INTER) {
mputv(1,COD);
bits->COD++;
}
if (COD)
return; /* not coded */
/* CBPCM */
cbpcm = Mode | ((CBP&3)<<4);
if (Global::trace) {
fprintf(Global::tf,"CBPCM (CBP=%d) (cbpcm=%d): ",CBP,cbpcm);
}
if (pic->picture_coding_type == PCT_INTRA) {
length = Encode(cbpcm,vlc_cbpcm_intra);
} else {
length = Encode(cbpcm,vlc_cbpcm);
}
bits->CBPCM += length;
/* CBPY */
cbpy = CBP>>2;
if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) /* Intra */
cbpy = cbpy^15;
if (Global::trace) {
fprintf(Global::tf,"CBPY (CBP=%d) (cbpy=%d): ",CBP,cbpy);
}
length = Encode(cbpy, vlc_cbpy);
bits->CBPY += length;
return;
}
/**********************************************************************
*
* Name: CountBitsSlice
* Description: couonts bits used for slice (GOB) info
*
* Input: slice no., quantizer
*
* Date: 94???? Author: Karl.Lillevold@nta.no
*
***********************************************************************/
int CountBitsSlice(int slice, int quant)
{
int bits = 0;
/* Picture Start Code */
if (Global::trace)
fprintf(Global::tf,"GOB sync (GBSC): ");
mputv(PSC_LENGTH,PSC); /* PSC */
bits += PSC_LENGTH;
/* Group Number */
if (Global::trace)
fprintf(Global::tf,"GN: ");
mputv(5,slice);
bits += 5;
/* GOB Sub Bitstream Indicator */
/* if CPM == 1: read 2 bits GSBI */
/* not supported in this version */
/* GOB Frame ID */
if (Global::trace)
fprintf(Global::tf,"GFID: ");
mputv(2, 0);
/* NB: in error-prone environments this value should change if
PTYPE in picture header changes. In this version of the encoder
PTYPE only changes when PB-frames are used in the following cases:
(i) after the first intra frame
(ii) if the distance between two P-frames is very large
Therefore I haven't implemented this GFID change */
/* GFID is not allowed to change unless PTYPE changes */
bits += 2;
/* Gquant */
if (Global::trace)
fprintf(Global::tf,"GQUANT: ");
mputv(5,quant);
bits += 5;
return bits;
}
/**********************************************************************
*
* Name: CountBitsCoeff
* Description: counts bits used for coeffs
*
* Input: qcoeff, coding mode CBP, bits structure, no. of
* coeffs
*
* Returns: struct with no. of bits used
* Side effects:
*
* Date: 940111 Author: Karl.Lillevold@nta.no
*
***********************************************************************/
void CountBitsCoeff(int *qcoeff, int Mode, int CBP, Bits *bits, int ncoeffs)
{
int i;
if (Mode == MODE_INTRA) {
for (i = 0; i < 4; i++) {
bits->Y += CodeCoeff(Mode, qcoeff,i,ncoeffs);
}
fo