【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“coder.cpp”一文,供大家参考学习!
////////////////////////////////////////////////////////////////////////////
//
//
// Project : VideoNet version 1.1.
// Description : Peer to Peer Video Conferencing over the LAN.
// Author : Nagareshwar Y Talekar (
coder.cpp为[网学网-网友上传,谢谢支持]。)
// 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 : coder.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, <
coder.cpp为[网学网-网友上传,谢谢支持]。>
*
* Date: 31-07-96
**************************************************/
/* Modyfied by Roalt Aalmoes with better algorithms and performance
* objectives
*
* Warning: Although I tried to remove all advanced options code,
* there might still be some artifacts in the code. Please do not
* blame me for not removing all of it.
* Removing all advanced and alternating quantization code was done
* for performance reasons. I'm sorry these options are not
* implemented here, but see the tmn1.7 code for a slow functioning
* advanced H.263 compression algorithm.
*****************************************************************/
/* Notes for clear code: */
/* var. j is used for row indexing of MB in frame */
/* var. i is used for column indexing of MB in frame */
/* pic is declared global */
/* MV is changed: it is now a real array of MV instead of array of pointers
to MV. Its range is also equal to MVs encoded, without border MVs
Advantages: No more mallocs and frees in the code, disadvantages: ?? */
/* PictImage structure is replaced by int pointer. Drawback: not flexible for
other format. */
#include"coder.h"
#include "countbit.h"
#include "pred.h"
#include "quant.h"
#include "mot_est.h"
#include "dct.h"
/**********************************************************************
*
* Name: Clip
* Description: clips recontructed data 0-255
*
* Input: pointer to recon. data structure
* Side effects: data structure clipped
*
* Date: 960715 Author: Roalt Aalmoes
*
***********************************************************************/
//__inline__ void Clip(MB_Structure *data)
void Clip(MB_Structure *data)
{
int n;
int *mb_ptr = (int *) data;
for (n = 0; n < 256 + 64 + 64; n++) {
*mb_ptr = mmin(255,mmax(0,*mb_ptr));
mb_ptr++;
}
}
/* Encodes one frame intra using params */
void CodeIntraH263(CParam *params, Bits *bits)
{
unsigned int *new_recon;
MB_Structure *data = (MB_Structure *)malloc(sizeof(MB_Structure));
int *qcoeff;
int Mode = MODE_INTRA;
int CBP;
int i,j;
new_recon = params->recon;
ZeroBits(bits);
Global::pic->QUANT = params->Q_intra;
Global::pic->picture_coding_type = PCT_INTRA;
bits->header += CountBitsPicture(Global::pic);
for ( j = 0; j < Global::mbr; j++) {
/* insert sync in *every* slice if use_gobsync is chosen */
if (Global::pic->use_gobsync && j != 0)
bits->header += CountBitsSlice(j,params->Q_intra);
for ( i = 0; i < Global::mbc; i++) {
Global::pic->MB = i + j * Global::mbc;
bits->no_intra++;
FillLumBlock(i*MB_SIZE, j*MB_SIZE, params->data, data);
FillChromBlock(i*MB_SIZE, j*MB_SIZE, params->data, data);
qcoeff = MB_EncodeAndFindCBP(data, params->Q_intra, Mode, &CBP);
/* Do standard VLC encoding */
/* COD = 0 ,Every block is coded as Intra frame */
CountBitsMB(Mode,0,CBP,0,Global::pic,bits);
CountBitsCoeff(qcoeff, Mode, CBP,bits,64);
MB_Decode(qcoeff, data, params->Q_intra, Mode);
Clip(data);
ReconImage(i,j,data,new_recon);
free(qcoeff);
}
}
Global::pic->QP_mean = params->Q_intra;
params->recon = new_recon;
AddBitsPicture(bits);
free(data);
return;
}
/**********************************************************************
*
* Name: MB_Encode
* Description: DCT and quantization of Macroblocks
*
* Input: MB data struct, mquant (1-31, 0 = no quant),
* MB info struct
* Returns: Pointer to quantized coefficients
* Side effects:
*
* Date: 930128 Author:
coder.cpp为[网学网-网友上传,谢谢支持]。
*
**********************************************************************/
/* If you compare original quant with FindCBP, you see they both act
on the same range of coefficients in the cases INTRA (1..63) or
INTER (0..63) */
int *MB_EncodeAndFindCBP(MB_Structure *mb_orig, int QP, int I, int *CBP)
{
int i, j, k, l, row, col;
int fblock[64];
int coeff[384];
int *coeff_ind;
int *qcoeff;
int *qcoeff_ind;
int CBP_Mask = 32;
*CBP = 0; /* CBP gives bit pattern of lowest 6 bits
that specify which coordinates are not
zero. Bits 6 (32) to 2 (4) repr. four
8x8 Y parts of macroblock, while bits
1 (2) and 0 (1) repr. resp. the U and
V component */
if ((qcoeff=(int *)malloc(sizeof(int)*384)) == 0) {
fprintf(stderr,"mb_encode(): Couldn't allocate qcoeff.\n");
exit(0);
}
coeff_ind = coeff;
qcoeff_ind = qcoeff;
for (k=0;k<16;k+=8) {
for (l=0;l<16;l+=8) {
for (i=k,row=0;row<64;i++,row+=8) {
#if LONGISDOUBLEINT
for (j=l,col=0;col<8;j += 2,col +=2 ) {
*(long *) (fblock+row+col) = * (long *) &(mb_orig->lum[i][j]);
}
#else
for (j=l,col=0;col<8;j++ , col++ ) {
*(int *) (fblock+row+col) = * (int *) &(mb_orig->lum[i][j]);
}
#endif
}
Dct(fblock,coeff_ind);
*CBP |= QuantAndFindCBP(coeff_ind,qcoeff_ind,QP,I,CBP_Mask);
coeff_ind += 64;
qcoeff_ind += 64;
CBP_Mask = CBP_Mask>>1;
} /* end l */
} /* End k */
for (i=0;i<8;i++) {
#ifdef LONGISDOUBLEINT
for (j=0;j<8;j += 2) {
*(long *) (fblock+i*8+j) = *(long *) &(mb_orig->Cb[i][j]);
}
#else
for (j=0;j<8;j++) {
*(int *) (fblock+i*8+j) = *(int *) &(mb_orig->Cb[i][j]);
}
#endif
}
Dct(fblock,coeff_ind);
*CBP |= QuantAndFindCBP(coeff_ind,qcoeff_ind,QP,I,CBP_Mask /* i == 4 */);
coeff_ind += 64;
qcoeff_ind += 64;
CBP_Mask = CBP_Mask>>1;
for (i=0;i<8;i++) {
#ifdef LONGISDOUBLEINT
for (j=0;j<8;j += 2) {
* (long *) (fblock+i*8+j) = *(long *) &(mb_orig->Cr[i][j]);
}
#else
for (j=0;j<8;j ++) {
* (int *) (fblock+i*8+j) = *(int *) &(mb_orig->Cr[i][j]);
}
#endif
}
Dct(fblock,coeff_ind);
*CBP |= QuantAndFindCBP(coeff_ind,qcoeff_ind,QP,I, CBP_Mask /* i == 5 */);
return qcoeff;
}
/**********************************************************************
*
* Name: MB_Decode
* Description: Reconstruction of quantized DCT-coded Macroblocks
*
* Input: Quantized coefficie
上一篇:
codec_plugin.cpp
下一篇:
法律专业开题报告范文