From 737b22a2df0bf5986dbe72cd5d5ee072cf7662c7 Mon Sep 17 00:00:00 2001 From: Justin Mitchell Date: Fri, 12 Jun 2026 16:40:26 -0400 Subject: [PATCH] Fix XTC grayscale mapping for dark/light gray pixels Swap the grayscale values for pixel values 1 and 2 to match the cover's kXthToBmp mapping. Previously 1 mapped to 170 (light gray) and 2 to 85 (dark gray), now corrected to 1->85 (dark gray) and 2->170 (light gray). Use lookup table for clarity. --- lib/Xtc/Xtc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Xtc/Xtc.cpp b/lib/Xtc/Xtc.cpp index 8052c88e..c75bae41 100644 --- a/lib/Xtc/Xtc.cpp +++ b/lib/Xtc/Xtc.cpp @@ -432,9 +432,10 @@ bool Xtc::generateThumbBmp(int height) const { const uint8_t bit1 = (plane1[byteOffset] >> bitInByte) & 1; const uint8_t bit2 = (plane2[byteOffset] >> bitInByte) & 1; const uint8_t pixelValue = (bit1 << 1) | bit2; - // Convert 2-bit (0-3) to grayscale: 0=black, 3=white - // pixelValue: 0=white, 1=light gray, 2=dark gray, 3=black (XTC polarity) - grayValue = (3 - pixelValue) * 85; // 0->255, 1->170, 2->85, 3->0 + // pixelValue: 0=white, 1=dark gray, 2=light gray, 3=black — + // same semantics as the cover's kXthToBmp mapping above + static constexpr uint8_t kXthToGray[4] = {255, 85, 170, 0}; + grayValue = kXthToGray[pixelValue]; } } } else {