| Dyeing(coloring) sdl_surfaces. |
|
pavanetti
|
In my game, I want to customize the character. For this, I want to set the color of the hair, clothes and maybe the eyes. How can I colorize a grayscale surface? Can I do without accessing each pixel? Accessing pixel by pixel I can generate a surface with the color that I pass as parameter. But if there is a technique to do this directly I appreciate it.
http://wiki.themanaworld.org/index.php/Image_dyeing |
|||||||||||
|
|
||||||||||||
| basic observation and solution |
|
gameEater63
|
I think the used technique depends on the colour format and bith depth, as follows:
8 bpp : You have a pallet or colour map at surface->format->pallet, which is an array of SDL_Color structs. Also each pixel has an index to the pallet as its colour. you can change colour of many pixels at once by simply modifying entries of this table. For this you need to be sure all those pixels have a same colour index. Other bit depths : As you may know, Each pixel has RGB values of its colour codded or packed in a 16,24 or 32 bits span. Suppose you want to colour a shirt. This shirt has several images for animation. You should create everal tiny images for each frame of animation, each showing that shirt in a different colour and using a colour key, So you can blit the image with right colour each frame in the right position. |
|||||||||||
|
|
||||||||||||

