Skip to content

Commit

Permalink
Fixed Windows cursor color conversion to be endian safe
Browse files Browse the repository at this point in the history
  • Loading branch information
eXpl0it3r committed Oct 1, 2018
1 parent 8554d21 commit 3aa156c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/SFML/Window/Win32/CursorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot
bitmapHeader.bV5BlueMask = 0x000000ff;
bitmapHeader.bV5AlphaMask = 0xff000000;

Uint8* bitmapData = NULL;
Uint32* bitmapData = NULL;

HDC screenDC = GetDC(NULL);
HBITMAP color = CreateDIBSection(
Expand All @@ -90,13 +90,10 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot

// Fill our bitmap with the cursor color data
// We'll have to swap the red and blue channels here
Uint8* bitmapOffset = bitmapData;
for (std::size_t remaining = size.x * size.y; remaining; --remaining, pixels += 4)
Uint32* bitmapOffset = bitmapData;
for (std::size_t remaining = size.x * size.y; remaining > 0; --remaining, pixels += 4)
{
*bitmapOffset++ = pixels[2]; // Blue
*bitmapOffset++ = pixels[1]; // Green
*bitmapOffset++ = pixels[0]; // Red
*bitmapOffset++ = pixels[3]; // Alpha
*bitmapOffset++ = (pixels[3] << 24) | (pixels[0] << 16) | (pixels[1] << 8) | pixels[2];
}

// Create a dummy mask bitmap (it won't be used)
Expand Down

0 comments on commit 3aa156c

Please sign in to comment.