From 37876bbec8fb858d7907db91a9334faa62a7aa38 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 9 Mar 2023 12:25:55 +0100 Subject: [PATCH] caca: updates - added splashscreen - fixed RGB-shifts - redraw last frawme if resized --- src/utils/misc.cpp | 33 +++++++++++++++++++++++++++++++++ src/utils/misc.h | 1 + src/video_display/caca.c | 26 +++++++++++++++++++------- src/video_display/gl.cpp | 32 +++----------------------------- 4 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/utils/misc.cpp b/src/utils/misc.cpp index 8373a3d77..9357358e8 100644 --- a/src/utils/misc.cpp +++ b/src/utils/misc.cpp @@ -56,6 +56,8 @@ #include "utils/macros.h" #include "utils/misc.h" #include "utils/color_out.h" +#include "video.h" +#include "video_display/splashscreen.h" #define STRERROR_BUF_LEN 1024 @@ -304,3 +306,34 @@ uint32_t parse_uint32(const char *value_str) noexcept(false) } return val; } + +struct video_frame *get_splashscreen() +{ + struct video_desc desc; + + desc.width = 512; + desc.height = 512; + desc.color_spec = RGBA; + desc.interlacing = PROGRESSIVE; + desc.fps = 1; + desc.tile_count = 1; + + struct video_frame *frame = vf_alloc_desc_data(desc); + + const char *data = splash_data; + memset(frame->tiles[0].data, 0, frame->tiles[0].data_len); + for (unsigned int y = 0; y < splash_height; ++y) { + char *line = frame->tiles[0].data; + line += vc_get_linesize(frame->tiles[0].width, + frame->color_spec) * + (((frame->tiles[0].height - splash_height) / 2) + y); + line += vc_get_linesize( + (frame->tiles[0].width - splash_width)/2, + frame->color_spec); + for (unsigned int x = 0; x < splash_width; ++x) { + HEADER_PIXEL(data,line); + line += 4; + } + } + return frame; +} diff --git a/src/utils/misc.h b/src/utils/misc.h index 12d69b72b..b30c98be9 100644 --- a/src/utils/misc.h +++ b/src/utils/misc.h @@ -68,6 +68,7 @@ struct key_val { const char *val; }; void print_module_usage(const char *module_name, const struct key_val *options, const struct key_val *options_full, bool print_full_help); +struct video_frame *get_splashscreen(); #ifdef __cplusplus } diff --git a/src/video_display/caca.c b/src/video_display/caca.c index e97e95c4f..c6810b1a4 100644 --- a/src/video_display/caca.c +++ b/src/video_display/caca.c @@ -44,9 +44,11 @@ #include "debug.h" #include "lib_common.h" #include "utils/color_out.h" +#include "utils/misc.h" #include "tv.h" #include "video.h" #include "video_display.h" +#include "video_display/splashscreen.h" #define MOD_NAME "[caca] " @@ -112,6 +114,9 @@ static void *display_caca_init(struct module *parent, const char *fmt, unsigned display_caca_done(s); return NULL; } + + s->f = get_splashscreen(); + pthread_mutex_init(&s->lock, NULL); pthread_cond_init(&s->frame_ready_cv, NULL); pthread_cond_init(&s->frame_consumed_cv, NULL); @@ -126,7 +131,7 @@ static struct video_frame *display_caca_getf(void *state) return vf_alloc_desc_data(s->desc); } -static void handle_events(struct state_caca *s) +static void handle_events(struct state_caca *s, struct video_frame *last_frame) { caca_event_t e; int ret = 0; @@ -141,6 +146,10 @@ static void handle_events(struct state_caca *s) s->screen_w = e.data.resize.w; s->screen_h = e.data.resize.h; verbose_msg(MOD_NAME "Resized to %dx%d\n", s->screen_w, s->screen_h); + if (last_frame) { + caca_dither_bitmap(s->canvas, 0, 0, s->screen_w, s->screen_h, s->dither, last_frame->tiles[0].data); + caca_refresh_display(s->display); + } break; case CACA_EVENT_QUIT: exit_uv(0); @@ -153,9 +162,9 @@ static void handle_events(struct state_caca *s) static _Bool reconfigure(struct state_caca *s, struct video_desc desc) { enum { - RMASK = 0xff0000, + RMASK = 0x0000ff, GMASK = 0x00ff00, - BMASK = 0x0000ff, + BMASK = 0xff0000, AMASK = 0x000000, }; caca_free_dither(s->dither); @@ -178,6 +187,7 @@ static void *worker(void *arg) { struct video_desc display_desc = { 0 }; struct state_caca *s = arg; + struct video_frame *last_frame = NULL; while (1) { struct video_frame *f = NULL; time_ns_t tout = get_time_in_ns() + 200 * NS_IN_MS; @@ -185,7 +195,7 @@ static void *worker(void *arg) pthread_mutex_lock(&s->lock); while (!s->f && !s->should_exit) { pthread_cond_timedwait(&s->frame_ready_cv, &s->lock, &timeout); - handle_events(s); + handle_events(s, last_frame); } f = s->f; s->f = NULL; @@ -202,12 +212,14 @@ static void *worker(void *arg) display_desc = video_desc_from_frame(f); } - handle_events(s); + handle_events(s, last_frame); caca_dither_bitmap(s->canvas, 0, 0, s->screen_w, s->screen_h, s->dither, f->tiles[0].data); caca_refresh_display(s->display); - handle_events(s); - vf_free(f); + handle_events(s, last_frame); + vf_free(last_frame); + last_frame = f; } + vf_free(last_frame); return NULL; } diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index 861fe4018..c99d2c735 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -79,6 +79,7 @@ #include "module.h" #include "utils/color_out.h" #include "utils/macros.h" // OPTIMIZED_FOR +#include "utils/misc.h" #include "utils/ref_count.hpp" #include "video.h" #include "video_display.h" @@ -531,35 +532,8 @@ static void gl_show_help(bool full) { static void gl_load_splashscreen(struct state_gl *s) { - struct video_desc desc; - - desc.width = 512; - desc.height = 512; - desc.color_spec = RGBA; - desc.interlacing = PROGRESSIVE; - desc.fps = 1; - desc.tile_count = 1; - - display_gl_reconfigure(s, desc); - - struct video_frame *frame = vf_alloc_desc_data(desc); - - const char *data = splash_data; - memset(frame->tiles[0].data, 0, frame->tiles[0].data_len); - for (unsigned int y = 0; y < splash_height; ++y) { - char *line = frame->tiles[0].data; - line += vc_get_linesize(frame->tiles[0].width, - frame->color_spec) * - (((frame->tiles[0].height - splash_height) / 2) + y); - line += vc_get_linesize( - (frame->tiles[0].width - splash_width)/2, - frame->color_spec); - for (unsigned int x = 0; x < splash_width; ++x) { - HEADER_PIXEL(data,line); - line += 4; - } - } - + struct video_frame *frame = get_splashscreen(); + display_gl_reconfigure(s, video_desc_from_frame(frame)); s->frame_queue.push(frame); }