Allow fewer tRNS entries than PLTE colors (#1284)

This commit is contained in:
Rangi
2023-12-31 06:47:53 -05:00
committed by GitHub
parent 528a4c0b70
commit b0f2f0ffd6
7 changed files with 17 additions and 15 deletions

View File

@@ -90,6 +90,7 @@ class Png {
int colorType;
int nbColors;
png_colorp embeddedPal = nullptr;
int nbTransparentEntries;
png_bytep transparencyPal = nullptr;
[[noreturn]] static void handleError(png_structp png, char const *msg) {
@@ -186,9 +187,8 @@ public:
pixels.resize(static_cast<size_t>(width) * static_cast<size_t>(height));
if (png_get_PLTE(png, info, &embeddedPal, &nbColors) != 0) {
int nbTransparentEntries;
if (png_get_tRNS(png, info, &transparencyPal, &nbTransparentEntries, nullptr)) {
assert(nbTransparentEntries == nbColors);
assert(nbTransparentEntries <= nbColors);
}
}

View File

View File

@@ -0,0 +1 @@
-Z

BIN
test/gfx/trns_lt_plte.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B