From 1ac0cfd604f68442623998c7d3b34c5a2f57365f Mon Sep 17 00:00:00 2001 From: mrichards42 Date: Sun, 31 Jan 2021 21:08:17 -0500 Subject: [PATCH] [fb] optimize dithering for WHITE and BLACK (#73) These colors should never change due to dithering, and this skips the costly conversion from remarkable_color to float and back. --- src/rmkit/fb/dither.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rmkit/fb/dither.h b/src/rmkit/fb/dither.h index 14a6e0b6..9a221153 100644 --- a/src/rmkit/fb/dither.h +++ b/src/rmkit/fb/dither.h @@ -28,21 +28,25 @@ static const float BLUE_NOISE_MATRIX_16[32][32] = {{ 0.005338541666666667,-0.019 inline remarkable_color BAYER_2(int x, int y, remarkable_color c) { + if (c == WHITE || c == BLACK) return c; return color::quantize<2>(color::to_float(c) + BAYER_MATRIX_2[x%32][y%32]); } inline remarkable_color BAYER_16(int x, int y, remarkable_color c) { + if (c == WHITE || c == BLACK) return c; return color::quantize<16>(color::to_float(c) + BAYER_MATRIX_16[x%32][y%32]); } inline remarkable_color BLUE_NOISE_2(int x, int y, remarkable_color c) { + if (c == WHITE || c == BLACK) return c; return color::quantize<2>(color::to_float(c) + BLUE_NOISE_MATRIX_2[x%32][y%32]); } inline remarkable_color BLUE_NOISE_16(int x, int y, remarkable_color c) { + if (c == WHITE || c == BLACK) return c; return color::quantize<16>(color::to_float(c) + BLUE_NOISE_MATRIX_16[x%32][y%32]); }