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

📄 encode_frame_sc.sc

📁 motion Jpeg 在SPI DSP平台优化好的代码
💻 SC
📖 第 1 页 / 共 2 页
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////      Title:          encode_frame_sc.sc  (StreamC code for JPEG ENCODING pipeline)//						Pipeline for (FDCT8x8+Quantization) & Variable Length Coding.////      Notice:         COPYRIGHT (C) STREAM PROCESSORS, INC. 2005-2007//                      THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE SPI//                      END-USER LICENSE AGREEMENT (EULA). THE PROGRAM MAY ONLY//                      BE USED IN A MANNER EXPLICITLY SPECIFIED IN THE EULA,//                      WHICH INCLUDES LIMITATIONS ON COPYING, MODIFYING,//                      REDISTRIBUTION AND WARANTIES. UNAUTHORIZED USE OF THIS//                      PROGRAM IS STRICTLY PROHIBITED. YOU MAY OBTAIN A COPY OF//                      THE EULA FROM WWW.STREAMPROCESSORS.COM. //    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      #includes ////////////////////////////////////////////////////////////////////////////////////////////////////#include "spi_common.h"#include "jpege_context.h"#include "write_bits.h"#include "fdct_aan_kc.h"#include "jpege_vlc_kc.h"//////////////////////////////////////////////////////////////////////////////////      Constants////////////////////////////////////////////////////////////////////////////////#define WORDS_PER_8x8BLK_IN		16		// One word has four 8-bit pixels, hence an 8x8 block would have 8x2 words#define WORDS_PER_8x8BLK_OUT	32		// One word has two 16-bit co-efficients, hence an 8x8 block would have 8x4 words///////////////////////////////////////////////////////////////////void convert_to_bitbuffer ( unsigned int   *p_kernel_output,			// Pointer to the bitstream generated by the kernel unsigned int   kernel_output_bitcount,	    // Size of the bitstrean interms of number of word BIT_BUFFER     *p_bitstream                // Pointer to the bit buffer in the bit_buffer structure ) // // Description: //     Translate kernel output to bit_buffer structure. There is no mem copy. //      //	Returns:		Nothing. // ////////////////////////////////////////////////////////////////{    unsigned int byte_count;    unsigned char bit_pos;    unsigned char *p_out;    p_out = (unsigned char *)p_kernel_output;    byte_count = (kernel_output_bitcount & 0xffff) * 4 + (((kernel_output_bitcount >> 16) + 7) >> 3);    bit_pos = (unsigned char)(kernel_output_bitcount >> 16) & 0x7;    if (bit_pos != 0)    {        p_out = (unsigned char *)p_kernel_output;        byte_count--;        p_bitstream->cur_byte = p_out[byte_count];        p_out[byte_count] = 0;    }    p_bitstream->byte_pos = byte_count;    p_bitstream->bit_pos  = bit_pos;    p_bitstream->p_buffer = (unsigned char *) p_kernel_output;}///////////////////////////////////////////////////////////////////void encode_one_component ( JPEGE_CONTEXT  *p_jenc,		        // JPEG context int            component_index			// specifies the component (Y/U/V) that is being encoded ) // // Description:  //     This function is called for each component in the frame to be encoded. //     The data present in the JPEGE_CONTEXT is interpreted & the whole frame is encoded accordingly. // //	Returns:		Nothing. // ////////////////////////////////////////////////////////////////{    //////////////////////////////////////////////////    //	Variable Declarations    //////////////////////////////////////////////////    unsigned char *p_input;    unsigned char *p_src, *p_src_img_offset;    unsigned short *p_quant_divisor;    int i, j, k, count, iterations_per_frame, iterations_per_row;    int num_blocks;    int padded_num_blocks;    int cur_strip_size, last_strip_size, strip_size;    int init[3], cur_height_loc;    int index, *p_input_index;    unsigned int last_iter_in_row;    unsigned int bitstream_offset[SPI_LANES];    unsigned int *p_bitstream;    unsigned int *kernel_output_bitcount, *prev_blk_bits;    unsigned int dc_huffman_table_k[DERIVED_DC_TABLE_LENGTH];    unsigned int ac_huffman_table_k[DERIVED_AC_TABLE_LENGTH];    JPEGE_COMPONENT_INFO *p_comp;    BIT_BUFFER *p_bit_buffer;    //////////////////////////////////////////////////    //	Stream Declarations    //////////////////////////////////////////////////    // Streams used in FDCT + Quantization kernel    stream uint8x4 block_strm (WORDS_PER_8x8BLK_IN * SPI_LANES * STRIP_SIZE);       // Stream storing input in 8x8 block row flattened format (8x2 words per block)    stream int16x2 coef_strm (BLKS_PER_KERNEL * WORDS_PER_8x8BLK_OUT );		        // Stream storing quantized coefficients, after fdct+quant(each coefficient is 16 bit, 8x4 words per lane)    stream int32x1 index_strm (INDICES_PER_KERNEL * 2);						        // Stream to store indices generated for 8x8 block load from input image.    stream uint16x2 divisor_strm(SPI_LANES * WORDS_PER_8x8BLK_OUT);			        // Stream to store transposed quantization scale values (divisors).    // Streams used in Variable Length Coding kernel    stream uint32x1 dc_huff_table_strm (SPI_LANES * DERIVED_DC_TABLE_LENGTH);       // Stream to store the derived DC huffman table.    stream uint32x1 ac_huff_table_strm (SPI_LANES * DERIVED_AC_TABLE_LENGTH);       // Stream to store the derived AC huffman table.    stream uint32x1 bitstream_out (BLKS_PER_KERNEL * BLOCK_BIT_BUFFER_SIZE >> 2);   // Stream to store the bitstream output.    stream uint32x1 prev_block_data(3 * SPI_LANES);							        // Stream storing 'prev dc coeff', 'prev incomplete word', 'no. of bits in prev incomplete word'.    stream uint32x1 bitstream_offset_strm (SPI_LANES);						        // Points to the word position in the bitstream where the output from the kernel needs to be stored for each lane    stream uint32x1 next_bitstream_offset_strm (SPI_LANES);					        // Values in "bitstream_offset_strm" + size of the bitstream created by current block    stream uint32x1 run_level (SPI_LANES * BLOCK_SIZE);						        // Storage location for the runs (top 16 bits) & levels (bottom 16 bits) for each block     p_input		 = p_jenc->p_input_buffer[component_index];    p_comp		 = &p_jenc->comp_info[component_index];    p_bit_buffer = p_comp->p_bit_buffers;    p_quant_divisor = p_jenc->quant_tbl[p_comp->quant_tbl_num].aan_divisor;    p_bitstream		= (unsigned int *)p_comp->p_mem_buffer;    num_blocks		= p_comp->num_blocks;    padded_num_blocks = p_comp->padded_num_blocks;    if ((p_input_index	  = (int *) spi_malloc (padded_num_blocks * sizeof (int))) == NULL)    {        spi_printf ("Error: Malloc of p_input_index failed. \n");        SPI_ASSERT(1);    }    iterations_per_frame = (p_comp->height_in_blocks + SPI_LANES - 1) / SPI_LANES;    iterations_per_row   = (p_comp->width_in_blocks + STRIP_SIZE - 1) / STRIP_SIZE;    if ((prev_blk_bits		   = (unsigned int *) spi_malloc (iterations_per_frame * SPI_LANES * sizeof (unsigned int))) == NULL)    {

⌨️ 快捷键说明

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