Bonjour, j'aimerai sauvegarder un sprite 8 bits BMP? pour cela j'ai utilisé 2 méthode mais elles ne marchent pas et je n'arrive pas a trouver la solution.
Voici les 2 méthodes :
1er methode
Voici le resultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 int save_spr(SDL_Surface* spr,init_sdl* J) { int i, j; SDL_Color colors[256]; int bpp = 8; u8 rmask = 0; u8 gmask = 0; u8 bmask = 0; u8 amask = 0; SDL_Surface* CpySpr = SDL_CreateRGBSurface(SDL_HWSURFACE,spr->w,spr->h,bpp,rmask,gmask,bmask,amask); if( !(malloc_error(CpySpr,NULL))) { FILE_ERROR;LINE_ERROR; return -1; } u8* CpyPix=(u8*)CpySpr->pixels; u8* Pix=(u8*)spr->pixels; for(i=0;i<256;i++) { colors[i].r=i; colors[i].g=i; colors[i].b=i; colors[i].unused=0; } SDL_SetPalette(CpySpr, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); for(j=0;j<spr->h;j++) for(i=0;i<spr->w;i++) *(CpyPix+i+CpySpr->pitch*j) = *(Pix+i+spr->pitch*j); SDL_BlitSurface(CpySpr,NULL,J->screen,0); SDL_Flip(J->screen); return 0; }
et :
J'ai essayé en mettant argb, abgr, bgra,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 int save_spr(SDL_Surface* spr,init_sdl* J) { int i, j; SDL_PixelFormat *fmt; SDL_Color *color; u8 index; fmt=spr->format; if(fmt->BitsPerPixel!=8){ fprintf(stderr, "Not an 8-bit surface.\n"); return(-1); } SDL_LockSurface(spr); index=*(u8 *)spr->pixels; color=&fmt->palette->colors[index]; SDL_UnlockSurface(spr); int bpp = 8; u8 rmask = color->r; u8 gmask = color->g; u8 bmask = color->b; u8 amask = 0; SDL_Surface* CpySpr = SDL_CreateRGBSurface(SDL_HWSURFACE,spr->w,spr->h,bpp,rmask,gmask,bmask,amask); if( !(malloc_error(CpySpr,NULL))) { FILE_ERROR;LINE_ERROR; return -1; } u8* CpyPix=(u8*)CpySpr->pixels; u8* Pix=(u8*)spr->pixels; for(j=0;j<spr->h;j++) for(i=0;i<spr->w;i++) *(CpyPix+i+CpySpr->pitch*j) = *(Pix+i+spr->pitch*j); SDL_BlitSurface(CpySpr,NULL,J->screen,0); SDL_Flip(J->screen); return 0; }
voici le resultat :
Merci par avance pour votre aide.
Partager