diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-02-20 19:04:21 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:21 +0200 |
| commit | 4765653cb3af905a9b20f1e5f2277e50d801c43b (patch) | |
| tree | 9c9f914e5ea9b19f2312cd43221df37d19dec2f3 /src/gfx | |
| parent | c9754ac4300abad20d942ad18bc5bf611a0b3a2e (diff) | |
| download | jancity-4765653cb3af905a9b20f1e5f2277e50d801c43b.tar.gz | |
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.
Diffstat (limited to 'src/gfx')
| -rw-r--r-- | src/gfx/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/sprite.c | 54 |
2 files changed, 53 insertions, 2 deletions
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 <gfx.h> #include <gfx/port.h> +#include <header.h> #include <SDL/SDL.h> +#include <errno.h> #include <stddef.h> #include <stdlib.h> +#include <string.h> 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 = |
