1-bit noise dithering for fast home screen rendering Uses hash-based noise for consistent dithering that works well at small sizes
| 95 | // 1-bit noise dithering for fast home screen rendering |
| 96 | // Uses hash-based noise for consistent dithering that works well at small sizes |
| 97 | uint8_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 | |
| 111 | void createBmpHeader(BmpHeader* bmpHeader, int width, int height, BmpRowOrder rowOrder) { |
| 112 | if (!bmpHeader) return; |
no test coverage detected