ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
emu_view_tile.c
Go to the documentation of this file.
1
12
13#include "emu_view.h"
15
29RA8_INTERNAL static size_t
30internal_row_offset(const emu_presentation_workspace_t* presentation, uint16_t x, uint16_t y)
31{
32 return (((size_t)y * presentation->composite_width) + x) * sizeof(uint16_t);
33}
34
36typedef struct {
37 uint16_t x;
38 uint16_t y;
39 uint16_t width;
40 uint16_t height;
42
57 const uint16_t* pixels,
58 const tile_destination_t* destination)
59{
60 for (uint16_t row = 0U; row < destination->height; row++) {
62 presentation,
63 internal_row_offset(presentation, destination->x, (uint16_t)(destination->y + row)),
64 &pixels[(size_t)row * destination->width],
65 (size_t)destination->width * sizeof(uint16_t))) {
66 return false;
67 }
68 }
69 return true;
70}
71
89 uint16_t source_x,
90 uint16_t source_y,
91 uint16_t width,
92 uint16_t height)
93{
94 tile_destination_t destination = {.x = source_x, .y = source_y, .width = width, .height = height};
95 if ((presentation->rotate_deg == (uint32_t)k_rotate_90) ||
96 (presentation->rotate_deg == (uint32_t)k_rotate_270)) {
97 destination.width = height;
98 destination.height = width;
99 }
100 if (presentation->rotate_deg == (uint32_t)k_rotate_90) {
101 destination.x = (uint16_t)(presentation->panel_height - source_y - height);
102 destination.y = source_x;
103 } else if (presentation->rotate_deg == (uint32_t)k_rotate_180) {
104 destination.x = (uint16_t)(presentation->panel_width - source_x - width);
105 destination.y = (uint16_t)(presentation->panel_height - source_y - height);
106 } else if (presentation->rotate_deg == (uint32_t)k_rotate_270) {
107 destination.x = source_y;
108 destination.y = (uint16_t)(presentation->panel_width - source_x - width);
109 }
110 return destination;
111}
112
128 const uint16_t* source,
129 uint16_t* rotated,
130 uint16_t width,
131 uint16_t height,
132 uint16_t output_width)
133{
134 for (uint16_t y = 0U; y < height; y++) {
135 for (uint16_t x = 0U; x < width; x++) {
136 /* The caller rejects 0 degrees, so 270 is the remaining default. */
137 uint16_t destination_x = y;
138 uint16_t destination_y = (uint16_t)(width - 1U - x);
139 if (presentation->rotate_deg == (uint32_t)k_rotate_90) {
140 destination_x = (uint16_t)(height - 1U - y);
141 destination_y = x;
142 } else if (presentation->rotate_deg == (uint32_t)k_rotate_180) {
143 destination_x = (uint16_t)(width - 1U - x);
144 destination_y = (uint16_t)(height - 1U - y);
145 } else {
146 /* 270 degrees: the seeded destination above already describes it. */
147 }
148 rotated[((size_t)destination_y * output_width) + destination_x] =
149 source[((size_t)y * width) + x];
150 }
151 }
152}
153
155 const uint16_t* source,
156 uint16_t source_x,
157 uint16_t source_y,
158 uint16_t width,
159 uint16_t height)
160{
161 if ((presentation == nullptr) || (source == nullptr) || (width == 0U) || (height == 0U) ||
162 ((size_t)source_x + width > presentation->panel_width) ||
163 ((size_t)source_y + height > presentation->panel_height)) {
164 return false;
165 }
166 if (presentation->rotate_deg == 0U) {
167 const tile_destination_t destination = {.x = source_x,
168 .y = source_y,
169 .width = width,
170 .height = height};
171 return internal_write_rows(presentation, source, &destination);
172 }
173 const size_t max_tile_width = (presentation->panel_width < k_emu_presentation_tile_px)
174 ? presentation->panel_width
176 const size_t max_tile_height = (presentation->panel_height < k_emu_presentation_tile_px)
177 ? presentation->panel_height
179 /* Same borrowed scratch, second half: the rotation destination. Alignment to
180 * alignof(uint16_t) is a checked precondition of emu_presentation_open().
181 * Only the rotating path needs scratch; the workspace documents it as borrowed
182 * "or nullptr", so refuse rather than rotate into nothing. */
183 uint16_t* const pixels = presentation->scratch;
184 if (pixels == nullptr) {
185 return false;
186 }
187 uint16_t* const rotated = &pixels[max_tile_width * max_tile_height];
188 const tile_destination_t destination =
189 internal_tile_destination(presentation, source_x, source_y, width, height);
190 internal_rotate_tile(presentation, source, rotated, width, height, destination.width);
191 return internal_write_rows(presentation, rotated, &destination);
192}
bool emu_presentation_write(emu_presentation_workspace_t *workspace, size_t offset, const void *bytes, size_t count)
Write exact RGB565 bytes at a checked surface offset.
@ k_emu_presentation_tile_px
Square rotation tile side.
Board-view presentation: frames, composition, input routing, panels.
@ k_rotate_90
90 deg clockwise (-> portrait).
Definition emu_view.h:79
@ k_rotate_270
90 deg counter-clockwise.
Definition emu_view.h:81
@ k_rotate_180
Upside down.
Definition emu_view.h:80
bool priv_emu_view_tile_write(emu_presentation_workspace_t *presentation, const uint16_t *source, uint16_t source_x, uint16_t source_y, uint16_t width, uint16_t height)
Rotate and write one native-panel tile into its exact display location.
static RA8_INTERNAL tile_destination_t internal_tile_destination(const emu_presentation_workspace_t *presentation, uint16_t source_x, uint16_t source_y, uint16_t width, uint16_t height)
Resolve one source tile's placement after panel rotation.
static RA8_INTERNAL size_t internal_row_offset(const emu_presentation_workspace_t *presentation, uint16_t x, uint16_t y)
Return the raw-surface byte offset of one display row.
static RA8_INTERNAL bool internal_write_rows(emu_presentation_workspace_t *presentation, const uint16_t *pixels, const tile_destination_t *destination)
Write one contiguous tile into checked raw-surface rows.
static RA8_INTERNAL void internal_rotate_tile(const emu_presentation_workspace_t *presentation, const uint16_t *source, uint16_t *rotated, uint16_t width, uint16_t height, uint16_t output_width)
Rotate one bounded RGB565 tile into caller scratch.
Internal bounded RGB565 tile rotation/writer.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
One independent owned surface plus non-owning bounded scratch.
uint16_t panel_height
Native panel height.
uint16_t composite_width
Display plus sidebar width.
uint16_t * scratch
Borrowed RGB565 scratch, or nullptr.
uint32_t rotate_deg
Bound display rotation.
uint16_t panel_width
Native panel width.
Rotated tile placement and dimensions.
uint16_t height
Rotated tile height.
uint16_t y
Composite destination row.
uint16_t x
Composite destination column.
uint16_t width
Rotated tile width.