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

📄 putseq.cpp

📁 mpeg2编码解码源程序代码
💻 CPP
字号:

/* putseq.c, sequence level routines                                        *//* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. *//* * Disclaimer of Warranty * * These software programs are available to the user without any license fee or * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims * any and all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose.  In no event shall the copyright-holder be liable for any * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and user's * customers, employees, agents, transferees, successors, and assigns. * * The MPEG Software Simulation Group does not represent or warrant that the * programs furnished hereunder are free of infringement of any third-party * patents. * * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, * are subject to royalty fees to patent holders.  Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. * */#include <stdio.h>#include <string.h>#include "config.h"#include "globalenc.h"
#include "global.h"


void readimage(LPBYTE dst, LPBYTE neworg[], long stride,long color)
{
	long iWidth=horizontal_size;
	LPBYTE lpData=dst;
	LPBYTE temp0,temp1,temp2;
    long off;
	long Width;
		int R,G,B;

	if(color==24)
		Width=horizontal_size*3;
	else
        Width=horizontal_size;
    if(stride<0)
	  off=abs(stride+Width);
   else
      off=stride-Width;



	temp0=neworg[0];
	temp1=neworg[1];
	temp2=neworg[2];
	int Y,U,V;
	for(int j=0;j<vertical_size;j++) 
	{	
		for(int i=0;i<horizontal_size*3;i+=3)
		{

		    if(color==8)
			{
			U=0;
			V=0;
			R=G=B=*lpData;
			lpData++;
		
			Y=77.0/256.0*R +150.0/256.0*G + 29.0/256.0*B ;
			U=-44.0/256.0*R - 87.0/256.0*G + 131.0/256.0*B + 128 ;
			V=131.0/256.0*R - 110.0/256.0*G - 21.0/256.0*B + 128 ;
			
			
			*temp0=Y;
			temp0++;
			if(j%2==0&&i%2==0)
			{
				*temp1=U;
				*temp2=V;
				temp1++;
				temp2++;
			}
			}
			else
			{
			U=0;
			V=0;
			B=*lpData;
			lpData++;
			G=*lpData;
			lpData++;
			R=*lpData;
			lpData++;
			
			Y=77.0/256.0*R +150.0/256.0*G + 29.0/256.0*B ;
			U=-44.0/256.0*R - 87.0/256.0*G + 131.0/256.0*B + 128 ;
			V=131.0/256.0*R - 110.0/256.0*G - 21.0/256.0*B + 128 ;
			
			*temp0=Y;
			temp0++;
			//	 putc(Y,fp1);
			if(j%2==0&&i%2==0)
			{
				*temp1=U;
				*temp2=V;
				temp1++;
				temp2++;
			}
			}
		}
		lpData+=off;
		if(stride<0)
		{
			lpData+=stride;
		    lpData+=stride;
		}
		
	}
}void putseq(int i,LPBYTE dst,long stride,long color){  /* this routine assumes (N % M) == 0 */  int  j, k, f, f0, n, np, nb, sxf, syf, sxb, syb;  int ipflag;  char name[256];  unsigned char *neworg[3], *newref[3];  static char ipb[5] = {' ','I','P','B','D'};    /* f0: lowest frame number in current GOP     *     * first GOP contains N-(M-1) frames,     * all other GOPs contain N frames     */    f0 = N*((i+(M-1))/N) - (M-1);
    if (f0<0)      f0=0;    if (i==0 || (i-1)%M==0)    {      /* I or P frame */      
	  for (j=0; j<3; j++)      {        /* shuffle reference frames */        neworg[j] = oldorgframe[j];        newref[j] = oldrefframe[j];        oldorgframe[j] = neworgframe[j];        oldrefframe[j] = newrefframe[j];        neworgframe[j] = neworg[j];        newrefframe[j] = newref[j];
	      }
         /* f: frame number in display order */      f = (i==0) ? 0 : i+M-1;      if (f>=nframes)        f = nframes - 1;      if (i==f0) /* first displayed frame in GOP is I */      {        /* I frame */        pict_type = I_TYPE;
        forw_hor_f_code = forw_vert_f_code = 15;
        back_hor_f_code = back_vert_f_code = 15;        /* n: number of frames in current GOP         *         * first GOP contains (M-1) less (B) frames         */        n = (i==0) ? N-(M-1) : N;        /* last GOP may contain less frames */        if (n > nframes-f0)          n = nframes-f0;        /* number of P frames */        if (i==0)          np = (n + 2*(M-1))/M - 1; /* first GOP */        else          np = (n + (M-1))/M - 1;        /* number of B frames */        nb = n - np - 1;        rc_init_GOP(np,nb);                   putgophdr(f0,i==0); /* set closed_GOP in first GOP only */      }      else      {        /* P frame */        pict_type = P_TYPE;        forw_hor_f_code = motion_data[0].forw_hor_f_code;        forw_vert_f_code = motion_data[0].forw_vert_f_code;        back_hor_f_code = back_vert_f_code = 15;        sxf = motion_data[0].sxf;        syf = motion_data[0].syf;      }    }    else    {      /* B frame */      for (j=0; j<3; j++)      {        neworg[j] = auxorgframe[j];        newref[j] = auxframe[j];      }      /* f: frame number in display order */      f = i - 1;      pict_type = B_TYPE;      n = (i-2)%M + 1; /* first B: n=1, second B: n=2, ... */      forw_hor_f_code = motion_data[n].forw_hor_f_code;      forw_vert_f_code = motion_data[n].forw_vert_f_code;      back_hor_f_code = motion_data[n].back_hor_f_code;      back_vert_f_code = motion_data[n].back_vert_f_code;      sxf = motion_data[n].sxf;      syf = motion_data[n].syf;      sxb = motion_data[n].sxb;      syb = motion_data[n].syb;    }
    temp_ref = f - f0;    frame_pred_dct = frame_pred_dct_tab[pict_type-1];    q_scale_type = qscale_tab[pict_type-1];    intravlc = intravlc_tab[pict_type-1];    altscan = altscan_tab[pict_type-1];   
	readimage(dst,neworg,stride,color);
    if (fieldpic)    {      if (!quiet)      {        fprintf(stderr,"\nfirst field  (%s) ",topfirst ? "top" : "bot");        fflush(stderr);      }      pict_struct = topfirst ? TOP_FIELD : BOTTOM_FIELD;      motion_estimation(oldorgframe[0],neworgframe[0],                        oldrefframe[0],newrefframe[0],                        neworg[0],newref[0],                        sxf,syf,sxb,syb,mbinfo,0,0);      predict(oldrefframe,newrefframe,predframe,0,mbinfo);      dct_type_estimation(predframe[0],neworg[0],mbinfo);      transform(predframe,neworg,mbinfo,blocks);      putpict(neworg[0]);      for (k=0; k<mb_height2*mb_width; k++)      {        if (mbinfo[k].mb_type & MB_INTRA)          for (j=0; j<block_count; j++)            iquant_intra(blocks[k*block_count+j],blocks[k*block_count+j],                         dc_prec,intra_q,mbinfo[k].mquant);        else          for (j=0;j<block_count;j++)            iquant_non_intra(blocks[k*block_count+j],blocks[k*block_count+j],                             inter_q,mbinfo[k].mquant);      }      itransform(predframe,newref,mbinfo,blocks);      calcSNR(neworg,newref);      stats();      if (!quiet)      {        fprintf(stderr,"second field (%s) ",topfirst ? "bot" : "top");        fflush(stderr);      }      pict_struct = topfirst ? BOTTOM_FIELD : TOP_FIELD;      ipflag = (pict_type==I_TYPE);      if (ipflag)      {        /* first field = I, second field = P */        pict_type = P_TYPE;        forw_hor_f_code = motion_data[0].forw_hor_f_code;        forw_vert_f_code = motion_data[0].forw_vert_f_code;        back_hor_f_code = back_vert_f_code = 15;        sxf = motion_data[0].sxf;        syf = motion_data[0].syf;      }      motion_estimation(oldorgframe[0],neworgframe[0],                        oldrefframe[0],newrefframe[0],                        neworg[0],newref[0],                        sxf,syf,sxb,syb,mbinfo,1,ipflag);      predict(oldrefframe,newrefframe,predframe,1,mbinfo);      dct_type_estimation(predframe[0],neworg[0],mbinfo);      transform(predframe,neworg,mbinfo,blocks);      putpict(neworg[0]);      for (k=0; k<mb_height2*mb_width; k++)      {        if (mbinfo[k].mb_type & MB_INTRA)          for (j=0; j<block_count; j++)            iquant_intra(blocks[k*block_count+j],blocks[k*block_count+j],                         dc_prec,intra_q,mbinfo[k].mquant);        else          for (j=0;j<block_count;j++)            iquant_non_intra(blocks[k*block_count+j],blocks[k*block_count+j],                             inter_q,mbinfo[k].mquant);      }      itransform(predframe,newref,mbinfo,blocks);      calcSNR(neworg,newref);      stats();    }    else    {      pict_struct = FRAME_PICTURE;      /* do motion_estimation       *       * uses source frames (...orgframe) for full pel search       * and reconstructed frames (...refframe) for half pel search       */      motion_estimation(oldorgframe[0],neworgframe[0],                        oldrefframe[0],newrefframe[0],                        neworg[0],newref[0],                        sxf,syf,sxb,syb,mbinfo,0,0);      predict(oldrefframe,newrefframe,predframe,0,mbinfo);      dct_type_estimation(predframe[0],neworg[0],mbinfo);      transform(predframe,neworg,mbinfo, blocks);      putpict(neworg[0]);      for (k=0; k<mb_height*mb_width; k++)      {        if (mbinfo[k].mb_type & MB_INTRA)          for (j=0; j<block_count; j++)            iquant_intra(blocks[k*block_count+j],blocks[k*block_count+j],                         dc_prec,intra_q,mbinfo[k].mquant);        else          for (j=0;j<block_count;j++)            iquant_non_intra(blocks[k*block_count+j],blocks[k*block_count+j],                             inter_q,mbinfo[k].mquant);      }      itransform(predframe,newref,mbinfo,blocks);      calcSNR(neworg,newref);      stats();    }}

⌨️ 快捷键说明

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