时光机器

我们都被蒙蔽了

SDL设置转换色

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 一上午时间,。。。。。

阅读更多
个人分类: SDL
上一篇我的童年
下一篇知错就改,善摸大烟
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭