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

Software pixel-pusher implementation of ra8_gfx primitives. More...

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

Go to the source code of this file.

Enumerations

enum  gfx_565_mask_t : uint32_t {
  k_565_r_mask = 0x1FU ,
  k_565_g_mask = 0x3FU ,
  k_565_b_mask = 0x1FU
}
 RGB565 channel masks. More...
enum  ra8_gfx_color_shifts_t : uint8_t {
  k_shift_blue = 0 ,
  k_shift_green = 8 ,
  k_shift_red = 16 ,
  k_shift_alpha = 24
}
 Bit positions for unpacking 0xAARRGGBB colour values. More...
enum  ra8_gfx_color_masks_t : uint32_t { k_mask_byte = 0xFFU }
 Per-channel masks for colour conversion. More...
enum  ra8_gfx_565_t : uint8_t {
  k_565_r_shift_in = 3 ,
  k_565_g_shift_in = 2 ,
  k_565_b_shift_in = 3 ,
  k_565_r_shift_out = 11 ,
  k_565_g_shift_out = 5
}
 RGB565 packing constants. More...
enum  ra8_gfx_byte_idx_t : uint8_t {
  k_idx_r = 0 ,
  k_idx_g = 1 ,
  k_idx_b = 2 ,
  k_idx_argb_b = 0 ,
  k_idx_argb_g = 1 ,
  k_idx_argb_r = 2 ,
  k_idx_argb_a = 3
}
 Per-byte indices for RGB888 packing. More...
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_rgb565_bpp_t : uint8_t { k_rgb565_bpp = 2 }
 RGB565 bytes per pixel (used to size span byte counts). More...

Functions

static uint8_t internal_color_r (uint32_t color)
 Extract red byte from a 0xAARRGGBB colour.
static uint8_t internal_color_g (uint32_t color)
 Internal helper.
static uint8_t internal_color_b (uint32_t color)
 Internal helper.
static uint8_t internal_color_a (uint32_t color)
 Internal helper.
uint16_t priv_gfx_text_pack_565 (uint32_t color)
 Implementation of priv_gfx_text_pack_565() – promoted for cross-TU use.
static uint8_t internal_bpp (ra8_gfx_format_t format)
 Bytes per pixel for a given format.
static bool internal_format_ok (ra8_gfx_format_t f)
 Validate a format enum.
static void internal_put_pixel (uint8_t *dst, size_t stride, ra8_gfx_format_t format, size_t x, size_t y, uint32_t color)
 Write one pixel into a generic destination buffer.
static uint32_t internal_get_pixel (const uint8_t *src, size_t stride, ra8_gfx_format_t format, size_t x, size_t y)
 Read one pixel from a source buffer and return it as 0xAARRGGBB.
void priv_gfx_text_plot (int32_t x, int32_t y, uint32_t color)
 Implementation of priv_gfx_text_plot() – promoted for cross-TU use.
static void internal_fill_565 (uint8_t *p, size_t count, uint8_t lo, uint8_t hi)
 Fill count consecutive RGB565 pixels at p with packed bytes lo,hi.
static void internal_fill_rect_565 (int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
 Span-fill an axis-aligned RGB565 rectangle, clipped to the framebuffer.
static void internal_fill_rect (int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
 Fill a solid rectangle (RGB565 span fast path, else per-pixel).
static void internal_rect_outline (int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
 Draw the four edges of a 1-pixel-wide rectangle outline.
ra8_err_t ra8_gfx_init (void *fb, uint16_t width, uint16_t height, ra8_gfx_format_t format)
 Bind ra8_gfx to a caller-owned framebuffer.
ra8_err_t ra8_gfx_clear (uint32_t color)
 Fill the bound framebuffer's clip region with a single colour.
ra8_err_t ra8_gfx_set_clip (int32_t x, int32_t y, int32_t w, int32_t h)
 Restrict all subsequent drawing to a rectangle (dirty-region updates).
ra8_err_t ra8_gfx_reset_clip (void)
 Reset the clip rectangle to the whole framebuffer.
ra8_err_t ra8_gfx_pixel (int32_t x, int32_t y, uint32_t color)
 Set a single pixel.
static uint32_t internal_gray_to_color (uint32_t g)
 Expand an 8-bit gray sample to the 0x00RRGGBB colour word priv_gfx_text_pack_565 expects.
static void internal_blit_gray8_565 (const uint8_t *src, int32_t w, int32_t dst_x, int32_t dst_y, int32_t x0, int32_t y0, int32_t x1, int32_t y1)
 RGB565 fast path for ra8_gfx_blit_gray8(): clip pre-resolved, tight rows.
static void internal_blit_gray8_slow (const uint8_t *src, int32_t w, int32_t h, int32_t dx, int32_t dy)
 Per-pixel fallback for non-RGB565 formats, matching priv_gfx_text_plot() exactly.
ra8_err_t ra8_gfx_blit_gray8 (const uint8_t *src, int32_t w, int32_t h, int32_t dst_x, int32_t dst_y)
 Blit an 8-bit grayscale image to a framebuffer rectangle.
ra8_err_t ra8_gfx_line (int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color)
 Draw a line from (x0,y0) to (x1,y1) with Bresenham's algorithm.
ra8_err_t ra8_gfx_rect (int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color, bool filled)
 Draw an axis-aligned rectangle.
static void internal_circle_outline_step (int32_t cx, int32_t cy, int32_t x, int32_t y, uint32_t color)
 Plot the eight symmetric points of a midpoint-circle step.
static void internal_circle_filled_step (int32_t cx, int32_t cy, int32_t x, int32_t y, uint32_t color)
 Plot the two horizontal scan-lines for a midpoint-circle step.
ra8_err_t ra8_gfx_circle (int32_t cx, int32_t cy, int32_t r, uint32_t color, bool filled)
 Draw a circle using midpoint algorithm.
ra8_err_t ra8_gfx_blit (const void *src_buf, uint16_t src_w, uint16_t src_h, ra8_gfx_format_t src_format, int32_t dst_x, int32_t dst_y)
 Copy a sub-image from src_buf into the framebuffer at (dst_x,dst_y).

Variables

ra8_gfx_state_t g_gfx_text_state = {.format = k_ra8_gfx_format_rgb565}
 Single module-wide framebuffer binding shared by every ra8_gfx TU.

Detailed Description

Software pixel-pusher implementation of ra8_gfx primitives.

Portable C software rasteriser. The framebuffer pointer + format are stored in module-static state by ra8_gfx_init(); each draw entry point dispatches to a per-format pixel writer.

The main shapes (line, rect, circle) clip per pixel, which is fine for the sizes we render (a 7-inch panel is 1024 x 600). When DRW becomes available the rect/blit fast paths will be replaced; the public API does not change.

Since
0.1.0

Definition in file ra8_gfx_text.c.

Enumeration Type Documentation

◆ gfx_565_mask_t

enum gfx_565_mask_t : uint32_t

RGB565 channel masks.

Enumerator
k_565_r_mask 

5-bit red.

k_565_g_mask 

6-bit green.

k_565_b_mask 

5-bit blue.

Definition at line 29 of file ra8_gfx_text.c.

◆ ra8_gfx_565_t

enum ra8_gfx_565_t : uint8_t

RGB565 packing constants.

Enumerator
k_565_r_shift_in 

drop 3 LSBs of R (8 -> 5 bits).

k_565_g_shift_in 

drop 2 LSBs of G (8 -> 6 bits).

k_565_b_shift_in 

drop 3 LSBs of B (8 -> 5 bits).

k_565_r_shift_out 

565 r shift out.

k_565_g_shift_out 

565 g shift out.

Definition at line 58 of file ra8_gfx_text.c.

◆ 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.

k_idx_b 

Index b.

k_idx_argb_b 

Index argb b.

k_idx_argb_g 

Index argb g.

k_idx_argb_r 

Index argb r.

k_idx_argb_a 

Index argb a.

Definition at line 70 of file ra8_gfx_text.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 50 of file ra8_gfx_text.c.

◆ ra8_gfx_color_shifts_t

enum ra8_gfx_color_shifts_t : uint8_t

Bit positions for unpacking 0xAARRGGBB colour values.

Enumerator
k_shift_blue 

Shift blue.

k_shift_green 

Shift green.

k_shift_red 

Shift red.

k_shift_alpha 

Shift alpha.

Definition at line 39 of file ra8_gfx_text.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 84 of file ra8_gfx_text.c.

◆ ra8_gfx_rgb565_bpp_t

enum ra8_gfx_rgb565_bpp_t : uint8_t

RGB565 bytes per pixel (used to size span byte counts).

Enumerator
k_rgb565_bpp 

Rgb565 bpp.

Definition at line 90 of file ra8_gfx_text.c.

Function Documentation

◆ internal_blit_gray8_565()

void internal_blit_gray8_565 ( const uint8_t * src,
int32_t w,
int32_t dst_x,
int32_t dst_y,
int32_t x0,
int32_t y0,
int32_t x1,
int32_t y1 )
static

RGB565 fast path for ra8_gfx_blit_gray8(): clip pre-resolved, tight rows.

Writes the clipped block [x0,x1) x [y0,y1) from a packed gray8 source image directly into the RGB565 framebuffer. For each visible pixel the gray sample is located via the src pointer, w (source row stride), dst_x, and dst_y offset arithmetic, then expanded to 0x00RRGGBB by internal_gray_to_color() before being packed to two RGB565 bytes by priv_gfx_text_pack_565(). The two bytes are written in the same low-byte-first order that internal_put_pixel() uses for k_ra8_gfx_format_rgb565, making the result byte-identical to the per-pixel path while avoiding the per-pixel clip overhead.

Parameters
[in]srcBase pointer of the source gray8 image (one byte per pixel).
[in]wSource image width in pixels (row stride in bytes).
[in]dst_xDestination x offset of the source image top-left in the framebuffer.
[in]dst_yDestination y offset of the source image top-left in the framebuffer.
[in]x0First visible column (inclusive), already clipped by the caller.
[in]y0First visible row (inclusive), already clipped by the caller.
[in]x1One past the last visible column (exclusive), already clipped.
[in]y1One past the last visible row (exclusive), already clipped.
Precondition
The framebuffer format is k_ra8_gfx_format_rgb565 and g_gfx_text_state is initialised.
x0 < x1 and y0 < y1 (non-empty visible region, guaranteed by the caller).
Postcondition
Every framebuffer pixel in [x0,x1) x [y0,y1) holds the RGB565 encoding of its gray sample.
No pixel outside that clipped rectangle is modified.
Note
Not thread-safe; shares g_gfx_text_state with all other rasteriser functions.
Since
0.1.0

Definition at line 699 of file ra8_gfx_text.c.

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

Referenced by ra8_gfx_blit_gray8().

◆ internal_blit_gray8_slow()

void internal_blit_gray8_slow ( const uint8_t * src,
int32_t w,
int32_t h,
int32_t dx,
int32_t dy )
static

Per-pixel fallback for non-RGB565 formats, matching priv_gfx_text_plot() exactly.

Iterates over every pixel in the w x h source gray8 image, expands each sample to 0x00RRGGBB via internal_gray_to_color(), and calls priv_gfx_text_plot() to write the result at framebuffer coordinates (dx+col, dy+row). Because priv_gfx_text_plot() performs per-pixel clipping against the active clip rectangle, no additional bounds checking is needed here. This path is taken for all formats other than k_ra8_gfx_format_rgb565; the RGB565 fast path is internal_blit_gray8_565().

Parameters
[in]srcBase pointer of the source gray8 image (one byte per pixel, row-major).
[in]wSource image width in pixels (also the byte stride per row).
[in]hSource image height in pixels.
[in]dxDestination x offset of the image top-left in the framebuffer.
[in]dyDestination y offset of the image top-left in the framebuffer.
Precondition
src is non-null and addresses at least w*h readable bytes.
w > 0 and h > 0 (guaranteed by ra8_gfx_blit_gray8() before dispatch).
Postcondition
Every on-screen pixel in the destination rectangle holds the colour of its gray sample.
Off-screen pixels are silently dropped by priv_gfx_text_plot() clip checks.
Note
Not thread-safe; shares g_gfx_text_state with all other rasteriser functions.
Since
0.1.0

Definition at line 747 of file ra8_gfx_text.c.

References internal_gray_to_color(), and priv_gfx_text_plot().

Referenced by ra8_gfx_blit_gray8().

◆ internal_bpp()

uint8_t internal_bpp ( ra8_gfx_format_t format)
inlinestatic

Bytes per pixel for a given format.

See implementation.

Parameters
[in]formatSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 210 of file ra8_gfx_text.c.

Referenced by internal_get_pixel(), internal_put_pixel(), ra8_gfx_blit(), and ra8_gfx_init().

◆ internal_circle_filled_step()

void internal_circle_filled_step ( int32_t cx,
int32_t cy,
int32_t x,
int32_t y,
uint32_t color )
static

Plot the two horizontal scan-lines for a midpoint-circle step.

See implementation.

Parameters
[in]cxSee implementation.
[in]cySee implementation.
[in]xSee implementation.
[in]ySee implementation.
[in]colorSee 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 882 of file ra8_gfx_text.c.

References priv_gfx_text_plot().

Referenced by ra8_gfx_circle().

◆ internal_circle_outline_step()

void internal_circle_outline_step ( int32_t cx,
int32_t cy,
int32_t x,
int32_t y,
uint32_t color )
static

Plot the eight symmetric points of a midpoint-circle step.

See implementation.

Parameters
[in]cxSee implementation.
[in]cySee implementation.
[in]xSee implementation.
[in]ySee implementation.
[in]colorSee 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 852 of file ra8_gfx_text.c.

References priv_gfx_text_plot().

Referenced by ra8_gfx_circle().

◆ internal_color_a()

uint8_t internal_color_a ( uint32_t color)
inlinestatic

Internal helper.

See implementation.

Parameters
[in]colorSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 181 of file ra8_gfx_text.c.

References k_mask_byte, and k_shift_alpha.

Referenced by internal_put_pixel().

◆ internal_color_b()

uint8_t internal_color_b ( uint32_t color)
inlinestatic

Internal helper.

See implementation.

Parameters
[in]colorSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 163 of file ra8_gfx_text.c.

References k_mask_byte, and k_shift_blue.

Referenced by internal_put_pixel(), and priv_gfx_text_pack_565().

◆ internal_color_g()

uint8_t internal_color_g ( uint32_t color)
inlinestatic

Internal helper.

See implementation.

Parameters
[in]colorSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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.c.

References k_mask_byte, and k_shift_green.

Referenced by internal_put_pixel(), and priv_gfx_text_pack_565().

◆ internal_color_r()

uint8_t internal_color_r ( uint32_t color)
inlinestatic

Extract red byte from a 0xAARRGGBB colour.

See implementation.

Parameters
[in]colorSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 127 of file ra8_gfx_text.c.

References k_mask_byte, and k_shift_red.

Referenced by internal_put_pixel(), and priv_gfx_text_pack_565().

◆ internal_fill_565()

void internal_fill_565 ( uint8_t * p,
size_t count,
uint8_t lo,
uint8_t hi )
inlinestatic

Fill count consecutive RGB565 pixels at p with packed bytes lo,hi.

One tight inner loop that stores the two pre-packed bytes per pixel, so a span fill pays the colour packing (priv_gfx_text_pack_565 + the per-channel extraction) once for the whole run instead of once per pixel. The byte order (low byte first) is exactly what internal_put_pixel writes for k_ra8_gfx_format_rgb565, so the result is byte-identical to plotting each pixel individually.

Parameters
[out]pDestination of the first pixel (2 bytes per pixel).
[in]countNumber of pixels to write.
[in]loLow byte of the packed RGB565 word.
[in]hiHigh byte of the packed RGB565 word.
Precondition
p is non-null and addresses at least 2*count writable bytes.
The destination format is k_ra8_gfx_format_rgb565.
Postcondition
count pixels starting at p hold the packed colour.
No bytes outside the 2*count-byte run are modified.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 376 of file ra8_gfx_text.c.

References k_rgb565_bpp, and memset().

Referenced by internal_fill_rect_565().

◆ internal_fill_rect()

void internal_fill_rect ( int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t color )
static

Fill a solid rectangle (RGB565 span fast path, else per-pixel).

RGB565 – the panel format – takes the clipped span fill; other formats fall back to the per-pixel priv_gfx_text_plot loop. Both write the same in-bounds pixels.

Parameters
[in]xTop-left corner x.
[in]yTop-left corner y.
[in]wWidth in pixels (> 0, checked by ra8_gfx_rect).
[in]hHeight in pixels (> 0, checked by ra8_gfx_rect).
[in]color32-bit fill colour.
Precondition
The module is initialised (checked by ra8_gfx_rect).
w > 0 and h > 0 (checked by ra8_gfx_rect).
Postcondition
Every on-screen pixel of the rectangle holds the colour.
No off-screen pixel is modified.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 470 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_fill_rect_565(), k_ra8_gfx_format_rgb565, and priv_gfx_text_plot().

Referenced by ra8_gfx_rect().

◆ internal_fill_rect_565()

void internal_fill_rect_565 ( int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t color )
static

Span-fill an axis-aligned RGB565 rectangle, clipped to the framebuffer.

Clips [x,x+w) x [y,y+h) to the framebuffer once, then fills each visible row with internal_fill_565. This writes exactly the pixels priv_gfx_text_plot would (the same in-bounds set) with the same packed bytes, so it is byte-identical to the per-pixel fill while replacing roughly six function calls per pixel (plot -> put_pixel -> pack_565 -> color_r/g/b -> bpp) with one packed store.

Parameters
[in]xTop-left corner x (may be partly or fully off-screen).
[in]yTop-left corner y (may be partly or fully off-screen).
[in]wWidth in pixels (assumed > 0 by the caller).
[in]hHeight in pixels (assumed > 0 by the caller).
[in]color32-bit colour, packed to RGB565 once.
Precondition
The module is initialised and the format is k_ra8_gfx_format_rgb565.
w > 0 and h > 0 (guaranteed by ra8_gfx_rect).
Postcondition
Every on-screen pixel of the rectangle holds the packed colour.
No off-screen or out-of-rectangle pixel is modified.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 415 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_fill_565(), k_glyph_bits_per_byte, k_mask_byte, and priv_gfx_text_pack_565().

Referenced by internal_fill_rect(), and ra8_gfx_clear().

◆ internal_format_ok()

bool internal_format_ok ( ra8_gfx_format_t f)
inlinestatic

Validate a format enum.

See implementation.

Parameters
[in]fSee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 230 of file ra8_gfx_text.c.

References k_ra8_gfx_format_argb8888, k_ra8_gfx_format_rgb565, and k_ra8_gfx_format_rgb888.

Referenced by ra8_gfx_blit(), and ra8_gfx_init().

◆ internal_get_pixel()

uint32_t internal_get_pixel ( const uint8_t * src,
size_t stride,
ra8_gfx_format_t format,
size_t x,
size_t y )
static

Read one pixel from a source buffer and return it as 0xAARRGGBB.

See implementation.

Parameters
[in]srcSee implementation.
[in]strideSee implementation.
[in]formatSee implementation.
[in]xSee implementation.
[in]ySee implementation.
Returns
Result code.
Return values
k_ra8_okOperation succeeded.
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 306 of file ra8_gfx_text.c.

References internal_bpp(), k_565_b_mask, k_565_b_shift_in, k_565_g_mask, k_565_g_shift_in, k_565_g_shift_out, k_565_r_mask, k_565_r_shift_in, k_565_r_shift_out, k_glyph_bits_per_byte, k_idx_argb_a, k_idx_argb_b, k_idx_argb_g, k_idx_argb_r, k_idx_b, k_idx_g, k_idx_r, k_ra8_gfx_format_argb8888, k_ra8_gfx_format_rgb565, k_ra8_gfx_format_rgb888, k_shift_alpha, k_shift_blue, k_shift_green, and k_shift_red.

Referenced by ra8_gfx_blit().

◆ internal_gray_to_color()

uint32_t internal_gray_to_color ( uint32_t g)
inlinestatic

Expand an 8-bit gray sample to the 0x00RRGGBB colour word priv_gfx_text_pack_565 expects.

Replicates the single gray value g into the R, G, and B channels of a packed 0x00RRGGBB word by shifting g to the positions defined by k_shift_red, k_shift_green, and k_shift_blue, then ORing the three contributions together. The alpha channel is left as zero (fully opaque is implied by convention throughout the software rasteriser). The result can be fed directly to priv_gfx_text_pack_565 to produce the equivalent RGB565 pixel.

Parameters
[in]g8-bit gray intensity in the range [0, 255].
Returns
uint32_t Packed 0x00RRGGBB colour with R==G==B==g.
Return values
0x00000000When g is 0 (black).
0x00FFFFFFWhen g is 255 (white).
Precondition
g must fit in 8 bits (values above 255 saturate the low byte only).
The module-level colour shift constants k_shift_red/k_shift_green/k_shift_blue are valid.
Postcondition
The returned word has identical R, G, and B byte values equal to g.
The alpha byte of the returned word is zero.
Note
Not thread-safe; reads only compile-time constants, so concurrent calls are harmless.
Since
0.1.0

Definition at line 664 of file ra8_gfx_text.c.

References k_shift_blue, k_shift_green, and k_shift_red.

Referenced by internal_blit_gray8_565(), and internal_blit_gray8_slow().

◆ internal_put_pixel()

void internal_put_pixel ( uint8_t * dst,
size_t stride,
ra8_gfx_format_t format,
size_t x,
size_t y,
uint32_t color )
static

Write one pixel into a generic destination buffer.

Parameters
[out]dstDestination buffer base.
[in]strideBytes per row in destination.
[in]formatDestination pixel format.
[in]x,yPixel coordinates within the destination.
[in]color32-bit colour.

See implementation.

Parameters
[in]ySee 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 255 of file ra8_gfx_text.c.

References internal_bpp(), internal_color_a(), internal_color_b(), internal_color_g(), internal_color_r(), k_glyph_bits_per_byte, k_idx_argb_a, k_idx_argb_b, k_idx_argb_g, k_idx_argb_r, k_idx_b, k_idx_g, k_idx_r, k_mask_byte, k_ra8_gfx_format_argb8888, k_ra8_gfx_format_rgb565, k_ra8_gfx_format_rgb888, and priv_gfx_text_pack_565().

Referenced by priv_gfx_text_plot(), and ra8_gfx_clear().

◆ internal_rect_outline()

void internal_rect_outline ( int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t color )
static

Draw the four edges of a 1-pixel-wide rectangle outline.

Plots the top row (y), bottom row (y+h-1), left column (x), and right column (x+w-1) by iterating over all column and row positions in two separate loops. interior pixels are never touched. Each pixel is routed through priv_gfx_text_plot, which applies the active clip rectangle before writing to the framebuffer, so partial off-screen outlines are rendered correctly without additional guards here.

Parameters
[in]xTop-left corner x.
[in]yTop-left corner y.
[in]wWidth in pixels (> 0, checked by ra8_gfx_rect).
[in]hHeight in pixels (> 0, checked by ra8_gfx_rect).
[in]color32-bit edge colour.
Precondition
The module is initialised (checked by ra8_gfx_rect).
w > 0 and h > 0 (checked by ra8_gfx_rect).
Postcondition
The four edge runs hold the colour; the interior is untouched.
priv_gfx_text_plot clips every pixel to the framebuffer.
Note
Not thread-safe unless documented otherwise.
Since
0.1.0

Definition at line 506 of file ra8_gfx_text.c.

References priv_gfx_text_plot().

Referenced by ra8_gfx_rect().

◆ priv_gfx_text_pack_565()

uint16_t priv_gfx_text_pack_565 ( uint32_t color)

Implementation of priv_gfx_text_pack_565() – promoted for cross-TU use.

Pack a 32-bit colour into a single RGB565 word.

Definition at line 187 of file ra8_gfx_text.c.

References internal_color_b(), internal_color_g(), internal_color_r(), k_565_b_shift_in, k_565_g_shift_in, k_565_g_shift_out, k_565_r_shift_in, and k_565_r_shift_out.

Referenced by internal_blit_glyph_565(), internal_blit_gray8_565(), internal_fill_rect_565(), and internal_put_pixel().

◆ priv_gfx_text_plot()

void priv_gfx_text_plot ( int32_t x,
int32_t y,
uint32_t color )

◆ ra8_gfx_blit()

ra8_err_t ra8_gfx_blit ( const void * src_buf,
uint16_t src_w,
uint16_t src_h,
ra8_gfx_format_t src_format,
int32_t dst_x,
int32_t dst_y )
nodiscard

Copy a sub-image from src_buf into the framebuffer at (dst_x,dst_y).

Parameters
[in]src_bufSource image bytes.
[in]src_w,src_hSource size.
[in]src_formatPixel format of the source image.
[in]dst_x,dst_yDestination top-left in the framebuffer.
Returns
Error code.
Return values
k_ra8_okBlitted (clipped if needed).
k_ra8_err_null_ptrsrc_buf was NULL.
k_ra8_err_not_initializedra8_gfx_init() was not called.
k_ra8_err_invalid_argsrc_w or src_h was zero or src_format invalid.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Destination rectangle (clipped to FB) holds the converted pixels.
Since
0.1.0

Definition at line 928 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_bpp(), internal_format_ok(), internal_get_pixel(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_ok, and priv_gfx_text_plot().

Referenced by ls_blit().

◆ ra8_gfx_blit_gray8()

ra8_err_t ra8_gfx_blit_gray8 ( const uint8_t * src,
int32_t w,
int32_t h,
int32_t dst_x,
int32_t dst_y )
nodiscard

Blit an 8-bit grayscale image to a framebuffer rectangle.

Writes the w x h block of 8-bit gray samples at src into the bound framebuffer with its top-left at (dst_x, dst_y), expanding each sample g to the colour (g<<16)|(g<<8)|g and down-converting to the panel format. The clip rectangle and framebuffer bounds are resolved ONCE for the whole block (not per pixel), so a full image is a tight row loop – the same pixels a per-pixel ra8_gfx_pixel() loop would write, far fewer instructions. Rows are sampled left-to-right, top-to-bottom; src is row-major with stride w.

Parameters
[in]srcRow-major 8-bit gray buffer of at least w * h bytes.
[in]wSource width in pixels (> 0).
[in]hSource height in pixels (> 0).
[in]dst_xDestination column of the block's left edge.
[in]dst_yDestination row of the block's top edge.
Returns
Error code.
Return values
k_ra8_okVisible pixels written (or fully clipped out).
k_ra8_err_not_initializedra8_gfx_init() was not called.
k_ra8_err_invalid_argsrc is NULL, or w / h <= 0.
Precondition
ra8_gfx_init() returned k_ra8_ok.
src holds at least w * h bytes.
Postcondition
Each in-clip destination pixel equals its down-converted gray sample.
Pixels outside the clip rectangle are left unchanged.
Note
Not thread-safe; shares the single ra8_gfx bind state.
Since
0.1.0

Definition at line 758 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_blit_gray8_565(), internal_blit_gray8_slow(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_gfx_format_rgb565, and k_ra8_ok.

Referenced by erb_render_image(), sh_image_blit_cover(), and sh_image_blit_gray8().

◆ ra8_gfx_circle()

ra8_err_t ra8_gfx_circle ( int32_t cx,
int32_t cy,
int32_t r,
uint32_t color,
bool filled )
nodiscard

Draw a circle using midpoint algorithm.

Parameters
[in]cx,cyCentre.
[in]rRadius in pixels (>= 0).
[in]color32-bit colour.
[in]filledtrue for solid disc, false for 1-pixel outline.
Returns
Error code.
Return values
k_ra8_okDrawn.
k_ra8_err_not_initializedra8_gfx_init() was not called.
k_ra8_err_invalid_argr < 0.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Pixels on / inside the circle within bounds are updated.
Since
0.1.0

Definition at line 894 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_circle_filled_step(), internal_circle_outline_step(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_gfx_max_dim, and k_ra8_ok.

Referenced by er_round_rect(), and priv_ra8_svgp_draw_circle().

◆ ra8_gfx_clear()

ra8_err_t ra8_gfx_clear ( uint32_t color)
nodiscard

Fill the bound framebuffer's clip region with a single colour.

Parameters
[in]color32-bit colour in 0x00RRGGBB or 0xAARRGGBB form.
Returns
Error code.
Return values
k_ra8_okCleared.
k_ra8_err_not_initializedra8_gfx_init() was not called.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Every pixel of the active clip region equals color (down-converted as needed to the active pixel format). With the default (full-framebuffer) clip this is the whole framebuffer.
Note
Honours the clip rectangle set by ra8_gfx_set_clip(); the default clip is the whole framebuffer, so unclipped callers see no change.
See also
ra8_gfx_set_clip
Since
0.1.0

Definition at line 549 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_fill_rect_565(), internal_put_pixel(), k_ra8_err_not_initialized, k_ra8_gfx_format_rgb565, and k_ra8_ok.

Referenced by ch_render(), cm_render(), ef_decode_and_hash(), er_render_keyboard(), er_render_library(), er_render_reading(), erb_render_all(), erb_render_image(), internal_decode(), internal_rc_render_all(), ls_redraw(), main(), mg_reader_render(), render_page(), sfr_bringup_panel(), sfr_panic_halt(), sh_comic_probe_blob(), sh_comic_render(), sh_cover_render(), sh_epub_thumb(), sh_loading_overlay(), sh_reader_render(), sh_shelf_render(), sh_toc_render(), wa_app_render(), wd_app_render(), and wk_check_full().

◆ ra8_gfx_init()

ra8_err_t ra8_gfx_init ( void * fb,
uint16_t width,
uint16_t height,
ra8_gfx_format_t format )
nodiscard

Bind ra8_gfx to a caller-owned framebuffer.

Parameters
[in]fbPointer to framebuffer memory.
[in]widthFramebuffer width in pixels.
[in]heightFramebuffer height in pixels.
[in]formatPixel format (see ra8_gfx_format_t).
Returns
Error code.
Return values
k_ra8_okBound successfully.
k_ra8_err_null_ptrfb was NULL.
k_ra8_err_invalid_argDimensions out of range or unsupported format.
Precondition
fb points to at least width * height * bytes_per_pixel(format) bytes.
width, height in [1, 4096].
Postcondition
Subsequent draw calls operate on the bound buffer.
On error, no global state is changed.
Note
Not thread-safe; bind once during init.
Since
0.1.0

Definition at line 522 of file ra8_gfx_text.c.

References g_gfx_text_state, internal_bpp(), internal_format_ok(), k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_gfx_max_dim, k_ra8_gfx_min_dim, and k_ra8_ok.

Referenced by app_bringup_gfx(), cm_bringup_panel(), ez_bringup_panel(), main(), mg_bringup_panel(), priv_viewer_render_comic(), priv_viewer_tile_comic(), render_page(), sfr_bringup_panel(), sh_comic_probe_blob(), sh_comic_selfcheck(), sh_epub_thumb(), sh_panel_or_halt(), wc_panel_up(), wd_panel_up(), and wk_panel_up().

◆ ra8_gfx_line()

ra8_err_t ra8_gfx_line ( int32_t x0,
int32_t y0,
int32_t x1,
int32_t y1,
uint32_t color )
nodiscard

Draw a line from (x0,y0) to (x1,y1) with Bresenham's algorithm.

Parameters
[in]x0,y0,x1,y1Endpoints (clipped to framebuffer).
[in]color32-bit colour.
Returns
Error code.
Return values
k_ra8_okLine drawn (after clipping).
k_ra8_err_not_initializedra8_gfx_init() was not called.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Pixels on the rasterised line within bounds equal color.
Since
0.1.0

Definition at line 785 of file ra8_gfx_text.c.

References g_gfx_text_state, k_ra8_err_not_initialized, k_ra8_gfx_max_dim, k_ra8_ok, and priv_gfx_text_plot().

Referenced by ch_border(), ch_fill(), er_icon_delete(), er_icon_return(), er_tri_up(), priv_ra8_svgp_draw_line(), priv_ra8_svgp_draw_polyline(), and priv_ra8_svgp_fill_poly().

◆ ra8_gfx_pixel()

ra8_err_t ra8_gfx_pixel ( int32_t x,
int32_t y,
uint32_t color )
nodiscard

Set a single pixel.

Parameters
[in]xColumn, 0 = left.
[in]yRow, 0 = top.
[in]color32-bit colour.
Returns
Error code.
Return values
k_ra8_okPixel written.
k_ra8_err_not_initializedra8_gfx_init() was not called.
k_ra8_err_range_check_failed(x,y) outside framebuffer.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
On success the addressed pixel equals the down-converted colour.
Since
0.1.0

Definition at line 628 of file ra8_gfx_text.c.

References g_gfx_text_state, k_ra8_err_not_initialized, k_ra8_err_range_check_failed, k_ra8_ok, and priv_gfx_text_plot().

Referenced by internal_blit_alpha_mask(), internal_blit_scaled(), internal_draw_underline(), and priv_ra8_svgp_fill_poly_grad().

◆ ra8_gfx_rect()

ra8_err_t ra8_gfx_rect ( int32_t x,
int32_t y,
int32_t w,
int32_t h,
uint32_t color,
bool filled )
nodiscard

◆ ra8_gfx_reset_clip()

ra8_err_t ra8_gfx_reset_clip ( void )
nodiscard

Reset the clip rectangle to the whole framebuffer.

Returns
Error code.
Return values
k_ra8_okClip reset to the full framebuffer.
k_ra8_err_not_initializedra8_gfx_init() was not called.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Subsequent draws may touch any framebuffer pixel.
Note
Not thread-safe; the clip is module-global state.
See also
ra8_gfx_set_clip
Since
0.1.0

Definition at line 616 of file ra8_gfx_text.c.

References g_gfx_text_state, k_ra8_err_not_initialized, and k_ra8_ok.

Referenced by er_render_nag_region(), ls_redraw(), and sh_image_loupe().

◆ ra8_gfx_set_clip()

ra8_err_t ra8_gfx_set_clip ( int32_t x,
int32_t y,
int32_t w,
int32_t h )
nodiscard

Restrict all subsequent drawing to a rectangle (dirty-region updates).

Every draw call (clear, rect, line, pixel, text, blit) writes only pixels inside the intersection of this rectangle and the framebuffer; pixels outside are left untouched. This is the primitive for incremental / dirty-region repaints – set the clip to the damaged area, redraw, then ra8_gfx_reset_clip() – so a small change (e.g. an overlay banner) does not repaint the whole panel. The clip persists until changed or reset; ra8_gfx_init() and ra8_gfx_reset_clip() set it to the full framebuffer.

Parameters
[in]xClip left in pixels (clamped to the framebuffer).
[in]yClip top in pixels (clamped to the framebuffer).
[in]wClip width in pixels (a non-positive width yields an empty clip).
[in]hClip height in pixels (a non-positive height yields an empty clip).
Returns
Error code.
Return values
k_ra8_okClip set (possibly empty).
k_ra8_err_not_initializedra8_gfx_init() was not called.
Precondition
ra8_gfx_init() returned k_ra8_ok.
Postcondition
Subsequent draws are confined to the clamped rectangle.
An off-screen or zero-area request leaves an empty clip (draws are no-ops).
Note
Not thread-safe; the clip is module-global state.
See also
ra8_gfx_reset_clip
Since
0.1.0

Definition at line 580 of file ra8_gfx_text.c.

References g_gfx_text_state, k_ra8_err_not_initialized, and k_ra8_ok.

Referenced by er_render_nag_region(), and sh_image_loupe().

Variable Documentation

◆ g_gfx_text_state

ra8_gfx_state_t g_gfx_text_state = {.format = k_ra8_gfx_format_rgb565}

Single module-wide framebuffer binding shared by every ra8_gfx TU.

Module-wide framebuffer binding (single shared object; see ra8_gfx_internal.h).

Defined once in ra8_gfx_text.c (populated by ra8_gfx_init()); the text/glyph TU reads it through this extern declaration. There is exactly one object so all draw entry points observe the same framebuffer, format, and clip rectangle.

Note
Not thread-safe; mutated only by ra8_gfx_init()/ra8_gfx_set_clip().
Warning
Do not redefine; this is a single shared object, not per-TU state.
Since
0.1.0

The one definition of the shared rasteriser state. Other ra8_gfx TUs read it through the extern declaration in ra8_gfx_internal.h.

Note
Not thread-safe; mutated only by ra8_gfx_init()/ra8_gfx_set_clip().
Warning
Do not redefine; this is the single shared object for all ra8_gfx TUs.
Since
0.1.0

Definition at line 106 of file ra8_gfx_text.c.

Referenced by internal_blit_glyph_565(), internal_blit_gray8_565(), internal_fill_rect(), internal_fill_rect_565(), internal_render_glyph(), priv_gfx_text_plot(), ra8_gfx_blit(), ra8_gfx_blit_gray4_zoom(), ra8_gfx_blit_gray8(), ra8_gfx_blit_gray8_dither(), ra8_gfx_circle(), ra8_gfx_clear(), ra8_gfx_init(), ra8_gfx_line(), ra8_gfx_pixel(), ra8_gfx_rect(), ra8_gfx_reset_clip(), ra8_gfx_set_clip(), and ra8_gfx_text_out().