[devel] Fix png_get_current_row_number in the interlaced case.
diff --git a/png.h b/png.h
index d50c031..5d69f0f 100644
--- a/png.h
+++ b/png.h
@@ -1477,6 +1477,10 @@
* row number is still the row in the final, de-interlaced, image but the row
* only contains the data of the current pass - consult png_row_info for the
* actual width of the row!
+ *
+ * In contrast the row numbers passed to the progressive reader and sequential
+ * reader callbacks are actually the rows in the input data - so the row in the
+ * interlaced pass for an interlaced image.
*/
PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp));
PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp));
diff --git a/pngtrans.c b/pngtrans.c
index 137f555..89661ad 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -703,11 +703,21 @@
}
#endif
+#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
png_uint_32 PNGAPI
png_get_current_row_number(png_const_structp png_ptr)
{
+ /* This API returns the row in output, not the input row: */
if (png_ptr != NULL)
- return png_ptr->row_number;
+ {
+ if (png_ptr->interlaced == PNG_INTERLACE_NONE)
+ return png_ptr->row_number;
+ else if (png_ptr->interlaced == PNG_INTERLACE_ADAM7)
+ return PNG_ROW_FROM_PASS_ROW(png_ptr->row_number, png_ptr->pass);
+
+ /* Else something bad is happening: */
+ }
+
return PNG_UINT_32_MAX; /* help the app not to fail silently */
}
@@ -718,6 +728,7 @@
return png_ptr->pass;
return 8; /* invalid */
}
+#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
PNG_WRITE_USER_TRANSFORM_SUPPORTED */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/pngvalid.c b/pngvalid.c
index 8724420..417d71b 100644
--- a/pngvalid.c
+++ b/pngvalid.c
@@ -3072,7 +3072,13 @@
* us the y in the sub-image:
*/
if (dp->do_interlace && dp->interlace_type == PNG_INTERLACE_ADAM7)
+ {
+ if (pass != png_get_current_pass_number(pp))
+ png_error(pp, "png_get_current_pass_number is broken");
y = PNG_ROW_FROM_PASS_ROW(y, pass);
+ if (y != png_get_current_row_number(pp))
+ png_error(pp, "png_get_current_row_number is broken");
+ }
/* Validate this just in case. */
if (y >= dp->h)
diff --git a/scripts/pnglibconf.h.prebuilt b/scripts/pnglibconf.h.prebuilt
index b1d2169..de1c4d3 100644
--- a/scripts/pnglibconf.h.prebuilt
+++ b/scripts/pnglibconf.h.prebuilt
@@ -148,6 +148,7 @@
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
#define PNG_sCAL_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
+#define PNG_USER_TRANSFORM_INFO_SUPPORTED
#define PNG_sBIT_SUPPORTED
#define PNG_cHRM_SUPPORTED
#define PNG_bKGD_SUPPORTED
@@ -155,7 +156,6 @@
#define PNG_WRITE_iTXt_SUPPORTED
#define PNG_oFFs_SUPPORTED
#define PNG_USER_TRANSFORM_PTR_SUPPORTED
-#define PNG_USER_TRANSFORM_INFO_SUPPORTED
#define PNG_hIST_SUPPORTED
#define PNG_iCCP_SUPPORTED
#define PNG_sRGB_SUPPORTED