Dyeing(coloring) sdl_surfaces

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

In my opinion you are working on a game that’s a monster. Please don’t take this as a flame. Whatever libs you are trying to use, they are not sdl. In general your game seems way too complex for no good reason other than the people that started were learning and didn’t know any better. That’s cool, that’s how we learn. If your team take what they know and start over in an effort to streamline and simplify I’ll bet the project can move forward easily. If this was an sdl and/or c/c++ issue I could craft several basic solutions easily in enough detail to get you started. Lots of people could. As it is now your project is dead.
I’ve been there. You spend so long on something and it’s like if you start over that you loose all of that effort. It seems that way. The truth is that you can make the basic design better and move your skills further faster. One time I spent two months on a pathfinding code and it worked but then I saw someone else had made an example that worked better and was tiny compared to mine. I tested both and found that my code was way slower and way too complex for no good reason. I learned the other guys code and used his code as a basis going forward. It was so hard for me.
If you follow my multiplayer examples maybe your team and I can help each other move forward.
p.s. I like the basic game you have despite the many basic issues it has

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.