ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_gfx_blit_gray4.c
Go to the documentation of this file.
1
22
23#include <stddef.h>
24#include <stdint.h>
25
26#include "ra8_gfx.h"
27#include "ra8_gfx_internal.h"
28
40
64static uint32_t internal_gray4_color(const uint8_t* src, int32_t src_w, int32_t x, int32_t y)
65{
66 const size_t flat = ((size_t)y * (size_t)src_w) + (size_t)x;
67 const uint8_t byte = src[flat >> 1U];
68 const uint8_t nib =
69 ((flat & 1U) != 0U) ? (uint8_t)(byte & k_ra8_g4_nib_lo) : (uint8_t)(byte >> k_ra8_g4_nib_sh);
70 const uint8_t g8 = (uint8_t)((nib << k_ra8_g4_nib_sh) | nib);
71 return ((uint32_t)g8 << k_ra8_g4_rgb_r_sh) | ((uint32_t)g8 << k_ra8_g4_rgb_g_sh) | (uint32_t)g8;
72}
73
95static void internal_gray4_block(int32_t bx, int32_t by, int32_t zoom, uint32_t color)
96{
97 for (int32_t dy = 0; dy < zoom; ++dy) {
98 for (int32_t dx = 0; dx < zoom; ++dx) {
99 priv_gfx_text_plot(bx + dx, by + dy, color);
100 }
101 }
102}
103
105 int32_t src_w,
106 int32_t src_h,
107 int32_t sx,
108 int32_t sy,
109 int32_t sw,
110 int32_t sh,
111 int32_t zoom,
112 int32_t dst_x,
113 int32_t dst_y)
114{
115 if (!g_gfx_text_state.initialized) {
117 }
118 if (src == nullptr) {
120 }
121 if (zoom <= 0) {
123 }
124 if ((src_w <= 0) || (src_h <= 0)) {
126 }
127 /* Clamp the sampled window to the source image bounds; an off-image edge draws
128 * only the in-image portion at its natural (dst + offset*zoom) position. A
129 * non-positive sw/sh collapses the range, so nothing is drawn. */
130 const int32_t x_lo = (sx > 0) ? sx : 0;
131 const int32_t y_lo = (sy > 0) ? sy : 0;
132 const int32_t x_hi = ((sx + sw) < src_w) ? (sx + sw) : src_w;
133 const int32_t y_hi = ((sy + sh) < src_h) ? (sy + sh) : src_h;
134 for (int32_t py = y_lo; py < y_hi; ++py) {
135 const int32_t by = dst_y + ((py - sy) * zoom);
136 for (int32_t px = x_lo; px < x_hi; ++px) {
137 internal_gray4_block(dst_x + ((px - sx) * zoom),
138 by,
139 zoom,
140 internal_gray4_color(src, src_w, px, py));
141 }
142 }
143 return k_ra8_ok;
144}
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC r...
static void internal_gray4_block(int32_t bx, int32_t by, int32_t zoom, uint32_t color)
Fill the zoom x zoom framebuffer block at (bx, by) with color.
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 fra...
static uint32_t internal_gray4_color(const uint8_t *src, int32_t src_w, int32_t x, int32_t y)
Expand the packed gray4 pixel at (x, y) to a 0x00RRGGBB gray colour.
ra8_gfx_g4_const_t
Nibble-unpack + gray-to-colour expansion constants for the gray4 blit.
@ k_ra8_g4_rgb_r_sh
Red shift of the 0x00RRGGBB gray expand.
@ k_ra8_g4_rgb_g_sh
Green shift of the 0x00RRGGBB gray expand.
@ k_ra8_g4_nib_sh
Nibble shift (and the 4->8-bit replicate).
@ k_ra8_g4_nib_lo
Low-nibble mask.
Module-private declarations shared across the ra8_gfx software rasteriser TUs.
ra8_gfx_state_t g_gfx_text_state
Single module-wide framebuffer binding shared by every ra8_gfx TU.
void priv_gfx_text_plot(int32_t x, int32_t y, uint32_t color)
Plot a single pixel with bounds checking against the active clip.