MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / quantize1bit

Function quantize1bit

lib/GfxRenderer/BitmapHelpers.cpp:97–109  ·  view source on GitHub ↗

1-bit noise dithering for fast home screen rendering Uses hash-based noise for consistent dithering that works well at small sizes

Source from the content-addressed store, hash-verified

95// 1-bit noise dithering for fast home screen rendering
96// Uses hash-based noise for consistent dithering that works well at small sizes
97uint8_t quantize1bit(int gray, int x, int y) {
98 gray = adjustPixel(gray);
99
100 // Generate noise threshold using integer hash (no regular pattern to alias)
101 uint32_t hash = static_cast<uint32_t>(x) * 374761393u + static_cast<uint32_t>(y) * 668265263u;
102 hash = (hash ^ (hash >> 13)) * 1274126177u;
103 const int threshold = static_cast<int>(hash >> 24); // 0-255
104
105 // Simple threshold with noise: gray >= (128 + noise offset) -> white
106 // The noise adds variation around the 128 midpoint
107 const int adjustedThreshold = 128 + ((threshold - 128) / 2); // Range: 64-192
108 return (gray >= adjustedThreshold) ? 1 : 0;
109}
110
111void createBmpHeader(BmpHeader* bmpHeader, int width, int height, BmpRowOrder rowOrder) {
112 if (!bmpHeader) return;

Callers 3

writeOutputRowFunction · 0.85
flushScaledRowFunction · 0.85

Calls 1

adjustPixelFunction · 0.85

Tested by

no test coverage detected