summaryrefslogtreecommitdiff
path: root/jdatadst-tj.c
diff options
context:
space:
mode:
authorChris Blume <cblume@chromium.org>2019-03-01 01:09:50 -0800
committerChris Blume <cblume@chromium.org>2019-03-01 01:09:50 -0800
commitcca8c4dec783a048da6933c86028556622d7c355 (patch)
tree8a7ff526cd8cbe3bf1bfaa4ec1c29fe3268ed51b /jdatadst-tj.c
parent61a2bbaa9aec89cb2c882d87ace6aba9aee49bb9 (diff)
Update libjpeg-turbo to v2.0.1
In order to apply some performance updates from ARM, we need to update libjpeg-turbo. These performance updates have yielded a 50% speedup on some devices. This CL updates our copy of libjpeg-turbo to v2.0.1 and re-applies our local patches. This patch also deletes some extra files which were not being used locally. Update our local patch that was applied to fix http://crbug.com/398235 (https://codereview.appspot.com/229430043/). The original patch incorrectly removed "& 0xFF" which limited an array index to within that array's bounds (effectively reverting https://github.com/libjpeg-turbo/libjpeg-turbo/commit/fa1d18385d904d530b4aec83ab7757a33397de6e). Restore the mask, making the array access safe and fixing a graphical glitch which would otherwise be introduced by this change. Bug:922430 Change-Id: I3860fdb424deecf7a17818ed09a640e632e71f8d
Diffstat (limited to 'jdatadst-tj.c')
-rw-r--r--jdatadst-tj.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/jdatadst-tj.c b/jdatadst-tj.c
index 5d4260a..0bd961b 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, 2014 D. R. Commander.
+ * Copyright (C) 2011, 2014, 2016, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -24,8 +24,8 @@
#include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
-extern void *malloc (size_t size);
-extern void free (void *ptr);
+extern void *malloc(size_t size);
+extern void free(void *ptr);
#endif
@@ -54,7 +54,7 @@ typedef my_mem_destination_mgr *my_mem_dest_ptr;
*/
METHODDEF(void)
-init_mem_destination (j_compress_ptr cinfo)
+init_mem_destination(j_compress_ptr cinfo)
{
/* no work necessary here */
}
@@ -84,17 +84,17 @@ init_mem_destination (j_compress_ptr cinfo)
*/
METHODDEF(boolean)
-empty_mem_output_buffer (j_compress_ptr cinfo)
+empty_mem_output_buffer(j_compress_ptr cinfo)
{
size_t nextsize;
JOCTET *nextbuffer;
- my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
+ my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
if (!dest->alloc) ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Try to allocate new buffer with double size */
nextsize = dest->bufsize * 2;
- nextbuffer = (JOCTET *) malloc(nextsize);
+ nextbuffer = (JOCTET *)malloc(nextsize);
if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
@@ -126,11 +126,11 @@ empty_mem_output_buffer (j_compress_ptr cinfo)
*/
METHODDEF(void)
-term_mem_destination (j_compress_ptr cinfo)
+term_mem_destination(j_compress_ptr cinfo)
{
- my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
+ my_mem_dest_ptr dest = (my_mem_dest_ptr)cinfo->dest;
- if(dest->alloc) *dest->outbuffer = dest->buffer;
+ if (dest->alloc) *dest->outbuffer = dest->buffer;
*dest->outsize = (unsigned long)(dest->bufsize - dest->pub.free_in_buffer);
}
@@ -147,9 +147,8 @@ 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)
+jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
+ unsigned long *outsize, boolean alloc)
{
boolean reused = FALSE;
my_mem_dest_ptr dest;
@@ -162,14 +161,19 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
*/
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,
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
sizeof(my_mem_destination_mgr));
- dest = (my_mem_dest_ptr) cinfo->dest;
+ dest = (my_mem_dest_ptr)cinfo->dest;
dest->newbuffer = NULL;
dest->buffer = NULL;
+ } else if (cinfo->dest->init_destination != init_mem_destination) {
+ /* It is unsafe to reuse the existing destination manager unless it was
+ * created by this function.
+ */
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
}
- dest = (my_mem_dest_ptr) cinfo->dest;
+ 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;
@@ -182,12 +186,12 @@ jpeg_mem_dest_tj (j_compress_ptr cinfo,
if (*outbuffer == NULL || *outsize == 0) {
if (alloc) {
/* Allocate initial buffer */
- dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);
+ dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE);
if (dest->newbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
*outsize = OUTPUT_BUF_SIZE;
- }
- else ERREXIT(cinfo, JERR_BUFFER_SIZE);
+ } else
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
}
dest->pub.next_output_byte = dest->buffer = *outbuffer;