2 #include "surf_util.h"
\r
3 #include "../mydef.h"
\r
5 SDL_Surface* connectSurface(SDL_Surface* top,SDL_Surface* bottom){
\r
6 SDL_Surface* ret = SDL_CreateRGBSurface( SDL_SRCALPHA,
\r
7 MAX(top->w,bottom->w),
\r
10 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
\r
22 SDL_SetAlpha(top,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
\r
23 SDL_SetAlpha(bottom,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
\r
25 SDL_BlitSurface(top,NULL,ret,NULL);
\r
27 SDL_Rect rect2 = {0,top->h};
\r
28 SDL_BlitSurface(bottom,NULL,ret,&rect2);
\r
29 SDL_FreeSurface(top);
\r
30 SDL_FreeSurface(bottom);
\r
34 void setAlpha(SDL_Surface* surf,double alpha_t){
\r
38 Uint32 mask,shift,bytesp,pitch,loss;
\r
42 SDL_PixelFormat* format = surf->format;
\r
43 /*
\95Ï
\90\94\82Ì
\90Ý
\92è*/
\r
44 mask = format->Amask;
\r
45 shift = format->Ashift;
\r
46 loss = format->Aloss;
\r
47 bytesp = format->BytesPerPixel;
\r
48 pitch = surf->pitch;
\r
49 pixels = surf->pixels;
\r
50 SDL_LockSurface(surf);//
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\83\8d\83b
\83N
\r
53 pix = (Uint32*)(&pixels[y*pitch + x*bytesp]);
\r
54 alpha = (Uint8)((((*pix) & mask) >> shift) << loss);
\r
56 (*pix) &= ~((0xff >> loss) << shift);
\r
57 (*pix) |= (alpha >> loss) << shift;
\r
60 SDL_UnlockSurface(surf);//
\83A
\83\93\83\8d\83b
\83N
\r
64 * src
\82Ì
\95s
\93§
\96¾
\93x
\82ð
\8fã
\8f\91\82«
\82µ
\82Ä
\82µ
\82Ü
\82¤
\81B
\r
65 * src
\82Ì
\95û
\82ª
\95s
\93§
\96¾
\82È
\82ç
\81A
\82»
\82ê
\82ð
\8fã
\8f\91\82«
\81B
\r
68 void overrideAlpha(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect){
\r
69 SDL_LockSurface(src);//
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\83\8d\83b
\83N
\r
70 SDL_LockSurface(dst);//
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\83\8d\83b
\83N
\r
71 //
\94Í
\88Í
\82Ì
\8am
\92è
\r
76 if(srcrect != NULL){
\r
79 if(sx >= sw || sy > sh){
\r
82 sw = MIN(sw-sx,srcrect->w);
\r
83 sh = MIN(sh-sy,srcrect->h);
\r
89 if(dstrect != NULL){
\r
92 if(dx >= dw || dy > dh){
\r
95 dw = MIN(dw-dx,dstrect->w);
\r
96 dh = MIN(dh-dy,dstrect->h);
\r
98 //
\8f¬
\82³
\82¢
\82Ù
\82¤
\82É
\82 \82í
\82¹
\82é
\r
109 //
\82â
\82Á
\82Æ
\82±
\82³
\95`
\89æ
\81B
\81B
\r
110 int sbytesp = src->format->BytesPerPixel;
\r
111 int dbytesp = dst->format->BytesPerPixel;
\r
112 int spitch = src->pitch;
\r
113 int dpitch = dst->pitch;
\r
114 int sAmask = src->format->Amask;
\r
115 int dAmask = dst->format->Amask;
\r
116 int sAshift = src->format->Ashift;
\r
117 int dAshift = dst->format->Ashift;
\r
118 int sAloss = src->format->Aloss;
\r
119 int dAloss = dst->format->Aloss;
\r
120 Uint8* spix = (Uint8*)src->pixels;
\r
121 Uint8* dpix = (Uint8*)dst->pixels;
\r
129 spt = (Uint32*)(&spix[(sy+y)*spitch+(sx+x)*sbytesp]);
\r
130 dpt = (Uint32*)(&dpix[(dy+y)*dpitch+(dx+x)*dbytesp]);
\r
131 salpha = ((*spt & sAmask)>>sAshift)<<sAloss;
\r
132 dalpha = ((*dpt & dAmask)>>dAshift)<<dAloss;
\r
133 if(salpha > dalpha){
\r
135 *dpt |= (salpha>>dAloss)<<dAshift;
\r
139 SDL_UnlockSurface(dst);//
\83A
\83\93\83\8d\83b
\83N
\r
140 SDL_UnlockSurface(src);//
\83A
\83\93\83\8d\83b
\83N
\r
143 void inline shadowBlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect){
\r
144 SDL_BlitSurface(src,srcrect,dst,dstrect);
\r
145 overrideAlpha(src,srcrect,dst,dstrect);
\r
148 void setRGB(SDL_Surface* surf,Uint32 color){
\r
152 int bytesp = surf->format->BytesPerPixel;
\r
153 int pitch = surf->pitch;
\r
154 Uint32 Amask = surf->format->Amask;
\r
155 color &= surf->format->Rmask | surf->format->Gmask | surf->format->Bmask;
\r
156 Uint8* pix = (Uint8*)surf->pixels;
\r
158 SDL_LockSurface(surf);//
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\83\8d\83b
\83N
\r
161 pt = (Uint32*)(&pix[y*pitch + x*bytesp]);
\r
166 SDL_UnlockSurface(surf);//
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\83A
\83\93\83\8d\83b
\83N
\r
169 void getRGBA(SDL_Surface* surf,int x,int y,char* r,char* g,char* b,char* a){
\r
170 int pix_index = y * surf->pitch + x * surf->format->BytesPerPixel;
\r
171 char* pix = (char*)surf->pixels;
\r
172 SDL_GetRGBA(*(Uint32*)(&pix[pix_index]),surf->format,(Uint8*)r,(Uint8*)g,(Uint8*)b,(Uint8*)a);
\r