diff --git a/src/sdl-instead/SDL_anigif.c b/src/sdl-instead/SDL_anigif.c index 67641f3..f2c14cd 100644 --- a/src/sdl-instead/SDL_anigif.c +++ b/src/sdl-instead/SDL_anigif.c @@ -197,77 +197,61 @@ int AG_ConvertSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ) -int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames, int skip, int *restore, int *lastdisp ) +int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ) { int n = 0; - SDL_Surface* mainSurface; - int i; - int lastDispose = AG_DISPOSE_NA; - int iRestore = 0; - int newDispose; - Uint8 alpha; - if ( !nFrames || !frames || !frames[0].surface) - return n; - if (skip) { - mainSurface = (4096 & SDL_SRCCOLORKEY) ? - SDL_DisplayFormatAlpha(frames[0].surface) : - SDL_DisplayFormat(frames[0].surface); - alpha = (1 == AG_DISPOSE_NONE || - 1 == AG_DISPOSE_NA) ? - SDL_ALPHA_OPAQUE : SDL_ALPHA_TRANSPARENT; - newDispose = (4096 & SDL_SRCCOLORKEY) ? - AG_DISPOSE_RESTORE_BACKGROUND : AG_DISPOSE_NONE; - } else { - mainSurface = (frames[0].surface->flags & SDL_SRCCOLORKEY) ? - SDL_DisplayFormatAlpha(frames[0].surface) : - SDL_DisplayFormat(frames[0].surface); - alpha = (frames[0].disposal == AG_DISPOSE_NONE || - frames[0].disposal == AG_DISPOSE_NA) ? - SDL_ALPHA_OPAQUE : SDL_ALPHA_TRANSPARENT; - newDispose = (frames[0].surface->flags & SDL_SRCCOLORKEY) ? - AG_DISPOSE_RESTORE_BACKGROUND : AG_DISPOSE_NONE; - } - if (!mainSurface) - return n; - if (skip) { - if (lastdisp) - lastDispose = *lastdisp; - if (restore) - iRestore = *restore; - } - SDL_FillRect( mainSurface, NULL, SDL_MapRGBA(mainSurface->format,0,0,0,alpha) ); - for ( i = skip; i < nFrames + skip; i++ ) { - SDL_Rect r; - SDL_Surface* surface; - if (!frames[i].surface) - continue; - surface = SDL_ConvertSurface( mainSurface, mainSurface->format, mainSurface->flags ); - if (!surface) - continue; - if ( lastDispose == AG_DISPOSE_NONE ) - SDL_BlitSurface( frames[i-1].surface, NULL, surface, NULL ); - else if ( lastDispose == AG_DISPOSE_RESTORE_PREVIOUS ) - SDL_BlitSurface( frames[iRestore].surface, NULL, surface, NULL ); - - if ( frames[i].disposal != AG_DISPOSE_RESTORE_PREVIOUS ) - iRestore = i; + if ( nFrames > 0 && frames && frames[0].surface ) + { + SDL_Surface* mainSurface = (frames[0].surface->flags & SDL_SRCCOLORKEY) ? SDL_DisplayFormatAlpha(frames[0].surface) : SDL_DisplayFormat(frames[0].surface); + const int newDispose = (frames[0].surface->flags & SDL_SRCCOLORKEY) ? AG_DISPOSE_RESTORE_BACKGROUND : AG_DISPOSE_NONE; - r.x = (Sint16)frames[i].x; - r.y = (Sint16)frames[i].y; - SDL_BlitSurface( frames[i].surface, NULL, surface, &r ); - SDL_FreeSurface( frames[i].surface ); - frames[i].surface = surface; - frames[i].x = frames[i].y = 0; - lastDispose = frames[i].disposal; - frames[i].disposal = newDispose; - n++; + if ( mainSurface ) + { + int i; + int lastDispose = AG_DISPOSE_NA; + int iRestore = 0; + const Uint8 alpha = (frames[0].disposal == AG_DISPOSE_NONE || + frames[0].disposal == AG_DISPOSE_NA) ? SDL_ALPHA_OPAQUE : SDL_ALPHA_TRANSPARENT; + + SDL_FillRect( mainSurface, NULL, SDL_MapRGBA(mainSurface->format,0,0,0,alpha) ); + + for ( i = 0; i < nFrames; i++ ) + { + if ( frames[i].surface ) + { + SDL_Surface* surface = SDL_ConvertSurface( mainSurface, mainSurface->format, mainSurface->flags ); + + if ( surface ) + { + SDL_Rect r; + + if ( lastDispose == AG_DISPOSE_NONE ) + SDL_BlitSurface( frames[i-1].surface, NULL, surface, NULL ); + + if ( lastDispose == AG_DISPOSE_RESTORE_PREVIOUS ) + SDL_BlitSurface( frames[iRestore].surface, NULL, surface, NULL ); + if ( frames[i].disposal != AG_DISPOSE_RESTORE_PREVIOUS ) + iRestore = i; + + r.x = (Sint16)frames[i].x; + r.y = (Sint16)frames[i].y; + SDL_BlitSurface( frames[i].surface, NULL, surface, &r ); + + SDL_FreeSurface( frames[i].surface ); + frames[i].surface = surface; + frames[i].x = frames[i].y = 0; + lastDispose = frames[i].disposal; + frames[i].disposal = newDispose; + n++; + } + } + } + + SDL_FreeSurface( mainSurface ); + } } - if (restore) - *restore = iRestore; - if (lastdisp) - *lastdisp = lastDispose; - SDL_FreeSurface( mainSurface ); + return n; } diff --git a/src/sdl-instead/SDL_anigif.h b/src/sdl-instead/SDL_anigif.h index 280e2a9..1fe8c67 100644 --- a/src/sdl-instead/SDL_anigif.h +++ b/src/sdl-instead/SDL_anigif.h @@ -48,7 +48,7 @@ extern DECLSPEC int AG_isGIF( SDL_RWops* src ); extern DECLSPEC int AG_LoadGIF( const char* file, AG_Frame* frames, int maxFrames, int *loop ); extern DECLSPEC void AG_FreeSurfaces( AG_Frame* frames, int nFrames ); extern DECLSPEC int AG_ConvertSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ); -extern DECLSPEC int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames, int skip, int *restore, int *lastdisp ); +extern DECLSPEC int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ); extern DECLSPEC int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int size, int *loop ); diff --git a/src/sdl-instead/graphics.c b/src/sdl-instead/graphics.c index 8f45170..c99f731 100644 --- a/src/sdl-instead/graphics.c +++ b/src/sdl-instead/graphics.c @@ -243,9 +243,6 @@ struct _anigif_t { int active; int delay; int spawn_nr; - int lastdisp; - int restore; - int nr_rendered; struct agspawn *spawn; AG_Frame frames[0]; }; @@ -291,13 +288,6 @@ static anigif_t anigif_find(anigif_t g) } extern int timer_counter; -static void anigif_render(anigif_t g) -{ - if (g->cur_frame >= g->nr_rendered) { - g->nr_rendered += AG_NormalizeSurfacesToDisplayFormat(g->frames, 1, g->cur_frame, &g->restore, &g->lastdisp); - } -} - static void anigif_disposal(anigif_t g) { SDL_Rect dest; @@ -306,8 +296,6 @@ static void anigif_disposal(anigif_t g) img_t *img = NULL; AG_Frame *frame; frame = &g->frames[g->cur_frame]; -// anigif_render(g); - SDL_GetClipRect(screen, &clip); dest.x = 0; //g->x; @@ -359,8 +347,6 @@ static void anigif_frame(anigif_t g) AG_Frame *frame; frame = &g->frames[g->cur_frame]; -// anigif_render(g); - SDL_GetClipRect(screen, &clip); dest.w = frame->surface->w; @@ -637,7 +623,7 @@ static img_t _gfx_load_image(char *filename) return NULL; memset(agif, 0, sizeof(struct _anigif_t) + nr * sizeof(AG_Frame)); AG_LoadGIF(filename, agif->frames, nr, &loop); - agif->nr_rendered = AG_NormalizeSurfacesToDisplayFormat(agif->frames, nr, 0, &agif->restore, &agif->lastdisp); + AG_NormalizeSurfacesToDisplayFormat( agif->frames, nr); agif->loop = loop; agif->nr_frames = nr; anigif_add(agif);