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
#
# LUA_CFLAGS=$(shell pkg-config --cflags lua)
# LUA_LFLAGS=$(shell pkg-config --libs lua)
LUA_CFLAGS=$(shell pkg-config --cflags lua)
LUA_LFLAGS=$(shell pkg-config --libs lua)
#
SDL_CFLAGS=$(shell sdl-config --cflags)

File diff suppressed because it is too large Load diff

View file

@ -1,61 +1,61 @@
/*
SDL_anigif: An example animated GIF image loading library for use with SDL
SDL_image Copyright (C) 1997-2006 Sam Lantinga
Animated GIF "derived work" Copyright (C) 2006 Doug McFadyen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SDL_ANIGIF_H
#define _SDL_ANIGIF_H
#include <SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
SDL_Surface* surface; /* SDL surface for this frame */
int x, y; /* Frame offset position */
int disposal; /* Disposal code */
int delay; /* Frame delay in ms */
int user; /* User data (not used by aniGIF) */
} AG_Frame;
#define AG_DISPOSE_NA 0 /* No disposal specified */
#define AG_DISPOSE_NONE 1 /* Do not dispose */
#define AG_DISPOSE_RESTORE_BACKGROUND 2 /* Restore to background */
#define AG_DISPOSE_RESTORE_PREVIOUS 3 /* Restore to previous */
extern DECLSPEC int AG_isGIF( SDL_RWops* src );
extern DECLSPEC int AG_LoadGIF( const char* file, AG_Frame* frames, int maxFrames );
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_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int size );
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_ANIGIF_H */
/*
SDL_anigif: An example animated GIF image loading library for use with SDL
SDL_image Copyright (C) 1997-2006 Sam Lantinga
Animated GIF "derived work" Copyright (C) 2006 Doug McFadyen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SDL_ANIGIF_H
#define _SDL_ANIGIF_H
#include <SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
SDL_Surface* surface; /* SDL surface for this frame */
int x, y; /* Frame offset position */
int disposal; /* Disposal code */
int delay; /* Frame delay in ms */
int user; /* User data (not used by aniGIF) */
} AG_Frame;
#define AG_DISPOSE_NA 0 /* No disposal specified */
#define AG_DISPOSE_NONE 1 /* Do not dispose */
#define AG_DISPOSE_RESTORE_BACKGROUND 2 /* Restore to background */
#define AG_DISPOSE_RESTORE_PREVIOUS 3 /* Restore to previous */
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_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int size, int *loop );
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* _SDL_ANIGIF_H */

View file

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

View file

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