📄 pack_rows_sc.sc
字号:
//////////////////////////////////////////////////////////////////////////////////////////////////////// Title: pack_rows_sc.sc (StreamC code for JPEG Bit packing pipeline)// Pipeline for memcpy using DPU loads & stores//// 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 "jpege_tables.h"#include "write_bits.h"void write_bytes_sc (BIT_BUFFER *p_bit_buffer, unsigned int value, int num_bytes){ int i, shift; unsigned char *p_buffer; SPI_ASSERT (p_bit_buffer != NULL); SPI_ASSERT (p_bit_buffer->bit_pos == 0); SPI_ASSERT (p_bit_buffer->cur_byte == 0); SPI_ASSERT (num_bytes <= 4); // Pointer to the uncached memory location since this function is interleaved with DPU writes to the same buffer p_buffer =(unsigned char *)spi_ptr_to_uncached(p_bit_buffer->p_buffer); shift = (num_bytes - 1) * 8; for (i = 0; i < num_bytes; i++) { *(p_buffer + p_bit_buffer->byte_pos) = (unsigned char) (value >> shift) & 0xff; p_bit_buffer->byte_pos++; shift -= 8; } p_bit_buffer->bit_pos = 0; p_bit_buffer->cur_byte = 0; }void word_align_byte_pos_sc(BIT_BUFFER *p_bit_buffer){ int i, stuff_bytes; SPI_ASSERT (p_bit_buffer != NULL); SPI_ASSERT (p_bit_buffer->bit_pos == 0); SPI_ASSERT (p_bit_buffer->cur_byte == 0); stuff_bytes = (4 - (p_bit_buffer->byte_pos & 0x3)) & 0x3; for (i = 0; i < stuff_bytes; i++) { write_bytes_sc (p_bit_buffer, 0xFF, 1); }}void write_single_component_scan_header_sc (JPEGE_CONTEXT *p_jenc, int component_index){ BIT_BUFFER *p_bit_buffer; JPEGE_COMPONENT_INFO *p_comp; p_bit_buffer = &p_jenc->output_buffer; p_comp = &p_jenc->comp_info[component_index]; //TODO // align the position of the byte to be written in the bitstream to word boundary by stuffing "FF"'s word_align_byte_pos_sc(p_bit_buffer); // IMPORTANT NOTE : // We know that we right 16 bytes i.e. 4 words in the header below // So the data following this is going to start at word boundary // In case this header is changed, the place where "word_align_byte_pos" is called // needs to be changed // Adding marker segment which specifies "restart interval definition " per scan write_bytes_sc (p_bit_buffer, 0xFFDD, 2); // DRI marker write_bytes_sc (p_bit_buffer, 0x0004, 2); // Lr marker write_bytes_sc (p_bit_buffer, (p_comp->scaled_width / BLOCK_WIDTH), 2); // Ri marker : MCU length / reset interval = one row of image write_bytes_sc (p_bit_buffer, 0xFFDA, 2); // SOS marker write_bytes_sc (p_bit_buffer, 1 * 2 + 2 + 1 + 3, 2); // length // number of components in scan = 1 write_bytes_sc (p_bit_buffer, 1, 1); write_bytes_sc (p_bit_buffer, p_comp->component_id, 1); write_bytes_sc (p_bit_buffer, (p_comp->dc_huff_tbl_num << 4) + p_comp->ac_huff_tbl_num, 1); // Write Ss, Se, Ah, Al for baseline write_bytes_sc (p_bit_buffer, 0, 1); // Ss write_bytes_sc (p_bit_buffer, 63, 1); // Se write_bytes_sc (p_bit_buffer, 0, 1); // (Ah << 4) + Al}void pack_bits_sc (JPEGE_CONTEXT *p_jenc)//// Description: // DPU implementation of mem copy using load & store// Each bit buffer which contains bitstream generated for one row of blocks is loaded// into the DPU & stored back in the output bitstream//// Returns: Nothing.//////////////////////////////////////////////////////////////////{ int i, k, count; BIT_BUFFER *p_dest_buffer, *p_bit_buffer_cur; JPEGE_COMPONENT_INFO *p_cur_comp; stream uint32x1 bitstream (MAX_COEFFS_PER_ROW_W); int stream_size; p_dest_buffer = &p_jenc->output_buffer;#if defined(DEBUG1) spi_printf("\n Before pack_bits. \n");#endif for (k = 0; k < p_jenc->num_components; k++) { write_single_component_scan_header_sc (p_jenc, k); p_cur_comp = &p_jenc->comp_info[k]; count = 0; for (i = 0; i < p_cur_comp->height_in_blocks; i++) { // the byte position has been already adjusted to be word aligned // so perform the mem copy using spi_load & spi_store // memcpy((p_output_buffer->p_buffer + p_output_buffer->byte_pos), p_bit_buffer->p_buffer, p_bit_buffer->byte_pos ); p_bit_buffer_cur = &p_cur_comp->p_bit_buffers[count]; // Round off the stream size to be a multiple of SPI_LANES stream_size = (((p_bit_buffer_cur->byte_pos + 3) >> 2) + SPI_LANES - 1) & (~(SPI_LANES - 1)); spi_load ( bitstream, // input stream p_bit_buffer_cur->p_buffer, // input buffer 0, // offset stream_size, // count 1, // group 1, // stride 1 // transpose ); spi_store ( bitstream, // output stream p_dest_buffer->p_buffer, // output buffer (p_dest_buffer->byte_pos >> 2), // offset stream_size, // count 1, // group 1, // stride 1 // transpose ); count = count+1; p_dest_buffer->byte_pos += p_bit_buffer_cur->byte_pos; } spi_barrier(); #if defined(DEBUG1) spi_printf("\n After one component : %d \n", k);#endif } spi_release_all_streams();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -