summaryrefslogtreecommitdiffstats
path: root/common/jpeg
diff options
context:
space:
mode:
authorDRC <dcommander@users.sourceforge.net>2009-03-14 01:21:13 +0000
committerDRC <dcommander@users.sourceforge.net>2009-03-14 01:21:13 +0000
commit598c2a5e2a2228b26e8059f23aa37b89f748e7d4 (patch)
tree8eef2002eb01e0182c89c6941b6d4b5ac06bb0ed /common/jpeg
parentf99c5719e465eb00b7e1bd9c16720ede6fa08b52 (diff)
downloadtigervnc-598c2a5e2a2228b26e8059f23aa37b89f748e7d4.tar.gz
tigervnc-598c2a5e2a2228b26e8059f23aa37b89f748e7d4.zip
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
Diffstat (limited to 'common/jpeg')
-rw-r--r--common/jpeg/jchuff.c14
-rw-r--r--common/jpeg/jdatadst.c5
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;