aboutsummaryrefslogtreecommitdiff
path: root/jdatadst-tj.c
diff options
context:
space:
mode:
authordcommander <dcommander@632fc199-4ca6-4c93-a231-07263d6284db>2014-08-21 15:51:47 +0000
committerdcommander <dcommander@632fc199-4ca6-4c93-a231-07263d6284db>2014-08-21 15:51:47 +0000
commit026eb25ae45007959a92c27920be8b62fa1cc768 (patch)
treef961363c3c9a3785de947153104fb2e9ab6be5a2 /jdatadst-tj.c
parentfa1ac3ff77cd2f64d71c74dbb8b13015b0723457 (diff)
If the output buffer in the TurboJPEG destination manager was allocated by the destination manager and is being reused from a previous compression operation, then we need to get the buffer size from the previous operation, since the calling program doesn't know the actual buffer size.
git-svn-id: svn://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1368 632fc199-4ca6-4c93-a231-07263d6284db
Diffstat (limited to 'jdatadst-tj.c')
-rw-r--r--jdatadst-tj.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/jdatadst-tj.c b/jdatadst-tj.c
index bc4a35d..8289d3a 100644
--- a/jdatadst-tj.c
+++ b/jdatadst-tj.c
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2012 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2011, D. R. Commander.
+ * Copyright (C) 2011, 2014 D. R. Commander.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains compression data destination routines for the case of
@@ -150,6 +150,7 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
unsigned char ** outbuffer, unsigned long * outsize,
boolean alloc)
{
+ boolean reused = FALSE;
my_mem_dest_ptr dest;
if (outbuffer == NULL || outsize == NULL) /* sanity check */
@@ -164,12 +165,16 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
sizeof(my_mem_destination_mgr));
dest = (my_mem_dest_ptr) cinfo->dest;
dest->newbuffer = NULL;
+ dest->outbuffer = NULL;
}
dest = (my_mem_dest_ptr) cinfo->dest;
dest->pub.init_destination = init_mem_destination;
dest->pub.empty_output_buffer = empty_mem_output_buffer;
dest->pub.term_destination = term_mem_destination;
+ if (dest->outbuffer && *(dest->outbuffer) == *outbuffer &&
+ *outbuffer != NULL && alloc)
+ reused = TRUE;
dest->outbuffer = outbuffer;
dest->outsize = outsize;
dest->alloc = alloc;
@@ -186,5 +191,7 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
}
dest->pub.next_output_byte = dest->buffer = *outbuffer;
- dest->pub.free_in_buffer = dest->bufsize = *outsize;
+ if (!reused)
+ dest->bufsize = *outsize;
+ dest->pub.free_in_buffer = dest->bufsize;
}