shithub: rgbds

Download patch

ref: 82012f698edfe39a0c7d2e2e17f6c7278c0d051a
parent: 57ac07b03ebd6c82e5df843b380feaccca593277
author: ISSOtm <eldredhabert0@gmail.com>
date: Sun Apr 24 13:32:40 EDT 2022

Fix alpha channel checking in RGBGFX test driver

Compare CGB colors only, including ignoring RGB components if alpha says
the color is transparent

--- a/test/gfx/rgbgfx_test.cpp
+++ b/test/gfx/rgbgfx_test.cpp
@@ -359,17 +359,21 @@
 			Rgba px0 = image0.pixel(x, y);
 			Rgba px1 = image1.pixel(x, y);
 
-#define compare(WHAT, NAME)                                       \
-	if (px0.WHAT >> 3 != px1.WHAT >> 3) {                         \
-		error(NAME " component at (%" PRIu32 ", %" PRIu32         \
-		           ") does not match (source = %u, result = %u)", \
-		      x, y, px0.WHAT >> 3, px1.WHAT >> 3);                \
-	}
-			compare(red, "Red");
-			compare(green, "Green");
-			compare(blue, "Blue");
-			compare(alpha, "Alpha");
-#undef compare
+			auto cgbColor = [](Rgba const &rgba) {
+				auto field = [](uint16_t component, uint8_t shift) {
+					return (component & 0x1F) << shift;
+				};
+				return rgba.isTransparent()
+				           ? Rgba::transparent
+				           : field(rgba.red, 0) | field(rgba.green, 5) | field(rgba.blue, 10);
+			};
+
+			if (cgbColor(px0) != cgbColor(px1)) {
+				error("Color mismatch at (%" PRIu32 ", %" PRIu32
+				      "): (%u,%u,%u,%u) became (%u,%u,%u,%u) after round-tripping",
+				      x, y, px0.red, px0.green, px0.blue, px0.alpha, px1.red, px1.green, px1.blue,
+				      px1.alpha);
+			}
 		}
 	}