aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDRC <information@libjpeg-turbo.org>2015-07-21 17:36:18 -0500
committerMatt Sarett <msarett@google.com>2015-11-23 17:23:48 -0500
commit90c92ed5bf98bda381fcc369f0da46837dbb8894 (patch)
treeb4d1115eba91ff2b81d70db99ee7485b5f36e159
parentfc235cfdabbcd1c915fa3a87a56d73727da2eaeb (diff)
downloadlibjpeg-turbo-90c92ed5bf98bda381fcc369f0da46837dbb8894.tar.gz
Further improvements to partial image decoding
When using context-based upsampling, use a dummy color conversion routine instead of a dummy row buffer. This improves performance (since the actual color conversion routine no longer has to be called), and it also fixes valgrind errors when decompressing to RGB565. Valgrind previously complained, because using the RGB565 color converter with the dummy row buffer was causing a table lookup with undefined indices.
-rw-r--r--jdapistd.c54
-rw-r--r--jdmaster.c4
-rw-r--r--jpegint.h10
3 files changed, 34 insertions, 34 deletions
diff --git a/jdapistd.c b/jdapistd.c
index 578d5cc4..18f9f6ce 100644
--- a/jdapistd.c
+++ b/jdapistd.c
@@ -179,21 +179,37 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
}
-/* Prepare temporary row buffer */
+/* Dummy color convert function used by jpeg_skip_scanlines() */
+LOCAL(void)
+noop_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
+ JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
+{
+}
+
+
+/*
+ * In some cases, it is best to call jpeg_read_scanlines() and discard the
+ * output, rather than skipping the scanlines, because this allows us to
+ * maintain the internal state of the context-based upsampler. In these cases,
+ * we set up and tear down a dummy color converter in order to avoid valgrind
+ * errors and to achieve the best possible performance.
+ */
LOCAL(void)
-dummy_buffer_setup (j_decompress_ptr cinfo)
+read_and_discard_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
{
- int nc;
+ JDIMENSION n;
+ void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
+ JDIMENSION input_row, JSAMPARRAY output_buf,
+ int num_rows);
+
+ color_convert = cinfo->cconvert->color_convert;
+ cinfo->cconvert->color_convert = noop_convert;
- if (!cinfo->master || cinfo->master->dummy_row_buffer)
- return;
+ for (n = 0; n < num_lines; n++)
+ jpeg_read_scanlines(cinfo, NULL, 1);
- nc = (cinfo->out_color_space == JCS_RGB565) ?
- 2 : cinfo->out_color_components;
- cinfo->master->dummy_row_buffer =
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- cinfo->output_width * nc * sizeof(JSAMPLE));
+ cinfo->cconvert->color_convert = color_convert;
}
@@ -205,7 +221,7 @@ dummy_buffer_setup (j_decompress_ptr cinfo)
LOCAL(void)
increment_simple_rowgroup_ctr (j_decompress_ptr cinfo, JDIMENSION rows)
{
- JDIMENSION i, rows_left;
+ JDIMENSION rows_left;
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
/* Increment the counter to the next row group after the skipped rows. */
@@ -217,9 +233,7 @@ increment_simple_rowgroup_ctr (j_decompress_ptr cinfo, JDIMENSION rows)
rows_left = rows % cinfo->max_v_samp_factor;
cinfo->output_scanline += rows - rows_left;
- dummy_buffer_setup(cinfo);
- for (i = 0; i < rows_left; i++)
- jpeg_read_scanlines(cinfo, &(cinfo->master->dummy_row_buffer), 1);
+ read_and_discard_scanlines(cinfo, rows_left);
}
/*
@@ -278,9 +292,7 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
if ((num_lines < lines_left_in_iMCU_row + 1) ||
(lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
- dummy_buffer_setup(cinfo);
- for (i = 0; i < num_lines; i++)
- jpeg_read_scanlines(cinfo, &(cinfo->master->dummy_row_buffer), 1);
+ read_and_discard_scanlines(cinfo, num_lines);
return num_lines;
}
@@ -344,9 +356,7 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
/* It is complex to properly move to the middle of a context block, so
* read the remaining lines instead of skipping them.
*/
- dummy_buffer_setup(cinfo);
- for (i = 0; i < lines_to_read; i++)
- jpeg_read_scanlines(cinfo, &(cinfo->master->dummy_row_buffer), 1);
+ read_and_discard_scanlines(cinfo, lines_to_read);
} else {
cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
@@ -383,9 +393,7 @@ jpeg_skip_scanlines (j_decompress_ptr cinfo, JDIMENSION num_lines)
/* It is complex to properly move to the middle of a context block, so
* read the remaining lines instead of skipping them.
*/
- dummy_buffer_setup(cinfo);
- for (i = 0; i < lines_to_read; i++)
- jpeg_read_scanlines(cinfo, &(cinfo->master->dummy_row_buffer), 1);
+ read_and_discard_scanlines(cinfo, lines_to_read);
} else {
increment_simple_rowgroup_ctr(cinfo, lines_to_read);
}
diff --git a/jdmaster.c b/jdmaster.c
index 2ef43fea..604e2916 100644
--- a/jdmaster.c
+++ b/jdmaster.c
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2009-2011, 2015 D. R. Commander.
+ * Copyright (C) 2009-2011, D. R. Commander.
* Copyright (C) 2013, Linaro Limited.
* For conditions of distribution and use, see the accompanying README file.
*
@@ -733,7 +733,5 @@ jinit_master_decompress (j_decompress_ptr cinfo)
master->pub.is_dummy_pass = FALSE;
- master->pub.dummy_row_buffer = NULL;
-
master_selection(cinfo);
}
diff --git a/jpegint.h b/jpegint.h
index df5aa6eb..eaf51833 100644
--- a/jpegint.h
+++ b/jpegint.h
@@ -5,8 +5,8 @@
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2015, D. R. Commander
- * Copyright (C) 2015, Google, Inc.
+ * It was modified by The libjpeg-turbo Project to include only code relevant
+ * to libjpeg-turbo.
* For conditions of distribution and use, see the accompanying README file.
*
* This file provides common declarations for the various JPEG modules.
@@ -150,12 +150,6 @@ struct jpeg_decomp_master {
/* State variables made visible to other modules */
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
-
- /* Buffer large enough to store an output row. This is used when
- * jpeg_skip_scanlines() chooses to "skip" a row by reading it into this
- * dummy buffer.
- */
- JSAMPROW dummy_row_buffer;
};
/* Input control module */