或許有人會想問,為什麼這樣做?
32bit的圖片是比較漂亮沒錯。但是也大大拖慢了CPU的處理速度,轉成24bit之後效能會大大提升。
當然也有缺點,就是會變得比較醜…
當然SDL支援的圖片不是只有PNG跟BMP格式。
但在這個Porject裡我只有用到這兩個格式,如有需要用到TGA格式…就Google一下吧.
/**
* Srite :類型-(SDL_Surface *)SDL圖片底層Struct,對像圖片(想轉成BMP的圖)
* color :整張圖片的顏色 0 ~ 0xff , -1為關閉,PS:如果圖片不是單色請設成-1
* fade :0xff,代表不做漸層效果
* **/
SDL_Surface* Sprite_Convey2Lowbilt(SDL_Surface* Sprite, int color ,int fade ,int colorkey)
{
SDL_Surface * temp = SDL_DisplayFormatAlpha( Sprite ); //首先複製一分一樣的圖片
SDL_Color rgb1;
Uint32 rgb3;
Uint8 a, r, g, b;
#pragma omp parallel for
for ( int j = 0;j < temp->h ;++j )
{
for ( int i = 0;i < temp->w;++i )
{
rgb1 = GetRGB( Sprite, i, j );
if ( rgb1.unused != 0 && rgb1.unused > 64) // rgb1.unused 是透明度 0 ~ 0xff 這裡只偵測到超過一半才執行半透明混色
{
a = fade == 0xff ? fade : ( rgb1.unused - rgb1.unused / 10 ) ;
if(color!=-1)
{
rgb3 = ( 0xff << 0x18 ) + color;
}else
{
fuzzy( &rgb1, &a, &r, &g, &b );//取得顏色函式,這個涵式我在另外解說
rgb3 = ( 0xff << 0x18 ) + ( r << 0x10 ) + ( g << 0x8 ) + ( b );
}
}
else
rgb3 = ( 0xff << 0x18 ) + colorkey;//如果透明度超過,則加入colorkey的顏色
putpixel( temp, i, j, rgb3 );//把rgb存到指定的點,這個涵式我會在另外解說
}
}
temp = SDL_DisplayFormat( temp ); //最後再Format一次,即大功告成
return temp;
}
沒有留言:
張貼留言