| Summary: | Critical regression in SDL2 2.0.6 pre-release regarding transparency using color key | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Holger Schemel <sdl-bugzilla> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED DUPLICATE | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | icculus, sylvain.becker |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
Minimal test program and test image file to show the problem.
Full patch (including indentation changes) to fix the reported problem. |
||
|
Description
Holger Schemel
2017-09-13 21:13:10 UTC
The link to the mentioned bug report is broken; here's the correct one: https://bugzilla.libsdl.org/show_bug.cgi?id=2979 The following patch (against SDL2 revision 11494:d167d43d74f2 from 2017-09-11) should fix the problem for both 16-bit "565 format" surfaces (as mentioned in bug 2979 linked above) and surfaces of all other depths (by effectively rolling back the changeset 11253:ecc1f6b82d95 for those surface formats, while using the "special color key handling" from that patch only for those surfaces (16-bit depth) that need it). The effect can be seen with the attached example programs from both bug 2979 (16-bit surface with color key) and the attached example programs from this bug report (8-bit image loaded to 32-bit surface). Here's the "short and readable version" of the patch without white-space changes, while the full patch (including changed indentation) follows as an attachment: --- snip --- --- src/video/SDL_surface.c.orig 2017-09-12 22:40:34.696199701 +0200 +++ src/video/SDL_surface.c 2017-09-13 23:18:16.939879983 +0200 @@ -988,6 +988,9 @@ } if (set_colorkey_by_color) { + if (surface->format->BitsPerPixel == 16) { + /* 16-bit "565 format" surfaces need special handling */ + SDL_Surface *tmp; SDL_Surface *tmp2; int converted_colorkey = 0; @@ -1013,6 +1016,15 @@ /* Set the converted colorkey on the new surface */ SDL_SetColorKey(convert, 1, converted_colorkey); + } else { + /* Set the colorkey by color, which needs to be unique */ + Uint8 keyR, keyG, keyB, keyA; + + SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, + &keyG, &keyB, &keyA); + SDL_SetColorKey(convert, 1, + SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); + } /* This is needed when converting for 3D texture upload */ SDL_ConvertColorkeyToAlpha(convert); --- snip --- Created attachment 2935 [details]
Full patch (including indentation changes) to fix the reported problem.
I reopened and submitted a patch in the original bug 2979. The patch was incomplete. It was missing the case where the input surface has colormap / palette. It has to be shared so that the conversion is performed correctly. Great! I can confirm that with your new patch to bug 2979, not only do the example programs from both bug reports work correctly, but also the images from my game "Rocks'n'Diamonds" now have correct transparency again! :-) |