Jump to content
  • Advertisement
Sign in to follow this  
bschneid

[SDL] change the color of sprites?

This topic is 4342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Using SDL and C++, is it possible to alter the color of a loaded/displayed .bmp file? If so, is it efficient?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!