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

📄 jpegidct_int.c

📁 jpeg图像文件软件解码器的arm版本的源代码程序
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  JPEGIDCT_int.c
//
//  DESCRIPTION
//       Implement the fast IDCT algorithm. 
//
//       The implementation is based on IJG's jpeg code, which is in turn based
//       on the algorithm proposed by Arai, Agui, and Nakajima's algorithm for
//       scaled DCT, published on Trans. IEICE E-71(11):1095.
//       The quantization is performed in Huffman decoding so no computation is
//       wasted on unnecessary multiplications.
//
//       This module is implemented in order to verify the accuracy of the MMX
//       implmentation.
//       On a non-PC platform. This module should be optimized in order to 
//       speedup IDCT process.
//       In order to take the advantage of the fact that majority of the 
//       coefficients are zero, some special IDCT cases are implemented. 
//       Specifically,
//         1. If all coefficients are zero, do nothing, area is always clear,
//         2. If the first coefficient is non-zero, copy the DC value,
//         3. If the first 2 coefficients are non-zero, do special 2-point
//        IDCT,
//         4. If the first 4 coefficients are non-zero, do special 4-point
//        IDCT.
//   
//       More categories can be defined.
//
///////////////////////////////////////////////////////////////////////////////

#include "irom_PlatformDefines.h"

#if USE_C

#define COEFF_SCALE_BITS        5

/*
#define CONST_BITS            12
#define SHIFT_OFFSET        2048

#define FIX_1_082392200        4433    // FIX(1.082392200)
#define FIX_1_414213562        5793    // FIX(1.414213562)
#define FIX_1_847759065        7568    // FIX(1.847759065)
#define FIX_2_613125930        10703    // FIX(2.613125930)      */


/*
#define CONST_BITS            8
#define SHIFT_OFFSET        128

#define FIX_1_082392200        277        // FIX(1.082392200)
#define FIX_1_414213562        362        // FIX(1.414213562)
#define FIX_1_847759065        473        // FIX(1.847759065)
#define FIX_2_613125930        669        // FIX(2.613125930)     */

#define CONST_BITS              7
#define SHIFT_OFFSET            64

#define FIX_1_082392200         139        // FIX(1.082392200)
#define FIX_1_414213562         181        // FIX(1.414213562)
#define FIX_1_847759065         237        // FIX(1.847759065)
#define FIX_2_613125930         334        // FIX(2.613125930)    


#define MULTIPLY(var, const)  (((var) * (const)) >> CONST_BITS)

/////////////////////////////////////////////////////////////////////////////
// NAME  
//            JPEGIDCT_int
//
// DESCRIPTION
//            IDCT transform for JPEG decoding.
//
// INPUTS   
//            coeffBlock - pointer to coefficient block buffer
//            imageBlock - pointer to image block buffer
// 
// OUTPUTS  
//            imageBlock - stores transform result in this buffer        
//
// RETURN VALUE
//          none.    
//           
/////////////////////////////////////////////////////////////////////////////
void IROMCODE_JPEGIDCT_int
(
    int         *coeffBlock, 
    OP_UINT8    *imageBlock
)
{
    int         tmp0;
    int         tmp1; 
    int         tmp2; 
    int         tmp3; 
    int         tmp4; 
    int         tmp5; 
    int         tmp6; 
    int         tmp7;
    int         tmp10; 
    int         tmp11; 
    int         tmp12;
    int         tmp13;
    int         z5;
    int         z10;
    int         z11; 
    int         z12; 
    int         z13;
    int         const1 = 4112;
    
    int         *inptr;
    OP_UINT8    *imagePtr;
    int         ctr;

    // Pass 1: process rows from input
    // row transform, stored in row
    inptr = coeffBlock;
    
    for (ctr = BLOCK_SIZE; ctr > 0; ctr --)
    {
        // Even part
        tmp0 = inptr[0];
        tmp1 = inptr[2];
        tmp2 = inptr[4];
        tmp3 = inptr[6];
        
        tmp10 = tmp0 + tmp2;    // phase 3
        tmp11 = tmp0 - tmp2;
        
        tmp13 = tmp1 + tmp3;    // phases 5-3
        tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13;        // 2*c4
        
        tmp0 = tmp10 + tmp13;    // phase 2
        tmp3 = tmp10 - tmp13;
        tmp1 = tmp11 + tmp12;
        tmp2 = tmp11 - tmp12;
        
        // Odd part
        tmp4 = inptr[1];
        tmp5 = inptr[3];
        tmp6 = inptr[5];
        tmp7 = inptr[7];
        
        z13 = tmp6 + tmp5;        // phase 6
        z10 = tmp6 - tmp5;
        z11 = tmp4 + tmp7;
        z12 = tmp4 - tmp7;
        
        tmp7  = z11 + z13;        // phase 5
        tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);    // 2*c4
        
        z5 = MULTIPLY(z10 + z12, FIX_1_847759065);        // 2*c2
        tmp10 = MULTIPLY(z12, - FIX_1_082392200) + z5;    // 2*(c2-c6)
        tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930);    // -2*(c2+c6)
        
        tmp6 = tmp12 - tmp7;                            // phase 2
        tmp5 = tmp11 - tmp6;
        tmp4 = tmp10 - tmp5;
        
        inptr[0] = tmp0 + tmp7;
        inptr[1] = tmp1 + tmp6;
        inptr[2] = tmp2 + tmp5;
        inptr[3] = tmp3 + tmp4;        // tmp4 has been changed to -tmp4
        inptr[4] = tmp3 - tmp4;
        inptr[5] = tmp2 - tmp5;
        inptr[6] = tmp1 - tmp6;
        inptr[7] = tmp0 - tmp7;

        inptr += BLOCK_SIZE;
    }
    
    // Pass 2: process rows from work array, store into output array.
    inptr = coeffBlock;
    imagePtr = imageBlock;

    for (ctr = BLOCK_SIZE; ctr > 0; ctr--)
    {
        tmp0 = inptr[BLOCK_SIZE*0];
        tmp1 = inptr[BLOCK_SIZE*2];
        tmp2 = inptr[BLOCK_SIZE*4];
        tmp3 = inptr[BLOCK_SIZE*6];
          
        // Even part
        tmp10 = tmp0 + tmp2;    // phase 3
        tmp11 = tmp0 - tmp2;
            
        tmp13 = tmp1 + tmp3;    // phases 5-3
        tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13;        // 2*c4
              
        tmp0 = tmp10 + tmp13;    // phase 2
        tmp3 = tmp10 - tmp13;
        tmp1 = tmp11 + tmp12;
        tmp2 = tmp11 - tmp12;
                  
        // Odd part
                
        tmp4 = inptr[BLOCK_SIZE*1];
        tmp5 = inptr[BLOCK_SIZE*3];
        tmp6 = inptr[BLOCK_SIZE*5];
        tmp7 = inptr[BLOCK_SIZE*7];

        z13 = tmp6 + tmp5;        // phase 6
        z10 = tmp6 - tmp5;
        z11 = tmp4 + tmp7;
        z12 = tmp4 - tmp7;
                    
        tmp7  = z11 + z13;        // phase 5
        tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);    // 2*c4
                      
        z5 = MULTIPLY(z10 + z12, FIX_1_847759065);        // 2*c2
        tmp10 = MULTIPLY(z12, - FIX_1_082392200) + z5;    // 2*(c2-c6)
        tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930);    // -2*(c2+c6)
                        
        tmp6 = tmp12 - tmp7;                            // phase 2
        tmp5 = tmp11 - tmp6;
        tmp4 = tmp10 - tmp5;

        // Final output stage: scale down by a factor of 8 and range-limit

        imagePtr[BLOCK_SIZE*0] = Clip8(((tmp0 + tmp7 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*1] = Clip8(((tmp1 + tmp6 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*2] = Clip8(((tmp2 + tmp5 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*3] = Clip8(((tmp3 + tmp4 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*4] = Clip8(((tmp3 - tmp4 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*5] = Clip8(((tmp2 - tmp5 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*6] = Clip8(((tmp1 - tmp6 + const1) >> COEFF_SCALE_BITS));
        imagePtr[BLOCK_SIZE*7] = Clip8(((tmp0 - tmp7 + const1) >> COEFF_SCALE_BITS));

        inptr++;
        imagePtr++;
    }

    // it is the responsibility of this function to reset the coeffBlock buffer
    for(ctr = 0; ctr < BLOCK_AREA; ctr++) 
    {
        coeffBlock[ctr] = 0;
    }
}

#endif

⌨️ 快捷键说明

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