From 046fa888e4df754a20736303c27f497163edf4db Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 5 Mar 2020 04:12:37 +0200 Subject: [PATCH] intro screen --- libs/imago/src/conv.c | 50 ++++++++++++++++++++++++++++++++++++--- libs/imago/src/imago2.h | 1 + src/game.c | 10 +++++--- src/introscr.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/menuscr.c | 2 +- src/menuscr.h | 13 ---------- src/screens.h | 18 ++++++++++++++ 7 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 src/introscr.c delete mode 100644 src/menuscr.h create mode 100644 src/screens.h diff --git a/libs/imago/src/conv.c b/libs/imago/src/conv.c index 334fe35..bd7fb2d 100644 --- a/libs/imago/src/conv.c +++ b/libs/imago/src/conv.c @@ -1,6 +1,6 @@ /* libimago - a multi-format image file input/output library. -Copyright (C) 2010 John Tsiombikas +Copyright (C) 2010-2020 John Tsiombikas This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -17,6 +17,7 @@ along with this program. If not, see . */ #include #include "imago2.h" +#include "inttypes.h" /* pixel-format conversions are sub-optimal at the moment to avoid * writing a lot of code. optimize at some point ? @@ -34,6 +35,7 @@ static void unpack_rgba32(struct pixel *unp, void *pptr, int count); static void unpack_greyf(struct pixel *unp, void *pptr, int count); static void unpack_rgbf(struct pixel *unp, void *pptr, int count); static void unpack_rgbaf(struct pixel *unp, void *pptr, int count); +static void unpack_rgb565(struct pixel *unp, void *pptr, int count); static void pack_grey8(void *pptr, struct pixel *unp, int count); static void pack_rgb24(void *pptr, struct pixel *unp, int count); @@ -41,6 +43,7 @@ static void pack_rgba32(void *pptr, struct pixel *unp, int count); static void pack_greyf(void *pptr, struct pixel *unp, int count); static void pack_rgbf(void *pptr, struct pixel *unp, int count); static void pack_rgbaf(void *pptr, struct pixel *unp, int count); +static void pack_rgb565(void *pptr, struct pixel *unp, int count); /* XXX keep in sync with enum img_fmt at imago2.h */ static void (*unpack[])(struct pixel*, void*, int) = { @@ -49,7 +52,8 @@ static void (*unpack[])(struct pixel*, void*, int) = { unpack_rgba32, unpack_greyf, unpack_rgbf, - unpack_rgbaf + unpack_rgbaf, + unpack_rgb565 }; /* XXX keep in sync with enum img_fmt at imago2.h */ @@ -59,7 +63,8 @@ static void (*pack[])(void*, struct pixel*, int) = { pack_rgba32, pack_greyf, pack_rgbf, - pack_rgbaf + pack_rgbaf, + pack_rgb565 }; @@ -180,6 +185,28 @@ static void unpack_rgbaf(struct pixel *unp, void *pptr, int count) } } +static void unpack_rgb565(struct pixel *unp, void *pptr, int count) +{ + int i; + uint16_t *pix = pptr; + + for(i=0; i> 2) & 0xfc; + if(g & 4) g |= 3; /* ditto */ + b = (p >> 8) & 0xf8; + if(b & 8) r |= 7; /* same */ + + unp->r = (float)r / 255.0f; + unp->g = (float)g / 255.0f; + unp->b = (float)b / 255.0f; + unp->a = 1.0f; + unp++; + } +} + static void pack_grey8(void *pptr, struct pixel *unp, int count) { @@ -258,3 +285,20 @@ static void pack_rgbaf(void *pptr, struct pixel *unp, int count) memcpy(pptr, unp, count * sizeof *unp); } + +static void pack_rgb565(void *pptr, struct pixel *unp, int count) +{ + int i; + uint16_t *pix = pptr; + + for(i=0; ir * 255.0f); + uint16_t g = (uint16_t)(unp->g * 255.0f); + uint16_t b = (uint16_t)(unp->b * 255.0f); + if(r > 255) r = 255; + if(g > 255) g = 255; + if(b > 255) b = 255; + *pix++ = (r >> 3) | ((g & 0x3f) << 2) | ((b & 0x1f) << 8); + unp++; + } +} diff --git a/libs/imago/src/imago2.h b/libs/imago/src/imago2.h index b0bea09..2cd1481 100644 --- a/libs/imago/src/imago2.h +++ b/libs/imago/src/imago2.h @@ -35,6 +35,7 @@ enum img_fmt { IMG_FMT_GREYF, IMG_FMT_RGBF, IMG_FMT_RGBAF, + IMG_FMT_RGB565, NUM_IMG_FMT }; diff --git a/src/game.c b/src/game.c index 88a7e3f..2ec7c45 100644 --- a/src/game.c +++ b/src/game.c @@ -1,5 +1,5 @@ #include "game.h" -#include "menuscr.h" +#include "screens.h" int fb_width, fb_height; long fb_size; @@ -13,16 +13,20 @@ void (*key_event)(int key, int pressed); int init(int argc, char **argv) { + if(intro_init() == -1) { + return -1; + } if(menu_init() == -1) { return -1; } - draw = menu_draw; - key_event = menu_keyb; + draw = intro_draw; + key_event = intro_keyb; return 0; } void cleanup(void) { + intro_cleanup(); menu_cleanup(); } diff --git a/src/introscr.c b/src/introscr.c new file mode 100644 index 0000000..16567ff --- /dev/null +++ b/src/introscr.c @@ -0,0 +1,60 @@ +#include +#include "screens.h" +#include "imago2.h" +#include "gfx.h" +#include "gfxutil.h" +#include "game.h" + +#define FADE_DUR 1024 + +static void *logo; +static int logo_width, logo_height; +static long start_time; + +int intro_init(void) +{ + if(!(logo = img_load_pixels("data/msglogo.jpg", &logo_width, &logo_height, IMG_FMT_RGB24))) { + fprintf(stderr, "failed to load logo image\n"); + return -1; + } + return 0; +} + +void intro_cleanup(void) +{ + img_free_pixels(logo); +} + +void intro_start(void) +{ + start_time = time_msec; +} + +void intro_stop(void) +{ +} + +void intro_draw(void) +{ + int i, j; + uint16_t fade; + unsigned char *src = logo; + uint16_t *dest = fb_pixels; + + fade = (time_msec - start_time) * 256 / FADE_DUR; + if(fade > 256) fade = 256; + + for(i=0; i -#include "menuscr.h" +#include "screens.h" #include "imago2.h" #include "gfx.h" #include "gfxutil.h" diff --git a/src/menuscr.h b/src/menuscr.h deleted file mode 100644 index 2551662..0000000 --- a/src/menuscr.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MENUSCR_H_ -#define MENUSCR_H_ - -int menu_init(void); -void menu_cleanup(void); - -void menu_start(void); -void menu_stop(void); - -void menu_draw(void); -void menu_keyb(int key, int pressed); - -#endif /* MENUSCR_H_ */ diff --git a/src/screens.h b/src/screens.h new file mode 100644 index 0000000..9f07cd0 --- /dev/null +++ b/src/screens.h @@ -0,0 +1,18 @@ +#ifndef SCREENS_H_ +#define SCREENS_H_ + +int intro_init(void); +void intro_cleanup(void); +void intro_start(void); +void intro_stop(void); +void intro_draw(void); +void intro_keyb(int key, int pressed); + +int menu_init(void); +void menu_cleanup(void); +void menu_start(void); +void menu_stop(void); +void menu_draw(void); +void menu_keyb(int key, int pressed); + +#endif /* SCREENS_H_ */ -- 1.7.10.4