Fix handling of PNG files with RGB or RGBA color type that have a PLTE chunk

This commit is contained in:
Rangi
2026-09-13 16:09:49 -04:00
parent 82f58b95ac
commit 49b3f566b1
4 changed files with 7 additions and 1 deletions
+7 -1
View File
@@ -33,7 +33,13 @@ void sortIndexed(std::vector<Palette> &palettes, std::vector<Rgba> 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;
});
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B