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

📄 fdct_idct.c

📁 Motion JPEG编解码器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  /* load the multiplication constants */  c4   = vec_splat( SpecialConstants, 0 );  /* c4 = cos(4*pi/16)  */  a0   = vec_splat( SpecialConstants, 1 );  /* a0 = c6/c2         */  a1   = vec_splat( SpecialConstants, 2 );  /* a1 = c7/c1         */  a2   = vec_splat( SpecialConstants, 3 );  /* a2 = c5/c3         */  mc4  = vec_splat( SpecialConstants, 4 );  /* -c4                */  ma2  = vec_splat( SpecialConstants, 5 );  /* -a2                */  zero = vec_splat_s16(0);  /* copy the rows of input data */#ifdef ORIGINAL_SOURCE  vec_ptr = ( vector signed short * ) input;#else  vec_ptr = ( vector signed short * ) blocks;#endif  vx[0] = vec_ptr[0];  vx[1] = vec_ptr[1];  vx[2] = vec_ptr[2];  vx[3] = vec_ptr[3];  vx[4] = vec_ptr[4];  vx[5] = vec_ptr[5];  vx[6] = vec_ptr[6];  vx[7] = vec_ptr[7];  /* Perform DCT first on the 8 columns */  DCT_Transform( vx, vy );  /* Transpose matrix to work on rows */  Matrix_Transpose( vy, vx );  /* Perform DCT first on the 8 rows */  DCT_Transform( vx, vy );#ifndef ORIGINAL_SOURCE  /* mpeg2enc requires the matrix transposed back */  Matrix_Transpose( vy, vx );#endif  /* Post-scale and store result. */#ifdef ORIGINAL_SOURCE  vec_ptr = (vector signed short *) output;#endif  vec_ptr[0] = vec_mradds( PostScale[0], vx[0], zero );  vec_ptr[1] = vec_mradds( PostScale[1], vx[1], zero );  vec_ptr[2] = vec_mradds( PostScale[2], vx[2], zero );  vec_ptr[3] = vec_mradds( PostScale[3], vx[3], zero );  vec_ptr[4] = vec_mradds( PostScale[4], vx[4], zero );  vec_ptr[5] = vec_mradds( PostScale[5], vx[5], zero );  vec_ptr[6] = vec_mradds( PostScale[6], vx[6], zero );  vec_ptr[7] = vec_mradds( PostScale[7], vx[7], zero );}/*************************************************************** * * Copyright:   (c) Copyright Motorola Inc. 1998 * * Date:        April 20, 1998 * * Macro:       IDCT_Transform * * Description: Discrete Cosign Transform implemented by the *              Scaled Chen (III) Algorithm developed by Haifa *              Research Lab.  The major difference between this *              algorithm and the Scaled Chen (I) is that *              certain multiply-subtracts are replaced by *              multiply adds.  A full description of the *              Scaled Chen (I) algorithm can be found in: *              W.C.Chen, C.H.Smith and S.C.Fralick, "A Fast *              Computational Algorithm for the Discrete Cosine *              Transform", IEEE Transactions on Commnuications, *              Vol. COM-25, No. 9, pp 1004-1009, Sept. 1997. * * Inputs:      vx     : array of vector short *              t1-t10 : temporary vector variables set up by caller *              c4     : cos(4*pi/16) *              mc4    : -c4 *              a0     : c6/c2 *              a1     : c7/c1 *              a2     : c5/c3 *              ma2    : -a2 *              zero   : an array of zero elements * * Outputs:     vy     : array of vector short * **************************************************************/#define IDCT_Transform(vx,vy) \                                                                  \  /* 1st stage. */                                                \  t9 = vec_mradds( a1, vx[1], zero );  /* t8 = (a1) * x1 - x7  */ \  t8 = vec_subs( t9, vx[7]);                                      \  t1 = vec_mradds( a1, vx[7], vx[1] ); /* t1 = (a1) * x7 + x1  */ \  t7 = vec_mradds( a2, vx[5], vx[3] ); /* t7 = (a2) * x5 + x3  */ \  t3 = vec_mradds( ma2, vx[3], vx[5] );/* t3 = (-a2) * x5 + x3 */ \                                                                  \  /* 2nd stage */                                                 \  t5 = vec_adds( vx[0], vx[4] );        /* t5 = x0 + x4 */        \  t0 = vec_subs( vx[0], vx[4] );        /* t0 = x0 - x4 */        \  t9 = vec_mradds( a0, vx[2], zero );   /* t4 = (a0) * x2 - x6 */ \  t4 = vec_subs( t9, vx[6] );                                     \  t2 = vec_mradds( a0, vx[6], vx[2] );  /* t2 = (a0) * x6 + x2 */ \                                                                  \  t6 = vec_adds( t8, t3 );              /* t6 = t8 + t3 */        \  t3 = vec_subs( t8, t3 );              /* t3 = t8 - t3 */        \  t8 = vec_subs( t1, t7 );              /* t8 = t1 - t7 */        \  t1 = vec_adds( t1, t7 );              /* t1 = t1 + t7 */        \                                                                  \  /* 3rd stage. */                                                \  t7 = vec_adds( t5, t2 );              /* t7 = t5 + t2 */        \  t2 = vec_subs( t5, t2 );              /* t2 = t5 - t2 */        \  t5 = vec_adds( t0, t4 );              /* t5 = t0 + t4 */        \  t0 = vec_subs( t0, t4 );              /* t0 = t0 - t4 */        \                                                                  \  t4 = vec_subs( t8, t3 );              /* t4 = t8 - t3 */        \  t3 = vec_adds( t8, t3 );              /* t3 = t8 + t3 */        \                                                                  \  /* 4th stage. */                                                \  vy[0] = vec_adds( t7, t1 );        /* y0 = t7 + t1 */           \  vy[7] = vec_subs( t7, t1 );        /* y7 = t7 - t1 */           \  vy[1] = vec_mradds( c4, t3, t5 );  /* y1 = (c4) * t3 + t5  */   \  vy[6] = vec_mradds( mc4, t3, t5 ); /* y6 = (-c4) * t3 + t5 */   \  vy[2] = vec_mradds( c4, t4, t0 );  /* y2 = (c4) * t4 + t0  */   \  vy[5] = vec_mradds( mc4, t4, t0 ); /* y5 = (-c4) * t4 + t0 */   \  vy[3] = vec_adds( t2, t6 );        /* y3 = t2 + t6 */           \  vy[4] = vec_subs( t2, t6 );        /* y4 = t2 - t6 *//* Pre-Scaling matrix -- scaled by 1 */static const vector signed short PreScale[8] = {    (vector signed short)VCONST(4095, 5681, 5351, 4816, 4095, 4816, 5351, 5681),    (vector signed short)VCONST(5681, 7880, 7422, 6680, 5681, 6680, 7422, 7880),    (vector signed short)VCONST(5351, 7422, 6992, 6292, 5351, 6292, 6992, 7422),    (vector signed short)VCONST(4816, 6680, 6292, 5663, 4816, 5663, 6292, 6680),    (vector signed short)VCONST(4095, 5681, 5351, 4816, 4095, 4816, 5351, 5681),    (vector signed short)VCONST(4816, 6680, 6292, 5663, 4816, 5663, 6292, 6680),    (vector signed short)VCONST(5351, 7422, 6992, 6292, 5351, 6292, 6992, 7422),    (vector signed short)VCONST(5681, 7880, 7422, 6680, 5681, 6680, 7422, 7880)};/*************************************************************** * * Copyright:   (c) Copyright Motorola Inc. 1998 * * Date:        April 17, 1998 * * Function:    IDCT * * Description: Scaled Chen (III) algorithm for IDCT *              Arithmetic is 16-bit fixed point. * * Inputs:      input - Pointer to input data (short), which *                      must be between -2048 to +2047. *                      It is assumed that the allocated array *                      has been 128-bit aligned and contains *                      8x8 short elements. * * Outputs:     output - Pointer to output area for the transfored *                       data. The output values are between -255 *                       and 255 . It is assumed that a 128-bit *                       aligned 8x8 array of short has been *                       pre-allocated. * * Return:      None * ***************************************************************/#ifdef ORIGINAL_SOURCEvoid IDCT(short *input, short *output) {#elsevoid idct_altivec_old(short *block) {#endif  vector signed short t0, t1, t2, t3, t4, t5, t6, t7, t8, t9;  vector signed short a0, a1, a2, ma2, c4, mc4, zero;  vector signed short vx[8], vy[8];  vector signed short *vec_ptr;  /* used for conversion between                                    arrays of short and vector                                    signed short array.  */  /* Load the multiplication constants. */  c4   = vec_splat( SpecialConstants, 0 );  /* c4 = cos(4*pi/16)  */  a0   = vec_splat( SpecialConstants, 1 );  /* a0 = c6/c2         */  a1   = vec_splat( SpecialConstants, 2 );  /* a1 = c7/c1         */  a2   = vec_splat( SpecialConstants, 3 );  /* a2 = c5/c3         */  mc4  = vec_splat( SpecialConstants, 4 );  /* -c4                */  ma2  = vec_splat( SpecialConstants, 5 );  /* -a2                */  zero = vec_splat_s16(0);  /* Load the rows of input data and Pre-Scale them. */#ifdef ORIGINAL_SOURCE  vec_ptr = ( vector signed short * ) input;#else  vec_ptr = ( vector signed short * ) block;#endif  vx[0] = vec_mradds( vec_ptr[0], PreScale[0], zero );  vx[1] = vec_mradds( vec_ptr[1], PreScale[1], zero );  vx[2] = vec_mradds( vec_ptr[2], PreScale[2], zero );  vx[3] = vec_mradds( vec_ptr[3], PreScale[3], zero );  vx[4] = vec_mradds( vec_ptr[4], PreScale[4], zero );  vx[5] = vec_mradds( vec_ptr[5], PreScale[5], zero );  vx[6] = vec_mradds( vec_ptr[6], PreScale[6], zero );  vx[7] = vec_mradds( vec_ptr[7], PreScale[7], zero );  /* Perform IDCT first on the 8 columns */  IDCT_Transform( vx, vy );  /* Transpose matrix to work on rows */  Matrix_Transpose( vy, vx );  /* Perform IDCT next on the 8 rows */  IDCT_Transform( vx, vy );#ifndef ORIGINAL_SOURCE  /* mpeg2enc requires the matrix transposed back */  Matrix_Transpose( vy, vx );#endif  /* Post-scale and store result. */#ifdef ORIGINAL_SOURCE  vec_ptr = (vector signed short *) output;#endif  vec_ptr[0] = vx[0];  vec_ptr[1] = vx[1];  vec_ptr[2] = vx[2];  vec_ptr[3] = vx[3];  vec_ptr[4] = vx[4];  vec_ptr[5] = vx[5];  vec_ptr[6] = vx[6];  vec_ptr[7] = vx[7];}

⌨️ 快捷键说明

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