Skip to content

Commit

Permalink
moved ftext to libs as frametext
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Feb 29, 2024
1 parent bb3e4ec commit ca36383
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
31 changes: 15 additions & 16 deletions src/v4p/ftext.c → src/libs/frametext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,39 @@
*****************************************************************************/


#include "ftext.h"
#include "frametext.h"

#include <string.h>

#include <sys/types.h>

#include <linux/videodev2.h>

#include "../libs/tools.h"
#include "../libs/frame.h"
#include "tools.h"
#include "frame.h"
#include "frametext_font.h"

#include "ftext_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 (
Expand Down Expand Up @@ -110,16 +109,16 @@ 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;
}

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) {

Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/v4p/ftext.h → src/libs/frametext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 4 additions & 2 deletions src/v4p/ftext_font.c → src/libs/frametext_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/v4p/ftext_font.h → src/libs/frametext_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
9 changes: 4 additions & 5 deletions src/v4p/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
}
Expand Down Expand Up @@ -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; \
}
Expand Down
5 changes: 2 additions & 3 deletions src/v4p/drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

#include "../libs/types.h"
#include "../libs/frame.h"

#include "ftext.h"
#include "../libs/frametext.h"


typedef enum {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ca36383

Please sign in to comment.