| Summary: | Wrong colors in TGA files from GTA2 | ||
|---|---|---|---|
| Product: | SDL_image | Reporter: | robotanarchy <robotanarchy> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | amit.jain83, p.sangra, philipp.wiesemann |
| Version: | 2.0.0 | ||
| Hardware: | x86_64 | ||
| OS: | All | ||
| Attachments: |
source code to reproduce this, with an example tga file and screenshots
Swapping of bits happened for SDL_LIL_ENDIAN system which is wrong. It should be for SDL_BIG_ENDIAN system. |
||
|
Description
robotanarchy
2015-01-10 00:11:11 UTC
Thank you for reporting this problem and providing an example. It seems that the colors for this image are wrong because the bytes in img_surface->pixels are in the wrong order. There are two bytes for every pixel and if they are swapped it looks correct. A similar problem was fixed in bug 1886. The changeset which introduced this bug [1] also changed the swapping for little endian platforms. It could be the cause. [1] https://hg.libsdl.org/SDL_image/rev/5bf0f0d6a74e Thanks for finding out the exact issue! Do you have any idea when this will be fixed? I can confirm that Philipp Wisemann's theory is right: When I switch the bytes with the following code, the images are displayed correctly.
char* pixels = surface->pixels;
for(int y=0;y < surface->h;y++)
for(int x=0;x < surface->w;x++)
{
int left_byte_addr = y*surface->w*2 + x*2;
char left_old = pixels[ left_byte_addr ];
pixels[left_byte_addr +0] = pixels[left_byte_addr +1];
pixels[left_byte_addr +1] = left_old;
}
I've added this workaround code to my project, because the target platforms are x86 and x86_64 only, but it would still be best if this was fixed upstream. Thanks!
Created attachment 2248 [details] Swapping of bits happened for SDL_LIL_ENDIAN system which is wrong. It should be for SDL_BIG_ENDIAN system. Hi Robotanarchy Proper solution patch has been attached. Hi Philipp Wiesemann That fix given for bug 1886 is not exactly same as this bug. This issue was not fixed with that solution. That bug was coming for selection of incorrect masking color for 24 bits per pixel image format. But here in this case, it is being selected correctly. But it was swapping for little endian system, that should be big endian instead. Hi Sam, Any update on this ? Fixed, thanks! https://hg.libsdl.org/SDL_image/rev/64a10bd1598c |