From 1ca18c457508a3294f3eb35626348adfc662fa9d Mon Sep 17 00:00:00 2001 From: jpirnay Date: Thu, 7 May 2026 20:25:57 +0200 Subject: [PATCH] Revert to same quantization thresholds as in upstream --- lib/GfxRenderer/BitmapHelpers.cpp | 5 +---- lib/GfxRenderer/BitmapHelpers.h | 32 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/GfxRenderer/BitmapHelpers.cpp b/lib/GfxRenderer/BitmapHelpers.cpp index 4bc3b039..dd11675d 100644 --- a/lib/GfxRenderer/BitmapHelpers.cpp +++ b/lib/GfxRenderer/BitmapHelpers.cpp @@ -52,11 +52,8 @@ int adjustPixel(int gray) { return gray; } -// Simple quantization without dithering — evenly-spaced midpoint thresholds for factory LUT +// Simple quantization without dithering — thresholds tuned to X4 display brightness uint8_t quantizeSimple(int gray) { - // Midpoint thresholds for 4 levels would be: 0-63=0, 64-127=1, 128-191=2, 192-255=3 - // Crosspoint thresholds for 4 levels: 0-44=0, 45-69=1, 70-139=2, 140-255=3 - // (slightly brighter to compensate for quantization) if (gray < 45) { return 0; } else if (gray < 70) { diff --git a/lib/GfxRenderer/BitmapHelpers.h b/lib/GfxRenderer/BitmapHelpers.h index bd76cefd..04abce39 100644 --- a/lib/GfxRenderer/BitmapHelpers.h +++ b/lib/GfxRenderer/BitmapHelpers.h @@ -127,21 +127,21 @@ class AtkinsonDitherer { if (adjusted < 0) adjusted = 0; if (adjusted > 255) adjusted = 255; - // Quantize to 4 levels — evenly-spaced midpoint thresholds for factory LUT + // Quantize to 4 levels — thresholds tuned to X4 display brightness uint8_t quantized; int quantizedValue; - if (adjusted < 43) { + if (adjusted < 30) { quantized = 0; - quantizedValue = 0; - } else if (adjusted < 128) { + quantizedValue = 15; + } else if (adjusted < 50) { quantized = 1; - quantizedValue = 85; - } else if (adjusted < 213) { + quantizedValue = 30; + } else if (adjusted < 140) { quantized = 2; - quantizedValue = 170; + quantizedValue = 80; } else { quantized = 3; - quantizedValue = 255; + quantizedValue = 210; } // Calculate error (only distribute 6/8 = 75%) @@ -215,21 +215,21 @@ class FloydSteinbergDitherer { if (adjusted < 0) adjusted = 0; if (adjusted > 255) adjusted = 255; - // Quantize to 4 levels — evenly-spaced midpoint thresholds for factory LUT + // Quantize to 4 levels — thresholds tuned to X4 display brightness uint8_t quantized; int quantizedValue; - if (adjusted < 43) { + if (adjusted < 30) { quantized = 0; - quantizedValue = 0; - } else if (adjusted < 128) { + quantizedValue = 15; + } else if (adjusted < 50) { quantized = 1; - quantizedValue = 85; - } else if (adjusted < 213) { + quantizedValue = 30; + } else if (adjusted < 140) { quantized = 2; - quantizedValue = 170; + quantizedValue = 80; } else { quantized = 3; - quantizedValue = 255; + quantizedValue = 210; } // Calculate error