From 6d90dce3869cb111ca6f38534bb8133c5819620d Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Fri, 12 Mar 2010 17:20:50 +0000 Subject: [PATCH] debug msg removed --- src/sdl-instead/SDL_anigif.c | 118 ++++++++++++++++++++--------------- src/sdl-instead/SDL_anigif.h | 2 +- src/sdl-instead/graphics.c | 16 ++++- 3 files changed, 83 insertions(+), 53 deletions(-) diff --git a/src/sdl-instead/SDL_anigif.c b/src/sdl-instead/SDL_anigif.c index f2c14cd..67641f3 100644 --- a/src/sdl-instead/SDL_anigif.c +++ b/src/sdl-instead/SDL_anigif.c @@ -197,61 +197,77 @@ int AG_ConvertSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ) -int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames ) +int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames, int skip, int *restore, int *lastdisp ) { int n = 0; - - 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; - - 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 ); - } + 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; + + 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 (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 1fe8c67..280e2a9 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 ); +extern DECLSPEC int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames, int skip, int *restore, int *lastdisp ); 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 c99f731..8f45170 100644 --- a/src/sdl-instead/graphics.c +++ b/src/sdl-instead/graphics.c @@ -243,6 +243,9 @@ struct _anigif_t { int active; int delay; int spawn_nr; + int lastdisp; + int restore; + int nr_rendered; struct agspawn *spawn; AG_Frame frames[0]; }; @@ -288,6 +291,13 @@ 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; @@ -296,6 +306,8 @@ 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; @@ -347,6 +359,8 @@ 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; @@ -623,7 +637,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); - AG_NormalizeSurfacesToDisplayFormat( agif->frames, nr); + agif->nr_rendered = AG_NormalizeSurfacesToDisplayFormat(agif->frames, nr, 0, &agif->restore, &agif->lastdisp); agif->loop = loop; agif->nr_frames = nr; anigif_add(agif);