From 9cb67520c7cefabff2e1f138c1bae39bd0564efe Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 21 Aug 2020 09:58:20 +0100 Subject: [PATCH] Fixed black/white threshold computation for Unix monochrome cursors --- src/SFML/Window/Unix/CursorImpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index fe28917a..0fc1e20e 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -123,9 +123,9 @@ bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Ve // Choose between black/background & white/foreground color for each pixel, // based on the pixel color intensity: on average, if a channel is "active" - // at 25%, the bit is white. - int intensity = pixels[pixelIndex * 4 + 0] + pixels[pixelIndex * 4 + 1] + pixels[pixelIndex * 4 + 2]; - Uint8 bit = intensity > 64 ? 1 : 0; + // at 50%, the bit is white. + int intensity = (pixels[pixelIndex * 4 + 0] + pixels[pixelIndex * 4 + 1] + pixels[pixelIndex * 4 + 2]) / 3; + Uint8 bit = intensity > 128 ? 1 : 0; data[byteIndex] |= bit << bitIndex; } }