| Summary: | Color-key doesn't work when an alpha channel is present | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Trevor Elliott <awesomelyawesome> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | 2.0.1 | ||
| Hardware: | x86_64 | ||
| OS: | macOS 10.12 | ||
| Attachments: |
Ping with color-key transparency, and an alpha channel
testcase image patch test-case v2 |
||
|
Description
Trevor Elliott
2017-05-26 21:30:50 UTC
The attached image doesn't appear to have a colorkey, at least with libpng 1.6.32. Can you verify and attach another image if needed? I think, he meant that setting the colorkey isn't working on macosx, because his image has an alpha channel. I tried, and actually it did not work on macosx: the pink colorkey is visible. but not on linux (pink became transparent). setting the colorkey : int ck = SDL_MapRGBA(surf->format, 0xff, 0x00, 0xff, 0x00); SDL_SetColorKey(surf, SDL_TRUE, ck); (on linux, whatever the alpha value I put, the colorkey is alway set). Created attachment 2941 [details]
testcase
In fact that issue can be reproduced on any platform.
It occurs if the surface (with alpha and colorkey) has the same format of the renderer.
here's a testcase.
Created attachment 2942 [details]
image
BMP image for the test case.
Created attachment 2943 [details]
patch
Here's a patch to force the path to Convert the surface,
so that the internal SDL_ConvertColorkeyToAlpha() is called, without modifying the user surface.
Some note, this patch may add some overhead, since surfaces with colorkey will always be "converted" by SDL_CreateTextureFromSurface, even if they have the same format as the renderer and the color-key is correct. this affects SDL and not SDL_image Created attachment 3578 [details]
test-case v2
Updated the test-case so that it doesn't need an image.
A surface with Alpha and colorkey is created. Then its Texture is rendered on screen.
Whether the surface format is A-RGB-8888 or A-BGR-8888, it's transparent or not.
In one case: surface format is the same format as renderer format. it's uploaded directly (and isn't transparent).
In the other case, surface and renderer formats are differents, so an intermediate conversion is done, which has also the benefit or converting colorkey to alpha (with SDL_ConvertColorKeyToAlpha())
Fixed in https://hg.libsdl.org/SDL/rev/d4d5e1272239 When surface format is the same as renderer format, it still needs an intermediate conversion to transform colorkey to alpha. |