diff --git a/src/gfx/pal_sorting.cpp b/src/gfx/pal_sorting.cpp index 56712fd9..45918340 100644 --- a/src/gfx/pal_sorting.cpp +++ b/src/gfx/pal_sorting.cpp @@ -33,7 +33,13 @@ void sortIndexed(std::vector &palettes, std::vector const &embPal return true; } } - unreachable_(); // LCOV_EXCL_LINE + // A PNG image using PNG_COLOR_TYPE_RGB (2) or PNG_COLOR_TYPE_RGBA (6) can still + // contain a PLTE chunk. From the PNG spec: "If present, it provides a suggested set of + // from 1 to 256 colors to which the truecolor image can be quantized if the viewer + // cannot display truecolor directly." This means that an input image may have pixels + // with colors that are not in the PLTE chunk, so iterating through `embPal` may finish + // without returning. In that case, we compare `lhs` and `rhs` directly. + return lhs < rhs; }); } } diff --git a/test/gfx/rgb_with_plte.out.2bpp b/test/gfx/rgb_with_plte.out.2bpp new file mode 100644 index 00000000..147b4e9a Binary files /dev/null and b/test/gfx/rgb_with_plte.out.2bpp differ diff --git a/test/gfx/rgb_with_plte.out.pal b/test/gfx/rgb_with_plte.out.pal new file mode 100644 index 00000000..98c4fa00 Binary files /dev/null and b/test/gfx/rgb_with_plte.out.pal differ diff --git a/test/gfx/rgb_with_plte.png b/test/gfx/rgb_with_plte.png new file mode 100644 index 00000000..7b218580 Binary files /dev/null and b/test/gfx/rgb_with_plte.png differ