⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sim.h

📁 对视频进行压缩和解压缩的代码
💻 H
字号:
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<limits.h>#include "config_e.h"#include "macros.h"/* This should not be changed */#define MB_SIZE 16#define MBC   88#define MBR   72/* Parameters from TMN */#define PREF_NULL_VEC 100#define PREF_16_VEC 200#define PREF_PBDELTA_NULL_VEC 50int headerlength; /* Global variables */int pels;int cpels;int lines;int trace;int advanced;int syntax_arith_coding;int pb_frames;int mv_outside_frame;int long_vectors;float target_framerate;FILE *tf;/****************************/#define PSC        1#define PSC_LENGTH        17#define ESCAPE                          7167#define PCT_INTER                       1#define PCT_INTRA                       0#define ON                              1#define OFF                             0#define SF_SQCIF                        1  /* 001 */#define SF_QCIF                         2  /* 010 */#define SF_CIF                          3  /* 011 */#define SF_4CIF                         4  /* 100 */#define SF_16CIF                        5  /* 101 */#define MODE_INTER                      0#define MODE_INTER_Q                    1#define MODE_INTER4V                    2#define MODE_INTRA                      3#define MODE_INTRA_Q                    4#define PBMODE_NORMAL                   0#define PBMODE_MVDB                     1#define PBMODE_CBPB_MVDB                2#define NO_VEC                          999/* Motionvector structure */typedef struct motionvector
 {  int x;        /* Horizontal comp. of mv         */  int y;        /* Vertical comp. of mv         */  int x_half;        /* Horizontal half-pel acc.	 */  int y_half;        /* Vertical half-pel acc.	 */  int min_error;        /* Min error for this vector	 */  int Mode;                     /* Necessary for adv. pred. mode */} MotionVector;/* Point structure */typedef struct point 
{  int x;  int y;} Point;/* Structure with image data */typedef struct pict_image 
{  unsigned char *lum;        /* Luminance plane        */  unsigned char *Cr;        /* Cr plane        */  unsigned char *Cb;        /* Cb plane        */} PictImage;/* Group of pictures structure. *//* Picture structure */typedef struct pict 
{  int prev;   int curr;  int TR;             /* Time reference */  int bit_rate;  int src_frame_rate;  float target_frame_rate;  int source_format;  int picture_coding_type;  int spare;  int unrestricted_mv_mode;  int PB;  int QUANT;  int DQUANT;  int MB;  int seek_dist;        /* Motion vector search window */  int use_gobsync;      /* flag for gob_sync */  int MODB;             /* B-frame mode */  int BQUANT;           /* which quantizer to use for B-MBs in PB-frame */  int TRB;              /* Time reference for B-picture */  float QP_mean;        /* mean quantizer */} Pict;/* Slice structure */typedef struct slice
 {  unsigned int vert_pos;	/* Vertical position of slice        */  unsigned int quant_scale;	/* Quantization scale        */} Slice;/* Macroblock structure */typedef struct macroblock 
{  int mb_address;        /* Macroblock address        */  int macroblock_type;        /* Macroblock type        */  int skipped;        /* 1 if skipped        */  MotionVector motion;	        /* Motion Vector        */} Macroblock;/* Structure for macroblock data */typedef struct mb_structure 
{  short int lum[16][16];  short int Cr[8][8];  short int Cb[8][8];} MB_Structure;/* Structure for counted bits */typedef struct bits_counted {  int Y;  int C;  int vec;  int CBPY;  int CBPCM;  int MODB;  int CBPB;  int COD;  int header;  int DQUANT;  int total;  int no_inter;  int no_inter4v;  int no_intra;/* NB: Remember to change AddBits(), ZeroBits() and AddBitsPicture()    when entries are added here */} Bits;/* Structure for data from previous macroblock *//* Structure for average results and virtal buffer data */typedef struct results {  float SNR_l;        /* SNR for luminance */  float SNR_Cr;        /* SNR for chrominance */  float SNR_Cb;  float QP_mean;                /* Mean quantizer */} Results;int NextTwoPB(PictImage *p2, PictImage *bim, PictImage *p1,               int bskip, int pskip, int seek_dist);
void WriteImage(PictImage *image, char *filename);PictImage *InitImage(int size);void FreeImage(PictImage *image);char *StripName(char *s);short int *MB_Encode(MB_Structure *mb_orig, int QP, int I);int MB_Decode(short int *qcoeff, MB_Structure *mb_recon, int QP, int I);int Dct( short int *block, short int *coeff );int idct( short int *coeff,short int *block );void CodeOneOrTwo(PictImage *curr, PictImage *B_image, PictImage *prev,           PictImage *prev_recon, int QP, int frameskip, Bits *bits,          Pict *pic, PictImage *B_recon, PictImage *recon);PictImage *CodeOneIntra(PictImage *curr, int QP, Bits *bits, Pict *pic);int FindCBP(short int *qcoeff, int Mode, int ncoeffs);void CountBitsVectors(MotionVector *MV[5][MBR+1][MBC+2], Bits *bits,               int i, int j, int Mode, int newgob, Pict *pic);void FindPMV(MotionVector *MV[5][MBR+1][MBC+2], int x, int y,              int *p0, int *p1, int block, int newgob, int half_pel);void ZeroBits(Bits *bits);void ZeroRes(Results *res);void ZeroVec(MotionVector *MV);void MarkVec(MotionVector *MV);void CopyVec(MotionVector *MV1, MotionVector *MV2);int EqualVec(MotionVector *MV2, MotionVector *MV1);void AddBits(Bits *total, Bits *bits);void AddRes(Results *total, Results *res, Pict *pic);void AddBitsPicture(Bits *bits);MB_Structure *MB_Recon(PictImage *prev_recon, MB_Structure *diff,               int x_curr, int y_curr, MotionVector *MV);MB_Structure *Predict(PictImage *curr, PictImage *prev_recon,              int x_curr, int y_curr, MotionVector *MV);unsigned char *InterpolateImage(unsigned char *image, int w, int h);void MotionEstimatePicture(unsigned char *curr, unsigned char *prev,            unsigned char *prev_ipol, int seek_dist,            MotionVector *MV[5][MBR+1][MBC+2], int gobsync);void MotionEstimation(unsigned char *curr, unsigned char *prev, int x_curr,              int y_curr, int xoff, int yoff, int seek_dist,               MotionVector *MV[5][MBR+1][MBC+2], int *sad_0);int SAD_Macroblock(unsigned char *ii, unsigned char *act_block,           int h_length, int Min_FRAME);int SAD_MB_Bidir(unsigned char *ii, unsigned char *aa, unsigned char *bb,          int width, int min_sofar);MB_Structure *Predict_P(PictImage *curr_image, PictImage *prev_image,        unsigned char *prev_ipol,int x_curr, int y_curr,         MotionVector *fr[5][MBR+1][MBC+2], int PB);void DoPredChrom_P(int x_curr, int y_curr, int dx, int dy,           PictImage *curr, PictImage *prev,            MB_Structure *pred_error);void FindPredOBMC(int x, int y, MotionVector *MV[5][MBR+1][MBC+2],                   unsigned char *prev, int *pred, int comp, int PB);MB_Structure *MB_Recon_P(PictImage *prev_image, unsigned char *prev_ipol,                         MB_Structure *diff, int x_curr, int y_curr,                          MotionVector *MV[5][MBR+1][MBC+2], int PB);void ReconChromBlock_P(int x_curr, int y_curr, int dx, int dy,               PictImage *prev, MB_Structure *data);void FindChromBlock_P(int x_curr, int y_curr, int dx, int dy,               PictImage *prev, MB_Structure *data);  void ZeroMBlock(MB_Structure *data);int CountBitsPicture(Pict *pic);void CountBitsMB(int Mode, int COD, int CBP, int CBPB, Pict *pic, Bits *bits);int CountBitsSlice(int slice, int quant);int ModifyMode(int Mode, int dquant);int *InterleaveCoeff(int *qp, int *qb, int bs);void MakeEdgeImage(unsigned char *src, unsigned char *dst, int width,           int height, int edge);void BitPrint(int length, int val, char *bit);#ifdef OFFLINE_RATE_CONTROLint FrameUpdateQP(int buf, int bits, int frames_left, int QP, int B,           float seconds);#elseint UpdateQuantizer(int mb, float QP_mean, int pict_type, float bit_rate,                     int mb_width, int mb_height, int bitcount) ;int InitializeQuantizer(int pict_type, float bit_rate,                                            float target_frame_rate, float QP_mean);void InitializeRateControl();void UpdateRateControl(int bits);#endif/* Syntax based arithmetic coding routines */int AR_Encode(int index, int cumul_freq[]);int indexfn(int value, int table[], int max);int bit_opp_bits(int);int bit_in_psc_layer(int);int encoder_flush();/* bitstream-functions */void initbits();void putbits (int, int);int alignbits ();int bitcount();/* Fix broken header-files on suns to avoid compiler warnings *//* #define BROKEN_SUN_HEADERS here or in Makefile */#ifdef BROKEN_SUN_HEADERSextern int printf();extern int fprintf();extern int time();extern int fclose();extern int rewind();extern int fseek();extern int fread();extern int fwrite();extern int fflush();extern int fscanf();extern int _flsbuf();extern int _filbuf();#endif

PictImage *ReadImage();int Dct_MY( short int *block, short int *coeff);
int Idct_MY( short int *coeff,short int *block );
void Quant_MY(short int *coeff, short int *qcoeff, int QP, int Mode);
void Dequant_MY(short int *qcoeff, short int *rcoeff, int QP, int I);
void SAD_MY(unsigned char *ii, unsigned char *act_block, 
			int h_length, MotionVector *MV, int *min_sofar);
int SAD_Macroblock_MY(unsigned char *ii, unsigned char *act_block, int h_length, int Min_FRAME);
void ReconImage_MY(int i, int j, MB_Structure *data, PictImage *recon);
int ChooseMode_MY(unsigned char *curr, int x_pos, int y_pos, int min_SAD);
void FindHalfPel_MY(int x, int y, MotionVector *MV, unsigned char *prev, 
					short int *curr, int bs, int comp);
void FindMB_MY(int x, int y, unsigned char *image, short int MB[16][16]);
void FindPred_MY(int x, int y, MotionVector *fr, unsigned char *prev, 
                 short int *pred, int bs, int comp);
void ReconLumBlock_P_MY(int x, int y, MotionVector *fr,
                        unsigned char *prev, short int *data,int bs,int comp);
void Clip_MY(MB_Structure *data);
void CountBitsCoeff_MY(short int *qcoeff, int I, int CBP, Bits *bits, int ncoeffs);
int CodeCoeff_MY(int Mode, short int *qcoeff, int block, int ncoeffs);
unsigned char *LoadArea_MY1(unsigned char *im, int x, int y, int x_size, int y_size, int lx);
unsigned char *LoadArea_MY2(unsigned char *im, int x, int y, int x_size, int y_size, int lx);
void FillLumBlock_MY( int x, int y, PictImage *image, MB_Structure *data);
void FillChromBlock_MY(int x_curr, int y_curr, PictImage *image, MB_Structure *data);
unsigned char *InterpolateImage_MY(unsigned char *image, int w, int h);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -