shithub: rgbds

Download patch

ref: 78e751f022a5aa3a6ffc4fd08a81fc408c5b70d4
parent: d569c6392c98a5f3037814add1f03a0dc149a86e
author: ISSOtm <[email protected]>
date: Sun Apr 24 09:20:31 EDT 2022

Fix reading interlaced PNGs

Either we let libpng handle the transform, or we don't.
But make up your mind!

--- a/src/gfx/process.cpp
+++ b/src/gfx/process.cpp
@@ -294,8 +294,7 @@
 			png_set_packing(png);
 		}
 
-		// Set interlace handling (MUST be done before `png_read_update_info`)
-		int nbPasses = png_set_interlace_handling(png);
+		// Do NOT call `png_set_interlace_handling`. We want to expand the rows ourselves.
 
 		// Update `info` with the transformations
 		png_read_update_info(png, info);
@@ -323,8 +322,10 @@
 				}
 			}
 		} else {
+			assert(interlaceType == PNG_INTERLACE_ADAM7);
+
 			// For interlace to work properly, we must read the image `nbPasses` times
-			for (int pass = 0; pass < nbPasses; ++pass) {
+			for (int pass = 0; pass < PNG_INTERLACE_ADAM7_PASSES; ++pass) {
 				// The interlacing pass must be skipped if its width or height is reported as zero
 				if (PNG_PASS_COLS(width, pass) == 0 || PNG_PASS_ROWS(height, pass) == 0) {
 					continue;