From 4765653cb3af905a9b20f1e5f2277e50d801c43b Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 20 Feb 2022 19:04:21 +0100 Subject: Add metadata header to media files The following properties are supported: - Sound: "loop". Must be either 0 or 1 - Images: "transparent". Must be either 0 or 1 These headers are only used for non-PS1 builds, since .TIM and .VAG files do already implement such information. --- src/gfx/CMakeLists.txt | 1 + src/gfx/sdl-1.2/src/sprite.c | 54 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) (limited to 'src/gfx') diff --git a/src/gfx/CMakeLists.txt b/src/gfx/CMakeLists.txt index 6685608..9cc1b0e 100644 --- a/src/gfx/CMakeLists.txt +++ b/src/gfx/CMakeLists.txt @@ -25,6 +25,7 @@ elseif(SDL1_2_BUILD) "sdl-1.2/src/sprite.c" "sdl-1.2/src/quad.c") set(deps ${deps} SDL) + set(privdeps ${privdeps} header) endif() add_library(gfx ${src}) diff --git a/src/gfx/sdl-1.2/src/sprite.c b/src/gfx/sdl-1.2/src/sprite.c index 9d65c0d..e20f1c8 100644 --- a/src/gfx/sdl-1.2/src/sprite.c +++ b/src/gfx/sdl-1.2/src/sprite.c @@ -1,8 +1,11 @@ #include #include +#include #include +#include #include #include +#include void sprite_free(struct sprite *const s) { @@ -16,7 +19,41 @@ int sprite_clone(const struct sprite *const src, struct sprite *const dst) return 0; } -int sprite_from_fp(struct sprite *const s, FILE *const f) +int sprite_screen_resize_ev(struct sprite *const s) +{ + int ret = -1; + SDL_Surface *const old = s->s; + + /* Magenta as transparent. */ + if (s->transparent + && SDL_SetColorKey(old, SDL_SRCCOLORKEY | SDL_RLEACCEL, + SDL_MapRGB(old->format, 255, 0, 255))) + { + fprintf(stderr, "SDL_SetColorKey: %s\n", SDL_GetError()); + goto end; + } + else if (!(s->s = SDL_DisplayFormat(old))) + { + fprintf(stderr, "SDL_DisplayFormat: %s\n", SDL_GetError()); + goto end; + } + + ret = 0; + +end: + SDL_FreeSurface(old); + return ret; +} + +static int load_header(struct sprite *const s, FILE *const f) +{ + if (header_load_bool(f, "transparent", &s->transparent)) + return -1; + + return 0; +} + +static int load_bitmap(struct sprite *const s, FILE *const f) { int ret = -1; SDL_RWops *ops = NULL; @@ -33,7 +70,9 @@ int sprite_from_fp(struct sprite *const s, FILE *const f) goto end; } /* Magenta as transparent. */ - else if (SDL_SetColorKey(ts, SDL_SRCCOLORKEY, SDL_MapRGB(ts->format, 255, 0, 255))) + else if (s->transparent + && SDL_SetColorKey(ts, SDL_SRCCOLORKEY | SDL_RLEACCEL, + SDL_MapRGB(ts->format, 255, 0, 255))) { fprintf(stderr, "SDL_SetColorKey: %s\n", SDL_GetError()); goto end; @@ -44,6 +83,7 @@ int sprite_from_fp(struct sprite *const s, FILE *const f) goto end; } + gfx_register_sprite(s); s->w = ts->w; s->h = ts->h; ret = 0; @@ -54,6 +94,16 @@ end: return ret; } +int sprite_from_fp(struct sprite *const s, FILE *const f) +{ + memset(s, 0, sizeof *s); + + if (load_header(s, f) || load_bitmap(s, f)) + return -1; + + return 0; +} + void sprite_sort(struct sprite *const s) { SDL_Rect r = -- cgit v1.2.3