SDL_Surface *ChangeColor(SDL_Surface *surface, int flag)
{
//flag : 1.绿色2.红色3.蓝色
SDL_Surface *sur=surface;
SDL_LockSurface(sur);
register Uint32 *s = (Uint32 *)sur->pixels;
int w = sur->w;
int h = sur->h;
long lPitch = surface->pitch>>2;
int i,j;
Uint32 sc;
int alpha = 32;
for(i=0; i<h; ++i)
{
for(j=0; j<w; ++j)
{
sc = (Uint32)s[lPitch*i+j];
Uint32 sr , sg , sb , dr , dg , db;
sr = (sc & 0xFF0000) >> 16 ;
sg = (sc & 0xFF00) >> 8 ;
sb = sc & 0xFF;
if (flag==1) {
dr = 0;
dg = 255;
db = 0;
dg = ((sg * alpha) + (dg *(32-alpha))) >> 5 ;
}
if (flag==2) {
dr = 255;
dg = 0;
db = 0;
dr = ((sr * alpha) + (dr *(32-alpha))) >> 5 ;
}
if (flag==3) {
dr = 0;
dg = 0;
db = 255;
db = ((sb * alpha) + (db *(32-alpha))) >> 5 ;
}
s[lPitch*i+j] = (Uint32) (dr <<16)|(dg<<8)|db ;
}
}
SDL_UnlockSurface(sur);
return sur;
}
change 1 bmp's oranginal color , alpha blent to a color post by flag....1.green,2,red,3,blue
shit ,use my 一上午时间,。。。。。