ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_gfx_text_glyph.c File Reference

Glyph-cell blitting and text rendering for the ra8_gfx software rasteriser. More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_err.h"
#include "ra8_gfx.h"
#include "ra8_gfx_internal.h"
Include dependency graph for ra8_gfx_text_glyph.c:

Go to the source code of this file.

Enumerations

enum  ra8_gfx_glyph_bits_t : uint8_t {
  k_glyph_bits_per_byte = 8 ,
  k_glyph_msb_index = 7
}
 Constants for monochrome glyph bit extraction. More...
enum  ra8_gfx_color_masks_t : uint32_t { k_mask_byte = 0xFFU }
 Per-channel masks for colour conversion. More...
enum  ra8_gfx_byte_idx_t : uint8_t {
  k_idx_r = 0 ,
  k_idx_g = 1
}
 Per-byte indices for RGB888 packing. More...

Functions

static void internal_blit_glyph_565 (int32_t x, int32_t y, int32_t gw, int32_t gh, uint32_t row_bytes, const uint8_t *gd, uint32_t fg, uint32_t bg)
 Blit one 1-bpp glyph cell into an RGB565 framebuffer, clipped on screen.
static void internal_render_glyph (int32_t x, int32_t y, const ra8_gfx_font_t *font, uint8_t cp, uint32_t fg, uint32_t bg)
 Render a single glyph at (x,y).
ra8_err_t ra8_gfx_text_out (int32_t x, int32_t y, const char *str, const ra8_gfx_font_t *font, uint32_t fg_color, uint32_t bg_color)
 Render a NUL-terminated ASCII string.
ra8_err_t ra8_gfx_text_size (const char *str, const ra8_gfx_font_t *font, uint32_t *out_w, uint32_t *out_h)
 Compute rendered pixel dimensions of a string.

Detailed Description

Glyph-cell blitting and text rendering for the ra8_gfx software rasteriser.

Holds the text sub-responsibility of the software pixel-pusher: the 1-bpp glyph-cell blitters and the public text entry points (ra8_gfx_text_out, ra8_gfx_text_size). These share the single framebuffer binding (g_gfx_text_state) and the low-level packers/plotters with the core rasteriser TU (ra8_gfx_text.c) via ra8_gfx_internal.h.

Since
0.1.0

Definition in file ra8_gfx_text_glyph.c.

Enumeration Type Documentation

◆ ra8_gfx_byte_idx_t

enum ra8_gfx_byte_idx_t : uint8_t

Per-byte indices for RGB888 packing.

Enumerator
k_idx_r 

Index r.

k_idx_g 

Index g.

Definition at line 45 of file ra8_gfx_text_glyph.c.

◆ ra8_gfx_color_masks_t

enum ra8_gfx_color_masks_t : uint32_t

Per-channel masks for colour conversion.

Enumerator
k_mask_byte 

Mask byte.

Definition at line 37 of file ra8_gfx_text_glyph.c.

◆ ra8_gfx_glyph_bits_t

enum ra8_gfx_glyph_bits_t : uint8_t

Constants for monochrome glyph bit extraction.

Enumerator
k_glyph_bits_per_byte 

Glyph bits per byte.

k_glyph_msb_index 

Glyph msb index.

Definition at line 28 of file ra8_gfx_text_glyph.c.

Function Documentation

◆ internal_blit_glyph_565()

void internal_blit_glyph_565 ( int32_t x,
int32_t y,
int32_t gw,
int32_t gh,
uint32_t row_bytes,
const uint8_t * gd,
uint32_t fg,
uint32_t bg )
static

Blit one 1-bpp glyph cell into an RGB565 framebuffer, clipped on screen.

The foreground and background colours are packed to RGB565 once, then each visible cell pixel stores the two pre-packed bytes directly – so the per-glyph colour packing (priv_gfx_text_pack_565 + per-channel extraction) and the per-pixel clip happen once each instead of once per pixel. The cell is clipped to the framebuffer up front (the same in-bounds set priv_gfx_text_plot would have written), and every on/off bit maps to the same colour, so the result is byte-identical to the per-pixel priv_gfx_text_plot path. The full cell is painted (foreground for set bits, background for clear bits), matching the per-pixel path's opaque cell.

Parameters
[in]xGlyph top-left x in framebuffer pixels.
[in]yGlyph top-left y in framebuffer pixels.
[in]gwGlyph cell width in pixels.
[in]ghGlyph cell height in pixels.
[in]row_bytesBytes per glyph row in gd.
[in]gdPacked 1-bpp glyph bitmap (MSB-first within each byte).
[in]fgForeground 32-bit colour (applied to set bits).
[in]bgBackground 32-bit colour (applied to clear bits).
Precondition
The bound format is k_ra8_gfx_format_rgb565.
gd addresses at least gh*row_bytes bytes.
Postcondition
Every on-screen cell pixel holds fg (set bit) or bg (clear bit).
No off-screen pixel is modified.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 79 of file ra8_gfx_text_glyph.c.

References g_gfx_text_state, k_glyph_bits_per_byte, k_glyph_msb_index, k_idx_g, k_idx_r, k_mask_byte, and priv_gfx_text_pack_565().

Referenced by internal_render_glyph().

◆ internal_render_glyph()

void internal_render_glyph ( int32_t x,
int32_t y,
const ra8_gfx_font_t * font,
uint8_t cp,
uint32_t fg,
uint32_t bg )
static

Render a single glyph at (x,y).

See implementation.

Parameters
[in]xSee implementation.
[in]ySee implementation.
[in]fontSee implementation.
[in]cpSee implementation.
[in]fgSee implementation.
[in]bgSee implementation.
Precondition
Module state is consistent.
Module state is consistent.
Postcondition
Caller-visible state matches the documented contract.
Caller-visible state matches the documented contract.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 145 of file ra8_gfx_text_glyph.c.

References ra8_gfx_font_t::bytes_per_glyph, ra8_gfx_font_t::first_codepoint, g_gfx_text_state, ra8_gfx_font_t::glyph_data, ra8_gfx_font_t::glyph_height, ra8_gfx_font_t::glyph_width, internal_blit_glyph_565(), k_glyph_bits_per_byte, k_glyph_msb_index, k_ra8_gfx_format_rgb565, ra8_gfx_font_t::last_codepoint, and priv_gfx_text_plot().

Referenced by ra8_gfx_text_out().

◆ ra8_gfx_text_out()

ra8_err_t ra8_gfx_text_out ( int32_t x,
int32_t y,
const char * str,
const ra8_gfx_font_t * font,
uint32_t fg_color,
uint32_t bg_color )
nodiscard

Render a NUL-terminated ASCII string.

Parameters
[in]x,yTop-left of the first glyph.
[in]strNUL-terminated ASCII string (NULL not allowed).
[in]fontFont descriptor (NULL not allowed).
[in]fg_colorForeground colour.
[in]bg_colorBackground colour.
Returns
Error code.
Return values
k_ra8_okRendered.
k_ra8_err_null_ptrstr or font was NULL.
k_ra8_err_not_initializedra8_gfx_init() was not called.
Precondition
ra8_gfx_init() returned k_ra8_ok.
font->glyph_data covers at least last-first+1 glyphs.
Postcondition
Glyph cells within bounds are filled with fg/bg colour pairs.
Since
0.1.0

Definition at line 182 of file ra8_gfx_text_glyph.c.

References g_gfx_text_state, ra8_gfx_font_t::glyph_width, internal_render_glyph(), k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_gfx_max_dim, and k_ra8_ok.

Referenced by ch_render(), cm_draw_status_bar(), er_draw_key_label(), er_nag_render(), er_text_left(), ls_text(), mg_render_status(), render_page(), sh_comic_render(), sh_cover_button(), sh_cover_render(), sh_draw_card(), sh_loading_overlay(), sh_reader_render(), sh_titlebar(), sh_toc_render(), wc_footer_render(), wc_status_render(), wc_tile_render(), wd_content_render(), wd_status_render(), wd_tabbar_render(), wd_text(), and wk_paint_text().

◆ ra8_gfx_text_size()

ra8_err_t ra8_gfx_text_size ( const char * str,
const ra8_gfx_font_t * font,
uint32_t * out_w,
uint32_t * out_h )
nodiscard

Compute rendered pixel dimensions of a string.

Parameters
[in]strASCII string.
[in]fontFont descriptor.
[out]out_wReceives total pixel width.
[out]out_hReceives total pixel height (font glyph height).
Returns
Error code.
Return values
k_ra8_okMeasured.
k_ra8_err_null_ptrAny argument was NULL.
Precondition
All pointer arguments are non-NULL.
Postcondition
*out_w and *out_h are written.
Since
0.1.0

Definition at line 211 of file ra8_gfx_text_glyph.c.

References ra8_gfx_font_t::glyph_height, ra8_gfx_font_t::glyph_width, k_ra8_err_null_ptr, k_ra8_gfx_max_dim, and k_ra8_ok.

Referenced by er_text_right(), ls_text(), wd_size(), and wk_paint_size().