From: DRC Date: Mon, 16 Mar 2009 23:58:30 +0000 (+0000) Subject: iEliminate backward incompatibility which required empty_output_buffer() to handle... X-Git-Tag: v0.0.90~109 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b81e1aef3f8e811b6e4204e50eb832f70b280fab;p=tigervnc.git iEliminate backward incompatibility which required empty_output_buffer() to handle cases in which the buffer wasn't 100% full git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3680 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/common/jpeg/jchuff.c b/common/jpeg/jchuff.c index 23b29b8b..13afab22 100644 --- a/common/jpeg/jchuff.c +++ b/common/jpeg/jchuff.c @@ -42,6 +42,10 @@ int jpeg_first_bit_table_init=0; nbits = jpeg_first_bit_table[t&255]; \ if (t > 255) nbits = jpeg_first_bit_table[t>>8] + 8; +#ifndef min + #define min(a,b) ((a)<(b)?(a):(b)) +#endif + /* Expanded entropy encoder object for Huffman encoding. * * The savable_state subrecord contains fields that change within an MCU, @@ -375,28 +379,55 @@ dump_buffer (working_state * state) /***************************************************************/ +#define BUFSIZE (DCTSIZE2 * 2) + +#define LOAD_BUFFER() { \ + if (state->free_in_buffer < BUFSIZE) { \ + localbuf = 1; \ + buffer = _buffer; \ + } \ + else buffer = state->next_output_byte; \ + } + +#define STORE_BUFFER() { \ + if (localbuf) { \ + bytes = buffer - _buffer; \ + buffer = _buffer; \ + while (bytes > 0) { \ + bytestocopy = min(bytes, state->free_in_buffer); \ + MEMCOPY(state->next_output_byte, buffer, bytestocopy); \ + state->next_output_byte += bytestocopy; \ + buffer += bytestocopy; \ + state->free_in_buffer -= bytestocopy; \ + if (state->free_in_buffer == 0) \ + if (! dump_buffer(state)) return FALSE; \ + bytes -= bytestocopy; \ + } \ + } \ + else { \ + state->free_in_buffer -= (buffer - state->next_output_byte); \ + state->next_output_byte = buffer; \ + } \ + } + +/***************************************************************/ LOCAL(boolean) flush_bits (working_state * state) { - unsigned char *buffer; + unsigned char _buffer[BUFSIZE], *buffer; int put_buffer, put_bits; + int bytes, bytestocopy, localbuf = 0; - if ((state)->free_in_buffer < 1) - if (! dump_buffer(state)) return FALSE; - if ((state)->free_in_buffer < 1) - ERREXIT(state->cinfo, JERR_BUFFER_SIZE); - - buffer = state->next_output_byte; put_buffer = state->cur.put_buffer; put_bits = state->cur.put_bits; + LOAD_BUFFER() DUMP_BITS_(0x7F, 7) state->cur.put_buffer = 0; /* and reset bit-buffer to empty */ state->cur.put_bits = 0; - state->free_in_buffer -= (buffer - state->next_output_byte); - state->next_output_byte = buffer; + STORE_BUFFER() return TRUE; } @@ -410,18 +441,14 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, int temp, temp2; int nbits; int r, sflag, size, code; - unsigned char *buffer; + unsigned char _buffer[BUFSIZE], *buffer; int put_buffer, put_bits; int code_0xf0 = actbl->ehufco[0xf0], size_0xf0 = actbl->ehufsi[0xf0]; + int bytes, bytestocopy, localbuf = 0; - if ((state)->free_in_buffer < DCTSIZE2 * 2) - if (! dump_buffer(state)) return FALSE; - if ((state)->free_in_buffer < DCTSIZE2 * 2) - ERREXIT(state->cinfo, JERR_BUFFER_SIZE); - - buffer = state->next_output_byte; put_buffer = state->cur.put_buffer; put_bits = state->cur.put_bits; + LOAD_BUFFER() /* Encode the DC coefficient difference per section F.1.2.1 */ @@ -474,8 +501,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, state->cur.put_buffer = put_buffer; state->cur.put_bits = put_bits; - state->free_in_buffer -= (buffer - state->next_output_byte); - state->next_output_byte = buffer; + STORE_BUFFER() return TRUE; } diff --git a/common/jpeg/jdatadst.c b/common/jpeg/jdatadst.c index b8748154..a8f6fb0e 100644 --- a/common/jpeg/jdatadst.c +++ b/common/jpeg/jdatadst.c @@ -82,9 +82,8 @@ empty_output_buffer (j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; - if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE - - dest->pub.free_in_buffer) != - (size_t) (OUTPUT_BUF_SIZE - dest->pub.free_in_buffer)) + if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != + (size_t) OUTPUT_BUF_SIZE) ERREXIT(cinfo, JERR_FILE_WRITE); dest->pub.next_output_byte = dest->buffer;