From 598c2a5e2a2228b26e8059f23aa37b89f748e7d4 Mon Sep 17 00:00:00 2001 From: DRC Date: Sat, 14 Mar 2009 01:21:13 +0000 Subject: [PATCH] Fix broken buffered I/O (to make cjpeg work) git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3678 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/jpeg/jchuff.c | 14 +++++++------- common/jpeg/jdatadst.c | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/jpeg/jchuff.c b/common/jpeg/jchuff.c index 94a66c5a..23b29b8b 100644 --- a/common/jpeg/jchuff.c +++ b/common/jpeg/jchuff.c @@ -311,6 +311,8 @@ dump_buffer (working_state * state) { struct jpeg_destination_mgr * dest = state->cinfo->dest; + dest->free_in_buffer = state->free_in_buffer; + if (! (*dest->empty_output_buffer) (state->cinfo)) return FALSE; /* After a successful buffer dump, must reset buffer pointers */ @@ -380,8 +382,10 @@ flush_bits (working_state * state) unsigned char *buffer; int put_buffer, put_bits; - if ((state)->free_in_buffer < DCTSIZE2 * 2) + 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; @@ -394,9 +398,6 @@ flush_bits (working_state * state) state->free_in_buffer -= (buffer - state->next_output_byte); state->next_output_byte = buffer; - if ((state)->free_in_buffer < DCTSIZE2 * 2) - if (! dump_buffer(state)) return FALSE; - return TRUE; } @@ -415,6 +416,8 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, 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; @@ -474,9 +477,6 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, state->free_in_buffer -= (buffer - state->next_output_byte); state->next_output_byte = buffer; - if ((state)->free_in_buffer < DCTSIZE2 * 2) - if (! dump_buffer(state)) return FALSE; - return TRUE; } diff --git a/common/jpeg/jdatadst.c b/common/jpeg/jdatadst.c index a8f6fb0e..b8748154 100644 --- a/common/jpeg/jdatadst.c +++ b/common/jpeg/jdatadst.c @@ -82,8 +82,9 @@ 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) != - (size_t) OUTPUT_BUF_SIZE) + if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE + - dest->pub.free_in_buffer) != + (size_t) (OUTPUT_BUF_SIZE - dest->pub.free_in_buffer)) ERREXIT(cinfo, JERR_FILE_WRITE); dest->pub.next_output_byte = dest->buffer; -- 2.39.5