anigif next stage..

This commit is contained in:
p.kosyh 2009-10-02 17:18:09 +00:00
parent 764d0df2db
commit c180844aee
5 changed files with 856 additions and 810 deletions

View file

@ -16,8 +16,8 @@ LUA_LFLAGS=$(shell pkg-config --libs lua5.1)
# for arch linux, fedora (may be others) use this # for arch linux, fedora (may be others) use this
# #
# LUA_CFLAGS=$(shell pkg-config --cflags lua) LUA_CFLAGS=$(shell pkg-config --cflags lua)
# LUA_LFLAGS=$(shell pkg-config --libs lua) LUA_LFLAGS=$(shell pkg-config --libs lua)
# #
SDL_CFLAGS=$(shell sdl-config --cflags) SDL_CFLAGS=$(shell sdl-config --cflags)

View file

@ -80,6 +80,7 @@ typedef struct
{ {
/* global data */ /* global data */
SDL_RWops* src; SDL_RWops* src;
int loop;
gifscreen gs; gifscreen gs;
gif89 g89; gif89 g89;
int zerodatablock; int zerodatablock;
@ -132,7 +133,7 @@ int AG_isGIF( SDL_RWops* src )
return isGIF; return isGIF;
} }
int AG_LoadGIF( const char* file, AG_Frame* frames, int size ) int AG_LoadGIF( const char* file, AG_Frame* frames, int size, int *loop )
{ {
int n = 0; int n = 0;
@ -140,7 +141,7 @@ int AG_LoadGIF( const char* file, AG_Frame* frames, int size )
if ( src ) if ( src )
{ {
n = AG_LoadGIF_RW( src, frames, size ); n = AG_LoadGIF_RW( src, frames, size, loop );
SDL_RWclose( src ); SDL_RWclose( src );
} }
@ -255,7 +256,7 @@ int AG_NormalizeSurfacesToDisplayFormat( AG_Frame* frames, int nFrames )
int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int maxFrames ) int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int maxFrames, int *loop)
{ {
int start; int start;
unsigned char buf[16]; unsigned char buf[16];
@ -394,7 +395,8 @@ int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int maxFrames )
done: done:
if ( image == NULL ) if ( image == NULL )
SDL_RWseek( src, start, SEEK_SET ); SDL_RWseek( src, start, SEEK_SET );
if (loop)
*loop = gd->loop;
free( gd ); free( gd );
return iFrame; return iFrame;
@ -432,13 +434,20 @@ static int ReadColorMap( gifdata* gd, int number, unsigned char buffer[3][MAXCOL
static int DoExtension( gifdata* gd, int label ) static int DoExtension( gifdata* gd, int label )
{ {
unsigned char buf[256]; unsigned char buf[256];
switch ( label ) switch ( label )
{ {
case 0x01: /* Plain Text Extension */ case 0x01: /* Plain Text Extension */
break; break;
case 0xff: /* Application Extension */ case 0xff: /* Application Extension */
if (GetDataBlock( gd, buf ) != 11)
break;
if (strncmp((char*)buf, "NETSCAPE2.0", 11))
break;
if (GetDataBlock( gd, buf ) != 3)
break;
if (buf[0] != 1)
break;
gd->loop = buf[1] | (buf[2] << 8);
break; break;
case 0xfe: /* Comment Extension */ case 0xfe: /* Comment Extension */

View file

@ -45,11 +45,11 @@ typedef struct
extern DECLSPEC int AG_isGIF( SDL_RWops* src ); extern DECLSPEC int AG_isGIF( SDL_RWops* src );
extern DECLSPEC int AG_LoadGIF( const char* file, AG_Frame* frames, int maxFrames ); 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 void AG_FreeSurfaces( AG_Frame* frames, int nFrames );
extern DECLSPEC int AG_ConvertSurfacesToDisplayFormat( 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 );
extern DECLSPEC int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int size ); extern DECLSPEC int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int size, int *loop );

View file

@ -1182,8 +1182,10 @@ inv:
if (new_pict || new_place) { if (new_pict || new_place) {
img_t offscreen; img_t offscreen;
game_cursor(CURSOR_CLEAR); game_cursor(CURSOR_CLEAR);
gfx_stop_gif(el_img(el_spic));
offscreen = gfx_screen(oldscreen); offscreen = gfx_screen(oldscreen);
gfx_change_screen(offscreen); gfx_change_screen(offscreen);
gfx_start_gif(el_img(el_spic));
gfx_free_image(offscreen); gfx_free_image(offscreen);
// input_clear(); // input_clear();
goto err; goto err;

View file

@ -231,6 +231,7 @@ struct _anigif_t {
struct _anigif_t *prev; struct _anigif_t *prev;
int cur_frame; int cur_frame;
int nr_frames; int nr_frames;
int loop;
int x; int x;
int y; int y;
int drawn; int drawn;
@ -254,7 +255,8 @@ static anigif_t anigif_find(anigif_t g)
return NULL; return NULL;
} }
extern int timer_counter; extern int timer_counter;
static void anigif_frame(anigif_t g)
static void anigif_disposal(anigif_t g)
{ {
SDL_Rect dest; SDL_Rect dest;
SDL_Rect clip; SDL_Rect clip;
@ -290,12 +292,24 @@ static void anigif_frame(anigif_t g)
if (img) { /* draw bg */ if (img) { /* draw bg */
SDL_BlitSurface(Surf(img), NULL, screen, &dest); SDL_BlitSurface(Surf(img), NULL, screen, &dest);
} }
dest.x = g->x; SDL_SetClipRect(screen, &clip);
dest.y = g->y; }
static void anigif_frame(anigif_t g)
{
SDL_Rect dest;
SDL_Rect clip;
AG_Frame *frame;
frame = &g->frames[g->cur_frame];
SDL_GetClipRect(screen, &clip);
dest.x = g->x + frame->x;
dest.y = g->y + frame->y;
dest.w = frame->surface->w; dest.w = frame->surface->w;
dest.h = frame->surface->h; dest.h = frame->surface->h;
dest.x += frame->x;
dest.y += frame->y; SDL_SetClipRect(screen, &g->clip);
SDL_BlitSurface(frame->surface, NULL, screen, &dest); SDL_BlitSurface(frame->surface, NULL, screen, &dest);
g->delay = timer_counter; g->delay = timer_counter;
SDL_SetClipRect(screen, &clip); SDL_SetClipRect(screen, &clip);
@ -516,10 +530,12 @@ img_t gfx_load_image(char *filename)
SDL_Surface *img; SDL_Surface *img;
int nr; int nr;
nr = AG_LoadGIF(filename, NULL, 0); nr = AG_LoadGIF(filename, NULL, 0, NULL);
if (nr > 0) { /* anigif logic */ if (nr > 0) { /* anigif logic */
int loop = 0;
anigif_t agif = malloc(sizeof(struct _anigif_t) + nr * sizeof(AG_Frame)); anigif_t agif = malloc(sizeof(struct _anigif_t) + nr * sizeof(AG_Frame));
AG_LoadGIF(filename, agif->frames, nr); AG_LoadGIF(filename, agif->frames, nr, &loop);
agif->loop = loop;
agif->nr_frames = nr; agif->nr_frames = nr;
agif->cur_frame = 0; agif->cur_frame = 0;
agif->drawn = 0; agif->drawn = 0;
@ -608,17 +624,36 @@ int gfx_frame_gif(img_t img)
{ {
anigif_t ag; anigif_t ag;
ag = is_anigif(img); ag = is_anigif(img);
if (!ag) if (!ag)
return 0; return 0;
if (!ag->drawn) if (!ag->drawn)
return 0; return 0;
if (ag->loop == -1)
return 0;
if ((timer_counter - ag->delay) < (ag->frames[ag->cur_frame].delay / HZ)) if ((timer_counter - ag->delay) < (ag->frames[ag->cur_frame].delay / HZ))
return 0; return 0;
anigif_disposal(ag);
ag->cur_frame ++; ag->cur_frame ++;
if (ag->cur_frame >= ag->nr_frames) { if (ag->cur_frame >= ag->nr_frames) {
ag->cur_frame = 0; if (!ag->loop || ag->loop > 1)
ag->cur_frame = 0;
else
ag->cur_frame --; /* last one */
if (ag->loop) {
ag->loop --;
if (!ag->loop)
ag->loop = -1; /* disabled */
}
} }
anigif_frame(ag); if (ag->loop != -1)
anigif_frame(ag);
return 1; return 1;
} }