5 SDL_Surface* connectSurface(SDL_Surface* top,SDL_Surface* bottom){
6 SDL_Surface* ret = SDL_CreateRGBSurface( SDL_SRCALPHA,
10 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
22 SDL_SetAlpha(top,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
23 SDL_SetAlpha(bottom,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
25 SDL_BlitSurface(top,NULL,ret,NULL);
27 SDL_Rect rect2 = {0,top->h};
28 SDL_BlitSurface(bottom,NULL,ret,&rect2);
30 SDL_FreeSurface(bottom);
34 void setAlpha(SDL_Surface* surf,double alpha_t){
38 Uint32 mask,shift,bytesp,pitch,loss;
42 SDL_PixelFormat* format = surf->format;
45 shift = format->Ashift;
47 bytesp = format->BytesPerPixel;
49 pixels = surf->pixels;
50 SDL_LockSurface(surf);//サーフェイスをロック
53 pix = (Uint32*)(&pixels[y*pitch + x*bytesp]);
54 alpha = (Uint8)((((*pix) & mask) >> shift) << loss);
56 (*pix) &= ~((0xff >> loss) << shift);
57 (*pix) |= (alpha >> loss) << shift;
60 SDL_UnlockSurface(surf);//アンロック
68 void overrideAlpha(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect){
69 SDL_LockSurface(src);//サーフェイスをロック
70 SDL_LockSurface(dst);//サーフェイスをロック
79 if(sx >= sw || sy > sh){
82 sw = MIN(sw-sx,srcrect->w);
83 sh = MIN(sh-sy,srcrect->h);
92 if(dx >= dw || dy > dh){
95 dw = MIN(dw-dx,dstrect->w);
96 dh = MIN(dh-dy,dstrect->h);
110 int sbytesp = src->format->BytesPerPixel;
111 int dbytesp = dst->format->BytesPerPixel;
112 int spitch = src->pitch;
113 int dpitch = dst->pitch;
114 int sAmask = src->format->Amask;
115 int dAmask = dst->format->Amask;
116 int sAshift = src->format->Ashift;
117 int dAshift = dst->format->Ashift;
118 int sAloss = src->format->Aloss;
119 int dAloss = dst->format->Aloss;
120 Uint8* spix = (Uint8*)src->pixels;
121 Uint8* dpix = (Uint8*)dst->pixels;
129 spt = (Uint32*)(&spix[(sy+y)*spitch+(sx+x)*sbytesp]);
130 dpt = (Uint32*)(&dpix[(dy+y)*dpitch+(dx+x)*dbytesp]);
131 salpha = ((*spt & sAmask)>>sAshift)<<sAloss;
132 dalpha = ((*dpt & dAmask)>>dAshift)<<dAloss;
135 *dpt |= (salpha>>dAloss)<<dAshift;
139 SDL_UnlockSurface(dst);//アンロック
140 SDL_UnlockSurface(src);//アンロック
143 void inline shadowBlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect){
144 SDL_BlitSurface(src,srcrect,dst,dstrect);
145 overrideAlpha(src,srcrect,dst,dstrect);
148 void setRGB(SDL_Surface* surf,Uint32 color){
152 int bytesp = surf->format->BytesPerPixel;
153 int pitch = surf->pitch;
154 Uint32 Amask = surf->format->Amask;
155 color &= surf->format->Rmask | surf->format->Gmask | surf->format->Bmask;
156 Uint8* pix = (Uint8*)surf->pixels;
158 SDL_LockSurface(surf);//サーフェイスをロック
161 pt = (Uint32*)(&pix[y*pitch + x*bytesp]);
166 SDL_UnlockSurface(surf);//サーフェイスをアンロック
169 void getRGBA(SDL_Surface* surf,int x,int y,char* r,char* g,char* b,char* a){
170 int pix_index = y * surf->pitch + x * surf->format->BytesPerPixel;
171 char* pix = (char*)surf->pixels;
172 SDL_GetRGBA(*(Uint32*)(&pix[pix_index]),surf->format,(Uint8*)r,(Uint8*)g,(Uint8*)b,(Uint8*)a);