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

📄 dct.cpp

📁 实现一个简单的视频聊天
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      /* temp0 through tmp7:  -512 to +512 */      /* if I-block, then -256 to +256 */      tmp0 = inptr[7] + inptr[0];      tmp1 = inptr[6] + inptr[1];      tmp2 = inptr[5] + inptr[2];      tmp3 = inptr[4] + inptr[3];      tmp4 = inptr[3] - inptr[4];      tmp5 = inptr[2] - inptr[5];      tmp6 = inptr[1] - inptr[6];      tmp7 = inptr[0] - inptr[7];            /* tmp10 through tmp13:  -1024 to +1024 */      /* if I-block, then -512 to +512 */      tmp10 = tmp3 + tmp0;      tmp11 = tmp2 + tmp1;      tmp12 = tmp1 - tmp2;            tmp13 = tmp0 - tmp3;            outptr[ zigzag[0][columncounter] ] = (int32) UNFIXH((tmp10 + tmp11) * SIN_1_4);      outptr[ zigzag[4][columncounter] ] = (int32) UNFIXH((tmp10 - tmp11) * COS_1_4);            outptr[ zigzag[2][columncounter] ] = (int32) UNFIXH(tmp13 * COS_1_8 + tmp12 * SIN_1_8);      outptr[ zigzag[6][columncounter] ] = (int32) UNFIXH(tmp13 * SIN_1_8 - tmp12 * COS_1_8);            tmp16 = UNFIXO((tmp6 + tmp5) * SIN_1_4);      tmp15 = UNFIXO((tmp6 - tmp5) * COS_1_4);            OVERSHIFT(tmp4);      OVERSHIFT(tmp7);            /*       * tmp4, tmp7, tmp15, tmp16 are overscaled by       * OVERSCALE       */            tmp14 = tmp4 + tmp15;      tmp25 = tmp4 - tmp15;      tmp26 = tmp7 - tmp16;      tmp17 = tmp7 + tmp16;            outptr[ zigzag[1][columncounter] ] = (int32) UNFIXH(tmp17 * OCOS_1_16 + tmp14 * OSIN_1_16);      outptr[ zigzag[7][columncounter] ] = (int32) UNFIXH(tmp17 * OCOS_7_16 - tmp14 * OSIN_7_16);      outptr[ zigzag[5][columncounter] ] = (int32) UNFIXH(tmp26 * OCOS_5_16 + tmp25 * OSIN_5_16);      outptr[ zigzag[3][columncounter] ] = (int32) UNFIXH(tmp26 * OCOS_3_16 - tmp25 * OSIN_3_16);            inptr += DCTSIZE;	/* advance inptr to next row */	                   /*      outptr++;*/		/* advance outptr to next column */      columncounter++;    }				/* END OF PASS TWO */}int Dct( int *block, int *coeff){  mp_fwd_dct_fast( *(Block *) &block[0], *(Block *) &coeff[0]);  return 0; }      #endif /* End of ifnotdef FASTDCT */#define FASTIDCT 10
#ifdef FASTIDCT/********************************************************************** * *	Name:		idct *	Description:	Descans zigzag-scanned coefficients and does *			inverse dct on 64 coefficients *                      single precision floats * *	Input:		64 coefficients, block for 64 pixels *	Returns:    	0 *	Side effects:	 * *	Date: 930128	Author: Robert.Danielsen@nta.no * **********************************************************************/int idct(int *coeff,int *block){  int 	        j1, i, j;  double 	b[8], b1[8], d[8][8];  double 	f0=.7071068, f1=.4903926, f2=.4619398, f3=.4157348;  double	        f4=.3535534;  double 	f5=.2777851, f6=.1913417, f7=.0975452;  double 	e, f, g, h;  /* Horizontal */  /* Descan coefficients first */  for (i = 0; i < 8; i++) {    for (j = 0; j < 8; j++) {      b[j] = *( coeff + zigzag[i][j]);    }    e = b[1] * f7 - b[7] * f1;    h = b[7] * f7 + b[1] * f1;    f = b[5] * f3 - b[3] * f5;    g = b[3] * f3 + b[5] * f5;    b1[0] = (b[0] + b[4]) * f4;    b1[1] = (b[0] - b[4]) * f4;    b1[2] = b[2] * f6 - b[6] * f2;    b1[3] = b[6] * f6 + b[2] * f2;    b[4] = e + f;    b1[5] = e - f;    b1[6] = h - g;    b[7] = h + g;        b[5] = (b1[6] - b1[5]) * f0;    b[6] = (b1[6] + b1[5]) * f0;    b[0] = b1[0] + b1[3];    b[1] = b1[1] + b1[2];    b[2] = b1[1] - b1[2];    b[3] = b1[0] - b1[3];    for (j = 0; j < 4; j++) {      j1 = 7 - j;      d[i][j] = b[j] + b[j1];      d[i][j1] = b[j] - b[j1];    }  }  /* Vertical */    for (i = 0; i < 8; i++) {    for (j = 0; j < 8; j++) {      b[j] = d[j][i];    }    e = b[1] * f7 - b[7] * f1;    h = b[7] * f7 + b[1] * f1;    f = b[5] * f3 - b[3] * f5;    g = b[3] * f3 + b[5] * f5;    b1[0] = (b[0] + b[4]) * f4;    b1[1] = (b[0] - b[4]) * f4;    b1[2] = b[2] * f6 - b[6] * f2;    b1[3] = b[6] * f6 + b[2] * f2;    b[4] = e + f;    b1[5] = e - f;    b1[6] = h - g;    b[7] = h + g;    b[5] = (b1[6] - b1[5]) * f0;    b[6] = (b1[6] + b1[5]) * f0;    b[0] = b1[0] + b1[3];    b[1] = b1[1] + b1[2];    b[2] = b1[1] - b1[2];    b[3] = b1[0] - b1[3];    for (j = 0; j < 4; j++) {      j1 = 7 - j;      d[j][i] = b[j] + b[j1];      d[j1][i] = b[j] - b[j1];    }  }  for (i = 0; i < 8; i++) {    for (j = 0; j < 8; j++) {      *(block + i * 8 + j) = mnint(d[i][j]);    }  }  return 0;}#elif VERYFASTIDCT/* * tmndecode  * Copyright (C) 1995 Telenor R&D *                    Karl Olav Lillevold <kol@nta.no>                     * * based on mpeg2decode, (C) 1994, MPEG Software Simulation Group * and mpeg2play, (C) 1994 Stefan Eckart *                         <stefan@lis.e-technik.tu-muenchen.de> * *//**********************************************************//* inverse two dimensional DCT, Chen-Wang algorithm       *//* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984)             *//* 32-bit integer arithmetic (8 bit coefficients)         *//* 11 mults, 29 adds per DCT                              *//*                                      sE, 18.8.91       *//**********************************************************//* coefficients extended to 12 bit for IEEE1180-1990      *//* compliance                           sE,  2.1.94       *//**********************************************************//* this code assumes >> to be a two's-complement arithmetic *//* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */#define W7 565  /* 2048*sqrt(2)*cos(7*pi/16) *//* private data */static int iclip[1024]; /* clipping table */static int *iclp;/* private prototypes */static void idctrow(int *blk);static void idctcol(int *blk);/* row (horizontal) IDCT * *           7                       pi         1 * dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l ) *          l=0                      8          2 * * where: c[0]    = 128 *        c[1..7] = 128*sqrt(2) */static void idctrow(int *blk){  int x0, x1, x2, x3, x4, x5, x6, x7, x8;  /* shortcut */  if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |        (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])))  {    blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;    return;  }  x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */  /* first stage */  x8 = W7*(x4+x5);  x4 = x8 + (W1-W7)*x4;  x5 = x8 - (W1+W7)*x5;  x8 = W3*(x6+x7);  x6 = x8 - (W3-W5)*x6;  x7 = x8 - (W3+W5)*x7;    /* second stage */  x8 = x0 + x1;  x0 -= x1;  x1 = W6*(x3+x2);  x2 = x1 - (W2+W6)*x2;  x3 = x1 + (W2-W6)*x3;  x1 = x4 + x6;  x4 -= x6;  x6 = x5 + x7;  x5 -= x7;    /* third stage */  x7 = x8 + x3;  x8 -= x3;  x3 = x0 + x2;  x0 -= x2;  x2 = (181*(x4+x5)+128)>>8;  x4 = (181*(x4-x5)+128)>>8;    /* fourth stage */  blk[0] = (x7+x1)>>8;  blk[1] = (x3+x2)>>8;  blk[2] = (x0+x4)>>8;  blk[3] = (x8+x6)>>8;  blk[4] = (x8-x6)>>8;  blk[5] = (x0-x4)>>8;  blk[6] = (x3-x2)>>8;  blk[7] = (x7-x1)>>8;}/* column (vertical) IDCT * *             7                         pi         1 * dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l ) *            l=0                        8          2 * * where: c[0]    = 1/1024 *        c[1..7] = (1/1024)*sqrt(2) */__inline__ static void idctcol(int *blk){  int x0, x1, x2, x3, x4, x5, x6, x7, x8;  /* shortcut */  if (!((x1 = (blk[32]<<8)) | (x2 = blk[48]) | (x3 = blk[16]) |        (x4 = blk[8]) | (x5 = blk[56]) | (x6 = blk[40]) | (x7 = blk[24])))  {    blk[0]=blk[8]=blk[16]=blk[24]=blk[32]=blk[40]=blk[48]=blk[56]=      iclp[(blk[0]+32)>>6];    return;  }  x0 = (blk[8*0]<<8) + 8192;  /* first stage */  x8 = W7*(x4+x5) + 4;  x4 = (x8+(W1-W7)*x4)>>3;  x5 = (x8-(W1+W7)*x5)>>3;  x8 = W3*(x6+x7) + 4;  x6 = (x8-(W3-W5)*x6)>>3;  x7 = (x8-(W3+W5)*x7)>>3;    /* second stage */  x8 = x0 + x1;  x0 -= x1;  x1 = W6*(x3+x2) + 4;  x2 = (x1-(W2+W6)*x2)>>3;  x3 = (x1+(W2-W6)*x3)>>3;  x1 = x4 + x6;  x4 -= x6;  x6 = x5 + x7;  x5 -= x7;    /* third stage */  x7 = x8 + x3;  x8 -= x3;  x3 = x0 + x2;  x0 -= x2;  x2 = (181*(x4+x5)+128)>>8;  x4 = (181*(x4-x5)+128)>>8;    /* fourth stage */  blk[0] = iclp[(x7+x1)>>14];  blk[8] = iclp[(x3+x2)>>14];  blk[16] = iclp[(x0+x4)>>14];  blk[24] = iclp[(x8+x6)>>14];  blk[32] = iclp[(x8-x6)>>14];  blk[40] = iclp[(x0-x4)>>14];  blk[48] = iclp[(x3-x2)>>14];  blk[56] = iclp[(x7-x1)>>14];}/* two dimensional inverse discrete cosine transform */int idct(int *coeff, int *block){  int i;  extern int zigzag[8][8];  int *block_ptr, *zigzag_ptr;  block_ptr = block; zigzag_ptr = &(zigzag[0][0]);  for (i = 0; i < 8; i++) {    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    *(block_ptr++) = *(coeff + *(zigzag_ptr++));    /* WAS:     block[j + i*8] = (int) *( coeff + zigzag[i][j]); */  }  for (i=0; i<8; i++)    idctrow(block+8*i);    for (i=0; i<8; i++)    idctcol(block+i);    return 0;}void init_idct(){  int i;  iclp = iclip+512;  for (i= -512; i<512; i++)    iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);}#else/*  Perform IEEE 1180 reference (64-bit floating point, separable 8x1 *  direct matrix multiply) Inverse Discrete Cosine Transform*//* Here we use math.h to generate constants.  Compiler results may   vary a little *//* private data *//* cosine transform matrix for 8x1 IDCT */static double c[8][8];/* initialize DCT coefficient matrix */void init_idctref(){  int freq, time;  double scale;  for (freq=0; freq < 8; freq++)  {    scale = (freq == 0) ? sqrt(0.125) : 0.5;    for (time=0; time<8; time++)      c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));  }}/* perform IDCT matrix multiply for 8x8 coefficient block */void idctref(int *coeff, int *block){  int i, j, k, v;  double partial_product;  double tmp[64];  int tmp2[64];  extern int zigzag[8][8];  for (i=0; i<8; i++)    for (j=0; j<8; j++)      tmp2[j+i*8] = *(coeff + zigzag[i][j]);  for (i=0; i<8; i++)    for (j=0; j<8; j++)    {      partial_product = 0.0;      for (k=0; k<8; k++)        partial_product+= c[k][j]*tmp2[8*i+k];      tmp[8*i+j] = partial_product;    }  /* Transpose operation is integrated into address mapping by switching      loop order of i and j */  for (j=0; j<8; j++)    for (i=0; i<8; i++)    {      partial_product = 0.0;      for (k=0; k<8; k++)        partial_product+= c[k][i]*tmp[8*k+j];      v = floor(partial_product+0.5);      block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);    }}#endif

⌨️ 快捷键说明

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