libpng 1.6.10 - Merge seekable png patch
Change-Id: I3aa6d8775b884f719375c5aaa458a5c27c120b38
diff --git a/pngrutil.c b/pngrutil.c
index 98e9524..9638bed 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -235,6 +235,33 @@
return (0);
}
+#ifdef PNG_INDEX_SUPPORTED
+int /* PRIVATE */
+png_opt_crc_finish(png_structrp png_ptr, png_uint_32 skip)
+{
+ while (skip > 0)
+ {
+ png_uint_32 len;
+ png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
+
+ len = (sizeof tmpbuf);
+ if (len > skip)
+ len = skip;
+ skip -= len;
+
+ png_crc_read(png_ptr, tmpbuf, len);
+ }
+
+ if (png_crc_error(png_ptr))
+ {
+ png_chunk_warning(png_ptr, "CRC error");
+ return (1);
+ }
+
+ return (0);
+}
+#endif
+
/* Compare the CRC stored in the PNG file with that calculated by libpng from
* the data it has read thus far.
*/
@@ -3957,6 +3984,12 @@
while (png_ptr->idat_size == 0)
{
+#ifdef PNG_INDEX_SUPPORTED
+ if (png_ptr->index) {
+ png_opt_crc_finish(png_ptr, 0);
+ png_ptr->index->stream_idat_position = png_ptr->total_data_read;
+ } else
+#endif
png_crc_finish(png_ptr, 0);
png_ptr->idat_size = png_read_chunk_header(png_ptr);
@@ -4036,6 +4069,9 @@
}
if (ret != Z_OK)
+#ifdef PNG_INDEX_SUPPORTED
+ if (png_ptr->index && png_ptr->row_number != png_ptr->height - 1)
+#endif
{
png_zstream_error(png_ptr, ret);
@@ -4111,6 +4147,27 @@
}
}
+#ifdef PNG_INDEX_SUPPORTED
+void /* PRIVATE */
+png_set_interlaced_pass(png_structp png_ptr, int pass)
+{
+ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
+ /* Start of interlace block */
+ PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+ /* Offset to next interlace block */
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+ /* Start of interlace block in the y direction */
+ PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
+ /* Offset to next interlace block in the y direction */
+ PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
+ png_ptr->pass = pass;
+ png_ptr->iwidth = (png_ptr->width +
+ png_pass_inc[png_ptr->pass] - 1 -
+ png_pass_start[png_ptr->pass]) /
+ png_pass_inc[png_ptr->pass];
+}
+#endif
+
void /* PRIVATE */
png_read_finish_row(png_structrp png_ptr)
{