[SDL] change the color of sprites?

Started by
2 comments, last by Sante05 17 years, 10 months ago
Using SDL and C++, is it possible to alter the color of a loaded/displayed .bmp file? If so, is it efficient?
Advertisement
Yes, but it is *highly* inefficient as you must access each and every pixel and change it's color. But if you want to alter one color only you must also check every pixel for that color and then change it if it is that color.
Ok, so I will take that to mean its a bad idea...
Quote:Original post by agi_shi
Yes, but it is *highly* inefficient as you must access each and every pixel and change it's color. But if you want to alter one color only you must also check every pixel for that color and then change it if it is that color.


Unless you're using a palette, though that would severely limit your color range.

... or, now that I think about it, maybe there's a method to replace one single color for another in a fast way:

Say you want to replace all the pixels in a surface that have colorA with colorB.

Create a temp surface, same size as original, same pixel format. Fill it with colorB.

Set colorA as the source color key in your original surface.

Blit from the original surface into the temp one. The result will be the image with the replaced color.

Now you can free the original surface and keep the new one, or blit back the result on the original.
-----DevZing Blog (in Spanish)

This topic is closed to new replies.

Advertisement