From 4326bb9d7ff9d868f20fb32def39c27a8ccfc496 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 24 May 2019 19:53:54 +0200 Subject: [PATCH] Unify indentation style --- src/calibre/utils/imageops/ordered_dither.cpp | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/calibre/utils/imageops/ordered_dither.cpp b/src/calibre/utils/imageops/ordered_dither.cpp index a7cbd4e673..2fe3d29828 100644 --- a/src/calibre/utils/imageops/ordered_dither.cpp +++ b/src/calibre/utils/imageops/ordered_dither.cpp @@ -48,35 +48,35 @@ static uint32_t DIV255(uint32_t v) { static uint8_t dither_o8x8(int x, int y, uint8_t v) { - // 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, - 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, - 11, 59, 7, 55, 10, 58, 6, 54, 43, 27, 39, 23, 42, 26, 38, 22 }; + // 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, + 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, + 11, 59, 7, 55, 10, 58, 6, 54, 43, 27, 39, 23, 42, 26, 38, 22 }; - // Constants: - // Quantum = 8; Levels = 16; map Divisor = 65 - // QuantumRange = 0xFF - // QuantumScale = 1.0 / QuantumRange - // - // 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. - // 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, - // and requires a few explicit casts to make GCC happy ;). - uint32_t t = DIV255(v * ((15U << 6) + 1U)); - // level = t / (D-1); - uint32_t l = (t >> 6); - // t -= l * (D-1); - t = (t - (l << 6)); + // Constants: + // Quantum = 8; Levels = 16; map Divisor = 65 + // QuantumRange = 0xFF + // QuantumScale = 1.0 / QuantumRange + // + // 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. + // 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, + // and requires a few explicit casts to make GCC happy ;). + uint32_t t = DIV255(v * ((15U << 6) + 1U)); + // level = t / (D-1); + uint32_t l = (t >> 6); + // t -= l * (D-1); + t = (t - (l << 6)); - // map width & height = 8 - // 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); - // 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 - // that get shifted to the next step (i.e., q = 272 (0xFF + 17)). - return (q > UINT8_MAX ? UINT8_MAX : static_cast(q)); + // map width & height = 8 + // 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); + // 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 + // that get shifted to the next step (i.e., q = 272 (0xFF + 17)). + return (q > UINT8_MAX ? UINT8_MAX : static_cast(q)); } QImage ordered_dither(const QImage &image) { // {{{