From a2fde6511384372e2fda335a343bd7a032bddee2 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Fri, 21 Aug 2020 19:43:45 +0100 Subject: [PATCH] Simplified and clarified code for monochrome bit/byte computations --- src/SFML/Window/Unix/CursorImpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index 0fc1e20e9..5678c449c 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -104,18 +104,18 @@ bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Ve // The bit data is stored packed into bytes. If the number of pixels on each row of the image // does not fit exactly into (width/8) bytes, one extra byte is allocated at the end of each // row to store the extra pixels. - std::size_t bytes = (size.x + 7) / 8 * size.y; - std::vector mask(bytes, 0); // Defines which pixel is transparent. - std::vector data(bytes, 1); // Defines which pixel is white/black. + std::size_t packedWidth = (size.x + 7) / 8; + std::size_t bytes = packedWidth * size.y; + std::vector mask(bytes, 0); // Defines which pixel is opaque (1) or transparent (0). + std::vector data(bytes, 1); // Defines which pixel is white (1) or black (0). for (std::size_t j = 0; j < size.y; ++j) { for (std::size_t i = 0; i < size.x; ++i) { std::size_t pixelIndex = i + j * size.x; - std::size_t pixelIndexMask = i + j * (size.x + 7); - std::size_t byteIndex = pixelIndexMask / 8; - std::size_t bitIndex = pixelIndexMask % 8; + std::size_t byteIndex = i / 8 + j * packedWidth; + std::size_t bitIndex = i % 8; // Turn on pixel that are not transparent Uint8 opacity = pixels[pixelIndex * 4 + 3] > 0 ? 1 : 0;