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

Sub-rectangle nearest-neighbour integer-zoom blit for packed gray4 images. More...

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

Go to the source code of this file.

Enumerations

enum  ra8_gfx_g4_const_t : uint32_t {
  k_ra8_g4_nib_lo = 0x0FU ,
  k_ra8_g4_nib_sh = 4U ,
  k_ra8_g4_rgb_g_sh = 8U ,
  k_ra8_g4_rgb_r_sh = 16U
}
 Nibble-unpack + gray-to-colour expansion constants for the gray4 blit. More...

Functions

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.
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 framebuffer (no scale-to-fit).

Detailed Description

Sub-rectangle nearest-neighbour integer-zoom blit for packed gray4 images.

Implements ra8_gfx_blit_gray4_zoom(): the one primitive the reader loupe (#211) needs that the scale-to-fit blitters deliberately lack – a source-rect -> dest-rect copy that magnifies (or reproduces 1:1) without decimating source pixels. It shares the single ra8_gfx framebuffer binding and the clipped per-pixel plotter (priv_gfx_text_plot) with the rest of the rasteriser, so a lens window is clipped to the active clip rectangle exactly like every other draw.

The source pixel format is the reader's native 4-bit grayscale: two pixels per byte at flat nibble index y * src_w + x, even index in the high nibble, odd index in the low nibble – the same packing ra8_gfx_blit_gray8() consumers unpack a row at a time out of the demand-paged image pool.

Since
0.1.0

Definition in file ra8_gfx_blit_gray4.c.

Enumeration Type Documentation

◆ ra8_gfx_g4_const_t

enum ra8_gfx_g4_const_t : uint32_t

Nibble-unpack + gray-to-colour expansion constants for the gray4 blit.

Since
0.1.0
Enumerator
k_ra8_g4_nib_lo 

Low-nibble mask.

k_ra8_g4_nib_sh 

Nibble shift (and the 4->8-bit replicate).

k_ra8_g4_rgb_g_sh 

Green shift of the 0x00RRGGBB gray expand.

k_ra8_g4_rgb_r_sh 

Red shift of the 0x00RRGGBB gray expand.

Definition at line 34 of file ra8_gfx_blit_gray4.c.

Function Documentation

◆ internal_gray4_block()

void internal_gray4_block ( int32_t bx,
int32_t by,
int32_t zoom,
uint32_t color )
static

Fill the zoom x zoom framebuffer block at (bx, by) with color.

Writes one magnified source pixel: a solid zoom-square block whose top-left is (bx, by). Each destination pixel is plotted through priv_gfx_text_plot(), which clips against the active clip rectangle, so a block straddling a clip edge writes only its visible pixels.

Parameters
[in]bxBlock left edge in framebuffer pixels.
[in]byBlock top edge in framebuffer pixels.
[in]zoomBlock edge length in pixels; caller-guaranteed >= 1.
[in]color0x00RRGGBB colour to write to every pixel of the block.
Returns
Nothing.
Precondition
g_gfx_text_state is initialised (caller checked).
zoom >= 1 so the block is non-empty.
Postcondition
Every in-clip pixel of the block equals the down-converted color.
Pixels outside the clip rectangle are left unchanged.
Note
Not thread-safe; shares g_gfx_text_state with all rasteriser functions.
Since
0.1.0

Definition at line 95 of file ra8_gfx_blit_gray4.c.

References priv_gfx_text_plot().

Referenced by ra8_gfx_blit_gray4_zoom().

◆ internal_gray4_color()

uint32_t internal_gray4_color ( const uint8_t * src,
int32_t src_w,
int32_t x,
int32_t y )
static

Expand the packed gray4 pixel at (x, y) to a 0x00RRGGBB gray colour.

Reads the byte holding flat nibble index y * src_w + x, selects the high nibble for an even index and the low nibble for an odd one, replicates the 4-bit level into 8 bits, then broadcasts it across R, G and B – the identical gray level ra8_gfx_blit_gray8() would produce for the same nibble.

Parameters
[in]srcPacked gray4 base pointer (two pixels per byte).
[in]src_wSource width in pixels (nibble stride); caller-guaranteed > 0.
[in]xSource column, caller-clamped to [0, src_w).
[in]ySource row, caller-clamped to [0, src_h).
Returns
0x00RRGGBB gray colour with R == G == B.
Return values
0x00000000The sampled nibble is 0 (black).
0x00FFFFFFThe sampled nibble is 0xF (white).
Precondition
src addresses at least (y * src_w + x) / 2 + 1 readable bytes.
x and y are already clamped to the image bounds by the caller.
Postcondition
No memory is modified (read-only traversal).
The returned colour has equal R, G and B channels.
Note
Not thread-safe only in that it reads the caller's buffer; no shared state.
Since
0.1.0

Definition at line 64 of file ra8_gfx_blit_gray4.c.

References k_ra8_g4_nib_lo, k_ra8_g4_nib_sh, k_ra8_g4_rgb_g_sh, and k_ra8_g4_rgb_r_sh.

Referenced by ra8_gfx_blit_gray4_zoom().

◆ ra8_gfx_blit_gray4_zoom()

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

Parameters
[in]srcPacked gray4 source image, >= (src_w * src_h + 1) / 2 bytes.
[in]src_wSource image width in pixels (> 0); also the nibble stride.
[in]src_hSource image height in pixels (> 0).
[in]sxSub-rectangle left in source pixels (may be negative).
[in]sySub-rectangle top in source pixels (may be negative).
[in]swSub-rectangle width in source pixels (<= 0 draws nothing).
[in]shSub-rectangle height in source pixels (<= 0 draws nothing).
[in]zoomInteger magnification factor (>= 1; <= 0 rejected).
[in]dst_xDestination column of the sub-rectangle's top-left.
[in]dst_yDestination row of the sub-rectangle's top-left.
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, src_w / src_h <= 0, or zoom <= 0.
Precondition
ra8_gfx_init() returned k_ra8_ok.
src holds at least (src_w * src_h + 1) / 2 readable bytes.
Postcondition
Each in-clip, in-image destination pixel equals its zoomed gray sample.
Pixels outside the clip rectangle or off the source image are unchanged.
Note
Not thread-safe; shares the single ra8_gfx bind state.
See also
ra8_gfx_blit_gray8 1:1 gray8 blit with no zoom or sub-rect.
ra8_gfx_set_clip Confine the lens blit to its window.
Since
0.1.0

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().