]> source.dussan.org Git - tigervnc.git/commitdiff
Fix broken buffered I/O (to make cjpeg work)
authorDRC <dcommander@users.sourceforge.net>
Sat, 14 Mar 2009 01:21:13 +0000 (01:21 +0000)
committerDRC <dcommander@users.sourceforge.net>
Sat, 14 Mar 2009 01:21:13 +0000 (01:21 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3678 3789f03b-4d11-0410-bbf8-ca57d06f2519

common/jpeg/jchuff.c
common/jpeg/jdatadst.c

index 94a66c5a4c8907b46ca8e7a8a7ac7bd8f7c039ce..23b29b8bf3e40e832e47732af1325f3f324d986e 100644 (file)
@@ -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;
 }
 
index a8f6fb0e025364eccfcb033dcf576560fc7c0fb3..b874815402b598c4be63dcf25fb41c26266b757a 100644 (file)
@@ -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;