From ca3638313b2952629f68b92edbdc0152355476f0 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Thu, 29 Feb 2024 03:10:48 +0200 Subject: [PATCH] moved ftext to libs as frametext --- src/{v4p/ftext.c => libs/frametext.c} | 31 +++++++++---------- src/{v4p/ftext.h => libs/frametext.h} | 12 +++---- .../ftext_font.c => libs/frametext_font.c} | 6 ++-- .../ftext_font.h => libs/frametext_font.h} | 4 +-- src/v4p/drm.c | 9 +++--- src/v4p/drm.h | 5 ++- 6 files changed, 33 insertions(+), 34 deletions(-) rename src/{v4p/ftext.c => libs/frametext.c} (87%) rename src/{v4p/ftext.h => libs/frametext.h} (87%) rename src/{v4p/ftext_font.c => libs/frametext_font.c} (99%) rename src/{v4p/ftext_font.h => libs/frametext_font.h} (96%) diff --git a/src/v4p/ftext.c b/src/libs/frametext.c similarity index 87% rename from src/v4p/ftext.c rename to src/libs/frametext.c index e1bc4ab..606e409 100644 --- a/src/v4p/ftext.c +++ b/src/libs/frametext.c @@ -20,7 +20,7 @@ *****************************************************************************/ -#include "ftext.h" +#include "frametext.h" #include @@ -28,32 +28,31 @@ #include -#include "../libs/tools.h" -#include "../libs/frame.h" - -#include "ftext_font.h" +#include "tools.h" +#include "frame.h" +#include "frametext_font.h" -static void _ftext_draw_line( - us_ftext_s *ft, const char *line, +static void _frametext_draw_line( + us_frametext_s *ft, const char *line, uint scale_x, uint scale_y, uint start_x, uint start_y); -us_ftext_s *us_ftext_init(void) { - us_ftext_s *ft; +us_frametext_s *us_frametext_init(void) { + us_frametext_s *ft; US_CALLOC(ft, 1); ft->frame = us_frame_init(); return ft; } -void us_ftext_destroy(us_ftext_s *ft) { +void us_frametext_destroy(us_frametext_s *ft) { us_frame_destroy(ft->frame); US_DELETE(ft->text, free); free(ft); } -void us_ftext_draw(us_ftext_s *ft, const char *text, uint width, uint height) { +void us_frametext_draw(us_frametext_s *ft, const char *text, uint width, uint height) { us_frame_s *const frame = ft->frame; if ( @@ -110,7 +109,7 @@ void us_ftext_draw(us_ftext_s *ft, const char *text, uint width, uint height) { const uint start_x = (frame->width >= line_width ? ((frame->width - line_width) / 2) : 0); - _ftext_draw_line(ft, line, scale_x, scale_y, start_x, start_y + n_line * 8 * scale_y); + _frametext_draw_line(ft, line, scale_x, scale_y, start_x, start_y + n_line * 8 * scale_y); ++n_line; } @@ -118,8 +117,8 @@ empty: free(str); } -void _ftext_draw_line( - us_ftext_s *ft, const char *line, +void _frametext_draw_line( + us_frametext_s *ft, const char *line, uint scale_x, uint scale_y, uint start_x, uint start_y) { @@ -139,10 +138,10 @@ void _ftext_draw_line( break; } - const u8 ch = US_MIN((u8)line[ch_x / 8 / scale_x], sizeof(US_FTEXT_FONT) / 8 - 1); + const u8 ch = US_MIN((u8)line[ch_x / 8 / scale_x], sizeof(US_FRAMETEXT_FONT) / 8 - 1); const uint ch_byte = (ch_y / scale_y) % 8; const uint ch_bit = (ch_x / scale_x) % 8; - const bool pix_on = !!(US_FTEXT_FONT[ch][ch_byte] & (1 << ch_bit)); + const bool pix_on = !!(US_FRAMETEXT_FONT[ch][ch_byte] & (1 << ch_bit)); u8 *const b = &frame->data[offset]; // XXX: Big endian for Raspberry u8 *const g = b + 1; diff --git a/src/v4p/ftext.h b/src/libs/frametext.h similarity index 87% rename from src/v4p/ftext.h rename to src/libs/frametext.h index 40bf06a..d2d3a51 100644 --- a/src/v4p/ftext.h +++ b/src/libs/frametext.h @@ -23,17 +23,17 @@ #pragma once -#include "../libs/types.h" -#include "../libs/frame.h" +#include "types.h" +#include "frame.h" typedef struct { char *text; us_frame_s *frame; -} us_ftext_s; +} us_frametext_s; -us_ftext_s *us_ftext_init(void); -void us_ftext_destroy(us_ftext_s *ft); +us_frametext_s *us_frametext_init(void); +void us_frametext_destroy(us_frametext_s *ft); -void us_ftext_draw(us_ftext_s *ft, const char *text, uint width, uint height); +void us_frametext_draw(us_frametext_s *ft, const char *text, uint width, uint height); diff --git a/src/v4p/ftext_font.c b/src/libs/frametext_font.c similarity index 99% rename from src/v4p/ftext_font.c rename to src/libs/frametext_font.c index 9fe6838..1902f38 100644 --- a/src/v4p/ftext_font.c +++ b/src/libs/frametext_font.c @@ -20,10 +20,12 @@ *****************************************************************************/ -#include "ftext_font.h" +#include "frametext_font.h" + +#include "types.h" -const u8 US_FTEXT_FONT[128][8] = { +const u8 US_FRAMETEXT_FONT[128][8] = { // https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul) {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001 diff --git a/src/v4p/ftext_font.h b/src/libs/frametext_font.h similarity index 96% rename from src/v4p/ftext_font.h rename to src/libs/frametext_font.h index 018e3d9..31214bf 100644 --- a/src/v4p/ftext_font.h +++ b/src/libs/frametext_font.h @@ -22,7 +22,7 @@ #pragma once -#include "../libs/types.h" +#include "types.h" -extern const u8 US_FTEXT_FONT[128][8]; +extern const u8 US_FRAMETEXT_FONT[128][8]; diff --git a/src/v4p/drm.c b/src/v4p/drm.c index 8da8e1c..e53ed63 100644 --- a/src/v4p/drm.c +++ b/src/v4p/drm.c @@ -39,8 +39,7 @@ #include "../libs/tools.h" #include "../libs/logging.h" #include "../libs/frame.h" - -#include "ftext.h" +#include "../libs/frametext.h" static void _drm_vsync_callback(int fd, uint n_frame, uint sec, uint usec, void *v_run); @@ -69,7 +68,7 @@ us_drm_s *us_drm_init(void) { US_CALLOC(run, 1); run->fd = -1; run->status_fd = -1; - run->ft = us_ftext_init(); + run->ft = us_frametext_init(); run->state = US_DRM_STATE_CLOSED; us_drm_s *drm; @@ -84,7 +83,7 @@ us_drm_s *us_drm_init(void) { void us_drm_destroy(us_drm_s *drm) { _drm_cleanup(drm); - us_ftext_destroy(drm->run->ft); + us_frametext_destroy(drm->run->ft); US_DELETE(drm->run, free); US_DELETE(drm, free); // cppcheck-suppress uselessAssignmentPtrArg } @@ -142,7 +141,7 @@ int us_drm_expose(us_drm_s *drm, us_drm_expose_e ex, const us_frame_s *frame, fl bool msg_drawn = false; # define DRAW_MSG(x_msg) { \ - us_ftext_draw(run->ft, (x_msg), mode->hdisplay, mode->vdisplay); \ + us_frametext_draw(run->ft, (x_msg), mode->hdisplay, mode->vdisplay); \ frame = run->ft->frame; \ msg_drawn = true; \ } diff --git a/src/v4p/drm.h b/src/v4p/drm.h index 964b0dc..f288aad 100644 --- a/src/v4p/drm.h +++ b/src/v4p/drm.h @@ -27,8 +27,7 @@ #include "../libs/types.h" #include "../libs/frame.h" - -#include "ftext.h" +#include "../libs/frametext.h" typedef enum { @@ -65,7 +64,7 @@ typedef struct { uint next_n_buf; bool has_vsync; - us_ftext_s *ft; + us_frametext_s *ft; uint p_width; uint p_height;