diff options
author | Tom Hudson <tomhudson@google.com> | 2016-05-04 13:22:56 -0400 |
---|---|---|
committer | Tom Hudson <tomhudson@google.com> | 2016-05-04 13:22:56 -0400 |
commit | 0d47d2d3a728e78676a15b1d818cc668cb7e5a9c (patch) | |
tree | 044a430eeaa2dec4d6de7b624da15fda1b8ed25f /jdatadst-tj.c | |
parent | 9d35298a6223278a66423f828a949d93d94d5911 (diff) |
Update to libjpeg_turbo 1.4.90
(Duplicate of https://codereview.chromium.org/1939823002/ for landing.)
TBR=noel@chromium.org,thakis@chromium.org
BUG=608347, 398235, 591927
Review URL: https://codereview.chromium.org/1953443002 .
Diffstat (limited to 'jdatadst-tj.c')
-rw-r--r-- | jdatadst-tj.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/jdatadst-tj.c b/jdatadst-tj.c index a8bf240..5d4260a 100644 --- a/jdatadst-tj.c +++ b/jdatadst-tj.c @@ -5,8 +5,9 @@ * Copyright (C) 1994-1996, Thomas G. Lane. * Modified 2009-2012 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2011, D. R. Commander. - * For conditions of distribution and use, see the accompanying README file. + * Copyright (C) 2011, 2014 D. R. Commander. + * For conditions of distribution and use, see the accompanying README.ijg + * file. * * This file contains compression data destination routines for the case of * emitting JPEG data to memory or to a file (or any stdio stream). @@ -22,13 +23,13 @@ #include "jpeglib.h" #include "jerror.h" -#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ -extern void * malloc JPP((size_t size)); -extern void free JPP((void *ptr)); +#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ +extern void *malloc (size_t size); +extern void free (void *ptr); #endif -#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ +#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ /* Expanded data destination object for memory output */ @@ -36,15 +37,15 @@ extern void free JPP((void *ptr)); typedef struct { struct jpeg_destination_mgr pub; /* public fields */ - unsigned char ** outbuffer; /* target buffer */ - unsigned long * outsize; - unsigned char * newbuffer; /* newly allocated buffer */ - JOCTET * buffer; /* start of buffer */ + unsigned char **outbuffer; /* target buffer */ + unsigned long *outsize; + unsigned char *newbuffer; /* newly allocated buffer */ + JOCTET *buffer; /* start of buffer */ size_t bufsize; boolean alloc; } my_mem_destination_mgr; -typedef my_mem_destination_mgr * my_mem_dest_ptr; +typedef my_mem_destination_mgr *my_mem_dest_ptr; /* @@ -86,7 +87,7 @@ METHODDEF(boolean) empty_mem_output_buffer (j_compress_ptr cinfo) { size_t nextsize; - JOCTET * nextbuffer; + JOCTET *nextbuffer; my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; if (!dest->alloc) ERREXIT(cinfo, JERR_BUFFER_SIZE); @@ -147,29 +148,33 @@ term_mem_destination (j_compress_ptr cinfo) GLOBAL(void) jpeg_mem_dest_tj (j_compress_ptr cinfo, - unsigned char ** outbuffer, unsigned long * outsize, - boolean alloc) + unsigned char **outbuffer, unsigned long *outsize, + boolean alloc) { + boolean reused = FALSE; my_mem_dest_ptr dest; - if (outbuffer == NULL || outsize == NULL) /* sanity check */ + if (outbuffer == NULL || outsize == NULL) /* sanity check */ ERREXIT(cinfo, JERR_BUFFER_SIZE); /* The destination object is made permanent so that multiple JPEG images * can be written to the same buffer without re-executing jpeg_mem_dest. */ - if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, - SIZEOF(my_mem_destination_mgr)); + sizeof(my_mem_destination_mgr)); dest = (my_mem_dest_ptr) cinfo->dest; dest->newbuffer = NULL; + dest->buffer = 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->buffer == *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; } |