I found an interesting thing that I'm not able to debug but I'd like to solve because it's crucial for the development of a small tool I need.
Basically all reduces to the fact that I load into an SDL_Surface
a PNG loaded with IMG_Load("filename.png")
. The skeleton of the code is
surface = IMG_Load("filename.png");
Then this tool should copy this surface pixel by pixel to another by applying a color map (which is just an unordered_map<u32,u32>
). This basically works, but many pixel have a slight change in their RGB values so this substitution fails.
For example, while a pixel 255,255,255 is correctly stored as 0xFFFFFFFF in the surface, another pixel, let's say 81,60,48 becomes 82,62,51. I thought about gamma correction but the image itself is not drawn since the color switch is applied before two surfaces, and the latter gets drawn to a texture just afterwards.
Any clues? I'm not interested in finding another solution to my problem since I require to be able to do precise pixel color switching with a fixed map, I'd just like to understand why this is happening (since PNG should just contain exact values, being lossless) and solve it.