From 78e751f022a5aa3a6ffc4fd08a81fc408c5b70d4 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 24 Apr 2022 13:20:31 +0200 Subject: [PATCH] Fix reading interlaced PNGs Either we let libpng handle the transform, or we don't. But make up your mind! --- src/gfx/process.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index c7c90e5a..2478aaea 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -294,8 +294,7 @@ public: 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 @@ public: } } } 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;