Unify indentation style

This commit is contained in:
NiLuJe 2019-05-24 19:53:54 +02:00
parent c465d7f4e7
commit 4326bb9d7f

View File

@ -48,35 +48,35 @@ static uint32_t DIV255(uint32_t v) {
static uint8_t static uint8_t
dither_o8x8(int x, int y, uint8_t v) dither_o8x8(int x, int y, uint8_t v)
{ {
// c.f., https://github.com/ImageMagick/ImageMagick/blob/ecfeac404e75f304004f0566557848c53030bad6/config/thresholds.xml#L107 // c.f., https://github.com/ImageMagick/ImageMagick/blob/ecfeac404e75f304004f0566557848c53030bad6/config/thresholds.xml#L107
static const uint8_t threshold_map_o8x8[] = { 1, 49, 13, 61, 4, 52, 16, 64, 33, 17, 45, 29, 36, 20, 48, 32, static const uint8_t threshold_map_o8x8[] = { 1, 49, 13, 61, 4, 52, 16, 64, 33, 17, 45, 29, 36, 20, 48, 32,
9, 57, 5, 53, 12, 60, 8, 56, 41, 25, 37, 21, 44, 28, 40, 24, 9, 57, 5, 53, 12, 60, 8, 56, 41, 25, 37, 21, 44, 28, 40, 24,
3, 51, 15, 63, 2, 50, 14, 62, 35, 19, 47, 31, 34, 18, 46, 30, 3, 51, 15, 63, 2, 50, 14, 62, 35, 19, 47, 31, 34, 18, 46, 30,
11, 59, 7, 55, 10, 58, 6, 54, 43, 27, 39, 23, 42, 26, 38, 22 }; 11, 59, 7, 55, 10, 58, 6, 54, 43, 27, 39, 23, 42, 26, 38, 22 };
// Constants: // Constants:
// Quantum = 8; Levels = 16; map Divisor = 65 // Quantum = 8; Levels = 16; map Divisor = 65
// QuantumRange = 0xFF // QuantumRange = 0xFF
// QuantumScale = 1.0 / QuantumRange // QuantumScale = 1.0 / QuantumRange
// //
// threshold = QuantumScale * v * ((L-1) * (D-1) + 1) // threshold = QuantumScale * v * ((L-1) * (D-1) + 1)
// NOTE: The initial computation of t (specifically, what we pass to DIV255) would overflow an uint8_t. // NOTE: The initial computation of t (specifically, what we pass to DIV255) would overflow an uint8_t.
// With a Q8 input value, we're at no risk of ever underflowing, so, keep to unsigned maths. // With a Q8 input value, we're at no risk of ever underflowing, so, keep to unsigned maths.
// Technically, an uint16_t would be wide enough, but it gains us nothing, // Technically, an uint16_t would be wide enough, but it gains us nothing,
// and requires a few explicit casts to make GCC happy ;). // and requires a few explicit casts to make GCC happy ;).
uint32_t t = DIV255(v * ((15U << 6) + 1U)); uint32_t t = DIV255(v * ((15U << 6) + 1U));
// level = t / (D-1); // level = t / (D-1);
uint32_t l = (t >> 6); uint32_t l = (t >> 6);
// t -= l * (D-1); // t -= l * (D-1);
t = (t - (l << 6)); t = (t - (l << 6));
// map width & height = 8 // map width & height = 8
// c = ClampToQuantum((l+(t >= map[(x % mw) + mw * (y % mh)])) * QuantumRange / (L-1)); // c = ClampToQuantum((l+(t >= map[(x % mw) + mw * (y % mh)])) * QuantumRange / (L-1));
uint32_t q = ((l + (t >= threshold_map_o8x8[(x & 7U) + 8U * (y & 7U)])) * 17); uint32_t q = ((l + (t >= threshold_map_o8x8[(x & 7U) + 8U * (y & 7U)])) * 17);
// NOTE: We're doing unsigned maths, so, clamping is basically MIN(q, UINT8_MAX) ;). // NOTE: We're doing unsigned maths, so, clamping is basically MIN(q, UINT8_MAX) ;).
// The only overflow we should ever catch should be for a few black (v = 0xFF) input pixels // The only overflow we should ever catch should be for a few black (v = 0xFF) input pixels
// that get shifted to the next step (i.e., q = 272 (0xFF + 17)). // that get shifted to the next step (i.e., q = 272 (0xFF + 17)).
return (q > UINT8_MAX ? UINT8_MAX : static_cast<uint8_t>(q)); return (q > UINT8_MAX ? UINT8_MAX : static_cast<uint8_t>(q));
} }
QImage ordered_dither(const QImage &image) { // {{{ QImage ordered_dither(const QImage &image) { // {{{