Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_SetWindowIcon producing messed up icon #2371

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

SDL_SetWindowIcon producing messed up icon #2371

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Labels
invalid This doesn't seem right

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.5
Reported for operating system, platform: Windows 10, x86_64

Comments on the original bug report:

On 2017-01-15 21:34:31 +0000, Daniel D'Agostino wrote:

Created attachment 2678
This is the window icon as rendered.

Quoting from: https://forums.libsdl.org/viewtopic.php?t=12277

"I've come across a weird issue with SDL_SetWindowIcon(). I am creating a surface from pixel data that I already have available, using SDL_CreateRGBSurfaceWithFormatFrom(). I know that the pixel data is correct because I'm rendering it in my game, and I know the surface I'm creating from it for the icon is valid because I tried saving it to a BMP and the image was created perfectly.

"But when I pass the same surface to SDL_SetWindowIcon(), I get a garbled mess."

When loading from a BMP, it works fine.

Repro project is here: https://bitbucket.org/dandago/experimental/src/35ab7d960e5461cfaf9fdee3bf37d9179f8de4cd/Sdl2WindowIcon/Sdl2WindowIcon/main.cpp?at=master&fileviewer=file-view-default

Attached is the icon I'm seeing as a result of this code.

I adapted the code from the sample at: https://wiki.libsdl.org/SDL_SetWindowIcon

The sample itself works - it's using just 4 bits per channel - whereas I'm using a byte per channel.

On 2017-01-15 21:42:59 +0000, Daniel D'Agostino wrote:

Created attachment 2679
Rendered icon after fixing Uint16 -> Uint32

On 2017-01-15 21:44:22 +0000, Daniel D'Agostino wrote:

(In reply to Daniel D'Agostino from comment # 0)

Created attachment 2678 [details]
This is the window icon as rendered.

Quoting from: https://forums.libsdl.org/viewtopic.php?t=12277

"I've come across a weird issue with SDL_SetWindowIcon(). I am creating a
surface from pixel data that I already have available, using
SDL_CreateRGBSurfaceWithFormatFrom(). I know that the pixel data is correct
because I'm rendering it in my game, and I know the surface I'm creating
from it for the icon is valid because I tried saving it to a BMP and the
image was created perfectly.

"But when I pass the same surface to SDL_SetWindowIcon(), I get a garbled
mess."

When loading from a BMP, it works fine.

Repro project is here:
https://bitbucket.org/dandago/experimental/src/
35ab7d960e5461cfaf9fdee3bf37d9179f8de4cd/Sdl2WindowIcon/Sdl2WindowIcon/main.
cpp?at=master&fileviewer=file-view-default

Attached is the icon I'm seeing as a result of this code.

I adapted the code from the sample at:
https://wiki.libsdl.org/SDL_SetWindowIcon

The sample itself works - it's using just 4 bits per channel - whereas I'm
using a byte per channel.

Had a small mistake in the code with Uint16 that should have been Uint32.

See updated repro code here:

https://bitbucket.org/dandago/experimental/src/792b14862ea211d3dda46e0a3bb3bb335ba3a12a/Sdl2WindowIcon/Sdl2WindowIcon/main.cpp?at=master&fileviewer=file-view-default

Also attached updated icon screenshot.

On 2017-01-16 21:55:38 +0000, Sam Lantinga wrote:

You're specifying a pixel format with alpha and passing an entirely transparent image. I've verified that if you specify a format without alpha e.g. SDL_PIXELFORMAT_RGB888 or set the alpha channel to 0xFF that the icon shows up as expected.

I've also checked and the pixels that you're providing are making it untouched to the Win32 API functions. I'm not sure why those API functions are mis-handling the pixel data if there isn't alpha channel data, but it may be legacy handling in the APIs. If you set even one pixel with an alpha value, the icon shows up as expected.

@SDLBugzilla SDLBugzilla added bug invalid This doesn't seem right labels Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant