|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC ready). More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_gfx_format_t : uint8_t { k_ra8_gfx_format_rgb565 = 2 , k_ra8_gfx_format_rgb888 = 3 , k_ra8_gfx_format_argb8888 = 4 } |
| Pixel format of the framebuffer bound by ra8_gfx_init(). More... | |
| enum | ra8_gfx_dim_limits_t : uint16_t { k_ra8_gfx_min_dim = 1 , k_ra8_gfx_max_dim = 4096 } |
| Bounds on framebuffer dimensions accepted by ra8_gfx_init(). More... | |
Functions | |
| 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. | |
| 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_blit_gray4_zoom (const uint8_t *src, int32_t src_w, int32_t src_h, int32_t sx, int32_t sy, int32_t sw, int32_t sh, int32_t zoom, int32_t dst_x, int32_t dst_y) |
| Nearest-neighbour integer-zoom blit of a sub-rectangle of a packed 4-bit grayscale image into the framebuffer (no scale-to-fit). | |
| 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. | |
| 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_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. | |
| 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). | |
Software 2D graphics primitives layered on top of a caller-owned
framebuffer (DRW / D/AVE 2D / GLCDC ready).
This module is a small, dependency-free 2D graphics library aimed at the RA8D2's GLCDC + DRW (D/AVE 2D) accelerator. The current implementation is a portable C software pixel pusher; if RA8_GFX_USE_DRW is defined a future revision can route ra8_gfx_rect / ra8_gfx_blit through ra8_drw's hardware blitter without changing call sites.
The framebuffer memory itself is owned by the caller – ra8_gfx_init only remembers a pointer and metadata, so the same library can be used over the GLCDC display plane, an off-screen scratch buffer, or a host-side test buffer.
Definition in file ra8_gfx.h.
| enum ra8_gfx_dim_limits_t : uint16_t |
Bounds on framebuffer dimensions accepted by ra8_gfx_init().
| Enumerator | |
|---|---|
| k_ra8_gfx_min_dim | Minimum width or height in pixels. |
| k_ra8_gfx_max_dim | Maximum supported edge length. |
| enum ra8_gfx_format_t : uint8_t |
Pixel format of the framebuffer bound by ra8_gfx_init().
Values double as the bytes-per-pixel - the low byte is the byte stride for one pixel; the high byte is just a unique tag.
| Enumerator | |
|---|---|
| k_ra8_gfx_format_rgb565 | 16-bit RGB565, little-endian in memory. |
| k_ra8_gfx_format_rgb888 | 24-bit packed R,G,B bytes. |
| k_ra8_gfx_format_argb8888 | 32-bit ARGB, A in MSB. |
|
nodiscard |
Copy a sub-image from src_buf into the framebuffer at (dst_x,dst_y).
| [in] | src_buf | Source image bytes. |
| [in] | src_w,src_h | Source size. |
| [in] | src_format | Pixel format of the source image. |
| [in] | dst_x,dst_y | Destination top-left in the framebuffer. |
| k_ra8_ok | Blitted (clipped if needed). |
| k_ra8_err_null_ptr | src_buf was NULL. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
| k_ra8_err_invalid_arg | src_w or src_h was zero or src_format invalid. |
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().
|
nodiscard |
Nearest-neighbour integer-zoom blit of a sub-rectangle of a packed 4-bit grayscale image into the framebuffer (no scale-to-fit).
Samples the source sub-rectangle [sx, sx + sw) x [sy, sy + sh) of a packed gray4 image and writes every sampled source pixel as a zoom x zoom nearest-neighbour block, so the destination spans sw * zoom by sh * zoom pixels (before clipping). Unlike ra8_gfx_blit() or the reflow engine's scale-to-fit path, no source pixels are decimated – this is the 1:1 (zoom == 1) or magnified (zoom >= 2) view a reader loupe uses to inspect a full-resolution page window without resolution loss.
The source is packed two pixels per byte at flat nibble index y * src_w + x: an even flat index occupies the high nibble, an odd flat index the low nibble. Each 4-bit sample n is expanded to the 8-bit gray (n << 4) | n, then to (g << 16) | (g << 8) | g before down-conversion to the bound pixel format – byte-identical to ra8_gfx_blit_gray8()'s expansion of the same gray level.
The sampled window is clamped to the source image bounds [0, src_w) x [0, src_h): a sub-rectangle that runs off an image edge draws only the in-image portion at its natural destination offset (the off-image remainder is left untouched). Destination pixels are additionally confined to the active clip rectangle, so a lens window near a panel edge is clipped, never wrapped.
| [in] | src | Packed gray4 source image, >= (src_w * src_h + 1) / 2 bytes. |
| [in] | src_w | Source image width in pixels (> 0); also the nibble stride. |
| [in] | src_h | Source image height in pixels (> 0). |
| [in] | sx | Sub-rectangle left in source pixels (may be negative). |
| [in] | sy | Sub-rectangle top in source pixels (may be negative). |
| [in] | sw | Sub-rectangle width in source pixels (<= 0 draws nothing). |
| [in] | sh | Sub-rectangle height in source pixels (<= 0 draws nothing). |
| [in] | zoom | Integer magnification factor (>= 1; <= 0 rejected). |
| [in] | dst_x | Destination column of the sub-rectangle's top-left. |
| [in] | dst_y | Destination row of the sub-rectangle's top-left. |
| k_ra8_ok | Visible pixels written (or fully clipped out). |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
| k_ra8_err_invalid_arg | src is NULL, src_w / src_h <= 0, or zoom <= 0. |
src holds at least (src_w * src_h + 1) / 2 readable bytes. Definition at line 104 of file ra8_gfx_blit_gray4.c.
References g_gfx_text_state, internal_gray4_block(), internal_gray4_color(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, and k_ra8_ok.
Referenced by internal_emit_strip(), and sh_image_loupe().
|
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.
| [in] | src | Row-major 8-bit gray buffer of at least w * h bytes. |
| [in] | w | Source width in pixels (> 0). |
| [in] | h | Source height in pixels (> 0). |
| [in] | dst_x | Destination column of the block's left edge. |
| [in] | dst_y | Destination row of the block's top edge. |
| k_ra8_ok | Visible pixels written (or fully clipped out). |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
| k_ra8_err_invalid_arg | src is NULL, or w / h <= 0. |
src holds at least w * h bytes. 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().
|
nodiscard |
Draw a circle using midpoint algorithm.
| [in] | cx,cy | Centre. |
| [in] | r | Radius in pixels (>= 0). |
| [in] | color | 32-bit colour. |
| [in] | filled | true for solid disc, false for 1-pixel outline. |
| k_ra8_ok | Drawn. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
| k_ra8_err_invalid_arg | r < 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().
|
nodiscard |
Fill the bound framebuffer's clip region with a single colour.
| [in] | color | 32-bit colour in 0x00RRGGBB or 0xAARRGGBB form. |
| k_ra8_ok | Cleared. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
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().
|
nodiscard |
Bind ra8_gfx to a caller-owned framebuffer.
| [in] | fb | Pointer to framebuffer memory. |
| [in] | width | Framebuffer width in pixels. |
| [in] | height | Framebuffer height in pixels. |
| [in] | format | Pixel format (see ra8_gfx_format_t). |
| k_ra8_ok | Bound successfully. |
| k_ra8_err_null_ptr | fb was NULL. |
| k_ra8_err_invalid_arg | Dimensions out of range or unsupported format. |
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().
|
nodiscard |
Draw a line from (x0,y0) to (x1,y1) with Bresenham's algorithm.
| [in] | x0,y0,x1,y1 | Endpoints (clipped to framebuffer). |
| [in] | color | 32-bit colour. |
| k_ra8_ok | Line drawn (after clipping). |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
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().
|
nodiscard |
Set a single pixel.
| [in] | x | Column, 0 = left. |
| [in] | y | Row, 0 = top. |
| [in] | color | 32-bit colour. |
| k_ra8_ok | Pixel written. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
| k_ra8_err_range_check_failed | (x,y) outside framebuffer. |
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().
|
nodiscard |
Draw an axis-aligned rectangle.
| [in] | x,y | Top-left corner. |
| [in] | w,h | Width and height in pixels. |
| [in] | color | 32-bit colour. |
| [in] | filled | true for solid fill, false for 1-pixel outline. |
| k_ra8_ok | Drawn. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
Definition at line 818 of file ra8_gfx_text.c.
References g_gfx_text_state, internal_fill_rect(), internal_rect_outline(), k_ra8_err_not_initialized, and k_ra8_ok.
Referenced by cm_draw_progress_bar(), cm_draw_status_bar(), er_icon_shift(), er_kbd_keys_render(), er_lib_body_render(), er_lib_sb_render(), er_nag_render(), er_read_footer_render(), er_read_sb_render(), er_render_boxnodes(), er_round_rect(), ez_draw_lens_chrome(), ez_draw_status(), ls_draw_rail(), ls_draw_status(), mg_render_minimap(), mg_render_status(), priv_ra8_svgp_draw_rect(), sh_border(), sh_cover_button(), sh_draw_card(), sh_titlebar(), sh_toc_render(), wa_fill_render(), wc_footer_render(), wc_status_render(), wc_tile_render(), wd_content_render(), wd_fill(), wd_status_render(), wd_tabbar_render(), and wk_paint_fill().
|
nodiscard |
Reset the clip rectangle to the whole framebuffer.
| k_ra8_ok | Clip reset to the full framebuffer. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
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().
|
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.
| [in] | x | Clip left in pixels (clamped to the framebuffer). |
| [in] | y | Clip top in pixels (clamped to the framebuffer). |
| [in] | w | Clip width in pixels (a non-positive width yields an empty clip). |
| [in] | h | Clip height in pixels (a non-positive height yields an empty clip). |
| k_ra8_ok | Clip set (possibly empty). |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
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().
|
nodiscard |
Render a NUL-terminated ASCII string.
| [in] | x,y | Top-left of the first glyph. |
| [in] | str | NUL-terminated ASCII string (NULL not allowed). |
| [in] | font | Font descriptor (NULL not allowed). |
| [in] | fg_color | Foreground colour. |
| [in] | bg_color | Background colour. |
| k_ra8_ok | Rendered. |
| k_ra8_err_null_ptr | str or font was NULL. |
| k_ra8_err_not_initialized | ra8_gfx_init() was not called. |
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().
|
nodiscard |
Compute rendered pixel dimensions of a string.
| [in] | str | ASCII string. |
| [in] | font | Font descriptor. |
| [out] | out_w | Receives total pixel width. |
| [out] | out_h | Receives total pixel height (font glyph height). |
| k_ra8_ok | Measured. |
| k_ra8_err_null_ptr | Any argument was NULL. |
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().