From 004749ea75ae2801369ec38dc5ac310910a76c2b Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Tue, 15 Sep 2026 22:03:56 -0400 Subject: [PATCH] Halt processing when any ambiguous-transparency colors exist (#2093) --- src/gfx/process.cpp | 15 ++++++++++++--- test/gfx/ambiguous.err | 3 ++- test/gfx/fully_ambiguous.err | 4 ++++ test/gfx/fully_ambiguous.png | Bin 0 -> 377 bytes 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/gfx/fully_ambiguous.err create mode 100644 test/gfx/fully_ambiguous.png diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index 66b6c010..bbd86b02 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -218,6 +218,13 @@ struct Image { } } } + if (size_t nbAmbiguousColors = ambiguous.size(); nbAmbiguousColors > 0) { + fatal( + "Image contains %zu ambiguous color%s (neither transparent nor opaque)", + nbAmbiguousColors, + nbAmbiguousColors == 1 ? "" : "s" + ); + } } class TilesVisitor { @@ -1056,12 +1063,14 @@ void process() { for (auto tile : image.visitAsTiles()) { AttrmapEntry &attrs = attrmap.emplace_back(); - // Count the unique non-transparent colors for packing + // Count the unique opaque colors for packing std::unordered_set tileColors; for (uint32_t y = 0; y < 8; ++y) { for (uint32_t x = 0; x < 8; ++x) { - if (Rgba color = tile.pixel(x, y); - color.isOpaque() || !options.hasTransparentPixels) { + Rgba color = tile.pixel(x, y); + // Ambiguous colors should not be in `tileColors` + assume(color.isOpaque() != color.isTransparent()); + if (color.isOpaque() || !options.hasTransparentPixels) { tileColors.insert(color.cgbColor()); } } diff --git a/test/gfx/ambiguous.err b/test/gfx/ambiguous.err index d7817a14..3a74e624 100644 --- a/test/gfx/ambiguous.err +++ b/test/gfx/ambiguous.err @@ -1,2 +1,3 @@ error: Color #ff800080 is neither transparent (alpha < 16) nor opaque (alpha >= 240) (first seen at (0, 8)) -Conversion aborted after 1 error +FATAL: Image contains 1 ambiguous color (neither transparent nor opaque) +Conversion aborted after 2 errors diff --git a/test/gfx/fully_ambiguous.err b/test/gfx/fully_ambiguous.err new file mode 100644 index 00000000..52fd9c76 --- /dev/null +++ b/test/gfx/fully_ambiguous.err @@ -0,0 +1,4 @@ +error: Color #ff000080 is neither transparent (alpha < 16) nor opaque (alpha >= 240) (first seen at (0, 0)) +error: Color #0000ff80 is neither transparent (alpha < 16) nor opaque (alpha >= 240) (first seen at (0, 4)) +FATAL: Image contains 2 ambiguous colors (neither transparent nor opaque) +Conversion aborted after 3 errors diff --git a/test/gfx/fully_ambiguous.png b/test/gfx/fully_ambiguous.png new file mode 100644 index 0000000000000000000000000000000000000000..d5bbd515d30d8871dad5755ed476cafa0eedffa5 GIT binary patch literal 377 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1enP_o1|q9iy!t)x7$D3u`~F*C13&(AeP!Bo#s z&(KJi(Y*wyXh&*$Nv;eZ8x(p2rK(fvC`Z7fqF5d?-RXtrCLo|Yu|C~Q?;Xnhs!9wl@%vu@=DL>9P i@C%zU#xlqXgfK8@&f)Br*fDc8NVBJ_pUXO@geCxOC`N1m literal 0 HcmV?d00001