From 2959d43b2bb4fe5f689043996c5ee64fba67799f Mon Sep 17 00:00:00 2001 From: Oliver Schinagl Date: Sun, 5 Jun 2005 16:47:26 +0000 Subject: --- src/c_huffman.c | 74 ++++++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/src/c_huffman.c b/src/c_huffman.c index 98e0f71..60b0709 100644 --- a/src/c_huffman.c +++ b/src/c_huffman.c @@ -38,24 +38,7 @@ typedef struct { } savable_state; #define ASSIGN_STATE(dest,src) ((dest) = (src)) -/* -typedef struct { - //struct jpeg_entropy_encoder pub; // public fields - - savable_state saved; // Bit buffer & DC state at start of MCU - - // These fields are NOT loaded into local working state. - unsigned int restarts_to_go; // MCUs left in this restart interval - int next_restart_num; // next restart number to write (0-7) - // Pointers to derived tables (these workspaces have image lifespan) - c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; - c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; - -} huff_entropy_encoder; - -typedef huff_entropy_encoder * huff_entropy_ptr; -*/ /* Working state while writing an MCU. * This struct contains all the fields that are needed by subroutines. @@ -105,7 +88,7 @@ add_huff_table (JHUFF_TBL *htblptr, const UINT8 *bits, const UINT8 *val) perror("Bad Huffman code table entry"); exit(0); } - //ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + MEMCOPY((htblptr)->huffval, val, nsymbols * SIZEOF(UINT8)); @@ -344,25 +327,6 @@ inline static boolean emit_bits(working_state * state, unsigned int code, int si return TRUE; } -/* - * Initialize for a Huffman-compressed scan. - */ -/* - static void start_pass_huff (j_compress_ptr cinfo) { - huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; - -//entropy->pub.encode_mcu = encode_mcu_huff; -//entropy->pub.finish_pass = finish_pass_huff; - -// Initialize bit buffer to empty -entropy->saved.put_buffer = 0; -entropy->saved.put_bits = 0; - -// Initialize restart stuff -entropy->restarts_to_go = cinfo->restart_interval; -entropy->next_restart_num = 0; -} -*/ static boolean flush_bits (working_state * state) { if (! emit_bits(state, 0x7F, 7)) // fill any partial byte with ones @@ -422,7 +386,7 @@ int encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_de if (! emit_bits(state, (unsigned int) temp2, nbits)) { return FALSE; } - bitCounter += nbits; // TODEBUG + bitCounter += nbits; // TODEBUG } /* Encode the AC coefficients per section F.1.2.2 */ @@ -492,25 +456,24 @@ int encode_one_block(working_state *state, JCOEFPTR block, int last_dc_val, c_de /* * Emit a restart marker & resynchronize predictions. */ -/* - static boolean emit_restart (working_state * state, int restart_num) { - int ci; - if (! flush_bits(state)) - return FALSE; +static boolean emit_restart (working_state * state, int restart_num) { + int ci; - emit_byte(state, 0xFF, return FALSE); - emit_byte(state, JPEG_RST0 + restart_num, return FALSE); + if (! flush_bits(state)) + return FALSE; -// Re-initialize DC predictions to 0 -for (ci = 0; ci < state->cinfo->comps_in_scan; ci++) -state->cur.last_dc_val[ci] = 0; + emit_byte(state, 0xFF, return FALSE); + emit_byte(state, JPEG_RST0 + restart_num, return FALSE); -// The restart counter is not updated until we successfully write the MCU. + // Re-initialize DC predictions to 0 + for (ci = 0; ci < MAX_COMPS_IN_SCAN; ci++) + state->cur.last_dc_val[ci] = 0; -return TRUE; + // The restart counter is not updated until we successfully write the MCU. + return TRUE; } -*/ + /* * Encode and output one MCU's worth of Huffman-compressed coefficients. @@ -596,10 +559,10 @@ ASSIGN_STATE(entropy->saved, state.cur); -//int dataToCode[64]; static int lastDCValue; static working_state savedHuffstate; + unsigned char outputBufferHuffman[500]; void encode_huffBlock64_init(void) @@ -619,7 +582,10 @@ void encode_huffBlock64_start(void) lastDCValue = 0; // Initialise buffer savedHuffstate.next_output_byte = outputBufferHuffman; - savedHuffstate.free_in_buffer = 500; // TODO: + savedHuffstate.free_in_buffer = 500; // TODO: + savedHuffstate.cur.put_buffer = 0; + savedHuffstate.cur.put_bits = 0; + // savedHuffstate.cinfo = NULL; } @@ -642,7 +608,7 @@ void encode_huffBlock64(short * data) savedHuffstate.free_in_buffer = state.free_in_buffer; ASSIGN_STATE(savedHuffstate.cur, state.cur); - + } void encode_huffBlock64_end(void ) -- cgit v0.12