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

📄 jpege_context.h

📁 motion Jpeg 在SPI DSP平台优化好的代码
💻 H
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////                      jpege_context.h (Prototypes for JPEG Encoder context functions 'C' File////      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. //    ////////////////////////////////////////////////////////////////////////////////////////////////////#define USE_JPEG_KERNELS#if defined (REF)#undef  USE_JPEG_KERNELS#endif//////////////////////////////////////////////////////////////////////////////////          Constants////////////////////////////////////////////////////////////////////////////////#define MAX_NUM_COMPONENTS			(4)#define MAX_NUM_QUANT_TBLS			(4)#define MAX_NUM_DC_HUFF_TBLS		(2)#define MAX_NUM_AC_HUFF_TBLS		(2)#define DERIVED_DC_TABLE_LENGTH     (12)#define DERIVED_AC_TABLE_LENGTH     (256)#define BLOCK_WIDTH					(8)#define BLOCK_HEIGHT				(8)#define BLOCK_SIZE					(BLOCK_WIDTH * BLOCK_HEIGHT)#define BLOCK_BIT_BUFFER_SIZE       (2 * BLOCK_SIZE)    // block bitstream buffer size in bytes#define BLOCK_BIT_BUFFER_SIZE_W     (BLOCK_BIT_BUFFER_SIZE >> 2) // block bitstream buffer size in word)// Some kernel related constants#define STRIP_SIZE					(45)#define BLKS_PER_KERNEL				(STRIP_SIZE * SPI_LANES)#define INDICES_PER_KERNEL			(BLOCK_HEIGHT * SPI_LANES)#define MAX_IMG_WIDTH				(1920)#define MAX_IMG_WIDTH_IN_BLKS		(MAX_IMG_WIDTH/BLOCK_WIDTH)#define MAX_COEFFS_PER_ROW_W		(MAX_IMG_WIDTH_IN_BLKS * BLOCK_BIT_BUFFER_SIZE_W)#define MAX_NUM_HUFF_SYMBOL			(162) // 162 is for 8-bit precision. 255 if 12-bit.#define DEFAULT_WIDTH				(720)#define DEFAULT_HEIGHT				(480)#define DEFAULT_INPUT_FORMAT		(YUV420_PLANAR)#define DEFAULT_PRECISION           (8)#define DEFAULT_QUANT_SCALE			(1)#define DEFAULT_QUALITY				(75)#define DEFAULT_SCANs               (3)#define DEFAULT_COMPONENTS_IN_SCAN  (1)#define UINT8  unsigned char#define INT16  signed short int#define UINT16 unsigned short int#define UINT32 unsigned long int#define INT32  signed long int#define	false	0#define	true	(!0)// NOTE: this should be replaced by a generic status from a support librarytypedef enum JPEGE_STATUS {    STATUS_SUCCESS = 0,    STATUS_FRAME_INCOMPLETE,    STATUS_FAIL = -1} JPEGE_STATUS;typedef enum IMAGE_FORMAT{    YUV444_PLANAR,    YUV422_PLANAR,    YUV420_PLANAR,    IMAGE_FORMAT_UNKNOWN} IMAGE_FORMAT;typedef struct BIT_BUFFER{	unsigned char *p_buffer;        // beginning of the buffer	unsigned int  buffer_size;      // #of bytes of the buffer    unsigned int  byte_pos;         // byte to be written to in the buffer.    unsigned char cur_byte;         // current non filled byte	unsigned char bit_pos;          // bit position in current byte} BIT_BUFFER;typedef struct DERIVED_DC_HUFF_TBL{    unsigned char  *code_length;      // need to allocate 13 for dc, 257 for ac    unsigned short *code_word;} DERIVED_HUFF_TBL;// Basic info about one component (color channel).typedef struct {    //----------------------------------------------------------------------------    // These values are fixed over the whole image. They must be supplied by parameter setup;    //----------------------------------------------------------------------------    int component_id;               // identifier for this component (0..255)    int component_index;            // its index in SOF    int h_samp_factor;              // horizontal sampling factor (1..4)    int v_samp_factor;              // vertical sampling factor (1..4)    int quant_tbl_num;              // quantization table selector (0..3)    //----------------------------------------------------------------------------    // These values may vary between scans.    //----------------------------------------------------------------------------    // For compression, they must be supplied by parameter setup;    int dc_huff_tbl_num;            // DC entropy table selector (0..3)    int ac_huff_tbl_num;            // AC entropy table selector (0..3)    DERIVED_HUFF_TBL d_dc_huff_tbl;    DERIVED_HUFF_TBL d_ac_huff_tbl;    //----------------------------------------------------------------------------    // Remaining fields should be treated as private by applications.    //----------------------------------------------------------------------------    // Component's size in (DCT (8x8)) blocks.    // These values are computed based on image dimensions and component sample factors    // Any dummy blocks added to complete an MCU are not counted; therefore    // these values do not depend on whether a scan is interleaved or not.    int width_in_blocks;    int height_in_blocks;    int num_blocks;     // = width_in_blocks * height_in_blocks    int padded_num_blocks;  // Num of blocks is padded to be a multiple of SPI_LANES    // The actual dimensions are the component's actual, unpadded number of samples,    // thus actual_width = ceil(image_width * Hi/Hmax) and similarly for height.     int scaled_width;               //actual width in samples    int scaled_height;              //actual height in samples    int actual_width;    int actual_height;    BIT_BUFFER *p_bit_buffers;    unsigned char *p_mem_buffer;    // pointer to actual buffer space allocated        //----------------------------------------------------------------------------    // These values are computed before starting a scan of the component.    //----------------------------------------------------------------------------    //int MCU_width;                    // number of blocks per MCU, horizontally    //int MCU_height;                   // number of blocks per MCU, vertically    //int MCU_blocks;                   // total number of blocks per MCU = MCU_width * MCU_height    //int MCU_sample_width;             // MCU width in samples, MCU_width * DCT_BLOCK_WIDTH    //int last_col_width;               // # of non-dummy blocks across in last MCU    //int last_row_height;              // # of non-dummy blocks down in last MCU} JPEGE_COMPONENT_INFO;typedef struct JPEGE_SCAN_INFO {    int num_comps_in_scan;		                      // number of components encoded in this scan    int component_index[MAX_NUM_COMPONENTS];           // their SOF/comp_info[] indexes} JPEGE_SCAN_INFO;typedef struct {    unsigned char basic_table[BLOCK_SIZE];    // This array gives the coefficient quantizers in natural array order    // (not the zigzag order in which they are stored in a JPEG DQT marker).    // CAUTION: IJG versions prior to v6a kept this array in zigzag order.    unsigned char scaled_table[BLOCK_SIZE];	                  // quantization step for each coefficient    unsigned short aan_divisor[BLOCK_SIZE];    int  table_sent;} JPEGE_QUANT_TBL;// Huffman coding tablestypedef struct JPEGE_HUFF_TBL{    // These two fields directly represent the contents of a JPEG DHT marker    unsigned char bits[17];		                // bits[k] = # of symbols with codes of length k bits. bits[0] is unused    unsigned char huffval[MAX_NUM_HUFF_SYMBOL];	// The symbols, in order of incr code length    int table_sent;} JPEGE_HUFF_TBL;// JFIF related fieldstypedef struct JPEGE_JFIF_INFO{    UINT8 major_version;                       // What to write for the JFIF version number    UINT8 minor_version;        // These three values are not used by the JPEG code, merely copied    // into the JFIF APP0 marker.  density_unit can be 0 for unknown,    // 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect    // ratio is defined by X_density/Y_density even when density_unit=0.    UINT8 density_unit;                        // JFIF code for pixel size units    UINT16 x_density;                          // Horizontal pixel density    UINT16 y_density;                          // Vertical pixel density} JPEGE_JFIF_INFO;typedef struct JPEGE_CONTEXT{    // Destination for compressed data    BIT_BUFFER output_buffer;    unsigned char *p_input_buffer[MAX_NUM_COMPONENTS];	int input_buffer_allocated[MAX_NUM_COMPONENTS];    // Source image     int image_width;                                // input image width    int image_height;                               // input image height    int encode_width;                             // encoding width after image is padded to the right    int encode_height;                            // encoding height after image is padded to the bottom    IMAGE_FORMAT input_format;                      // input image_format    int max_h_sample_factor;    int max_v_sample_factor;    // Compression parameters --- these fields must be set before calling    // jpeg_start_compress().  We recommend calling jpeg_set_defaults() to    // initialize everything to reasonable defaults, then changing anything    // the application specifically wants to change.  That way you won't get    // burnt when new parameters are added.  Also note that there are several    // helper routines to simplify changing parameters.    int data_precision;                             // bits of precision in image data. Default is 8 and only 8 is supported    int num_components;                             // # of color components in JPEG image. Defaulte 3    JPEGE_COMPONENT_INFO comp_info[MAX_NUM_COMPONENTS];  // comp_info[i] describes component that appears i'th in SOF    int quant_scale_factor;                              // scale factor for quant    JPEGE_QUANT_TBL quant_tbl[MAX_NUM_QUANT_TBLS];       // ptrs to coefficient quantization tables, or NULL if not defined    // ptrs to Huffman coding tables, or NULL if not defined    JPEGE_HUFF_TBL dc_huff_tbl[MAX_NUM_DC_HUFF_TBLS];    JPEGE_HUFF_TBL ac_huff_tbl[MAX_NUM_AC_HUFF_TBLS];    int num_scans;                                  // # of entries in scan_info array    JPEGE_SCAN_INFO *p_scan_info;                   // script for multi-scan file, or NULL    // The default value of scan_info is NULL, which causes a single-scan    // sequential JPEG file to be emitted.  To create a multi-scan file,    // set num_scans and scan_info to point to an array of scan definitions.    // The restart interval can be specified in absolute MCUs by setting    // restart_interval, or in MCU rows by setting restart_in_rows    // (in which case the correct restart_interval will be figured    // for each scan).    unsigned int restart_interval;                  //  MCUs per restart, or 0 for no restart    int restart_in_rows;                            // if > 0, MCU rows per restart interval        // These fields are valid during any one scan.    // They describe the components and MCUs actually appearing in the scan.    int comps_in_scan;                                // # of JPEG components in this scan    int MCUs_x;                                       // total number of MCUs horizontally    int MCUs_y;                                       // total number of MCUs vertically    // JFIF     JPEGE_JFIF_INFO jfif_info;    } JPEGE_CONTEXT;#define AAN_QCONST_BITS 14#define AAN_TCONST_BITS 15#define DIV_CONST_BITS 15#define DIV_CONST_HALF ((1 << DIV_CONST_BITS)/2)void jpeg_main();void fdct_and_quantize_aan_ref (char *p_in_data, short *p_out_data, unsigned short *p_qtable);void compute_divisor_aan (UINT8 *p_quant_table, unsigned short *p_divisors);void jpege_add_quant_table(    JPEGE_CONTEXT *p_jenc,    int table_index,    unsigned char *p_basic_table);void jpege_add_huff_table (    JPEGE_CONTEXT *p_jenc,    int table_type,    int table_index,    unsigned char *p_code_length,    unsigned char *p_values);void jpege_encode (JPEGE_CONTEXT *p_jenc);void jpege_put_all_tables(JPEGE_CONTEXT *p_jenc);void jpege_free_component_input_buffers (JPEGE_CONTEXT *p_jenc);void jpege_free_component_tables (JPEGE_CONTEXT *p_jenc);void jpege_free_component_bit_buffers(JPEGE_CONTEXT *p_jenc);void jpege_set_component_formats(JPEGE_CONTEXT *p_jenc, IMAGE_FORMAT in_format);JPEGE_STATUS jpege_set_component_sizes(JPEGE_CONTEXT *p_jenc);JPEGE_STATUS jpege_set_input_image (    JPEGE_CONTEXT *p_jenc,    unsigned char *p_buf[MAX_NUM_COMPONENTS]);void jpege_set_output_buffer (    JPEGE_CONTEXT *p_jenc,    unsigned char *p_buffer,    int buffer_size);JPEGE_STATUS jpege_set_component(    JPEGE_CONTEXT *p_jenc,     int component_index,     int component_id,    int xscale,    int yscale,    int qtable_index,    int dc_huffman_table_index,    int ac_huffman_table_index);void jpege_set_quality (    JPEGE_CONTEXT *p_jenc,    int quality);void jpege_set_qp (    JPEGE_CONTEXT *p_jenc,    int qp);JPEGE_STATUS jpege_set_default(    JPEGE_CONTEXT *p_jenc);

⌨️ 快捷键说明

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