display: share code to fetch the display buffer
What changed, and why it matters
This commit is a simple internal code cleanup in the display driver. It extracts a small, repeated snippet of pointer arithmetic into a shared helper function called get_display_buffer_at(). There is no change in behavior, no fix for a bug, and no security relevance visible in the diff or commit message.
No security action required. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors two call sites in main/display.c (display_icon() and display_picture()) to use a new helper get_display_buffer_at() instead of inline arithmetic for computing a pointer into the hardware display buffer. The helper is guarded by the same CONFIG_DISPLAY_FULL_FRAME_BUFFER preprocessor condition and performs the identical calculation: hw_buf + (x - CONFIG_DISPLAY_OFFSET_X) + (y - CONFIG_DISPLAY_OFFSET_Y) * CONFIG_DISPLAY_WIDTH. No bounds checking is added or removed; no callers, data types, or control flow are changed.
Changed components
main/display.c display driverInspect captured patch +12 / −8
diff --git a/main/display.c b/main/display.c
index a4edae3..ef6d2f0 100644
--- a/main/display.c
+++ b/main/display.c
@@ -446,6 +446,16 @@ typedef struct {
static propFont fontChar;
+#ifdef CONFIG_DISPLAY_FULL_FRAME_BUFFER
+uint16_t* get_display_buffer_at(int x, int y)
+{
+ const int calculated_x = x - CONFIG_DISPLAY_OFFSET_X;
+ const int calculated_y = y - CONFIG_DISPLAY_OFFSET_Y;
+ uint16_t* hw_buf = display_hw_get_buffer();
+ return hw_buf + calculated_x + calculated_y * CONFIG_DISPLAY_WIDTH;
+}
+#endif
+
static inline bool get_icon_pixel(uint16_t x, uint16_t y, uint16_t width, const Icon* icon)
{
const uint32_t val = ((uint32_t)width) * y + x;
@@ -497,10 +507,7 @@ void display_icon(const Icon* imgbuf, int x, int y, color_t color, dispWin_t are
}
#ifdef CONFIG_DISPLAY_FULL_FRAME_BUFFER
- const int calculatedx = x - CONFIG_DISPLAY_OFFSET_X;
- const int calculatedy = y - CONFIG_DISPLAY_OFFSET_Y;
- uint16_t* hw_buf = display_hw_get_buffer();
- uint16_t* disp_ptr = &hw_buf[calculatedx + calculatedy * CONFIG_DISPLAY_WIDTH];
+ uint16_t* disp_ptr = get_display_buffer_at(x, y);
const uint32_t* icon_data = imgbuf->data;
uint32_t icon_bits = 0, bit_counter = 0;
const uint32_t stride = CONFIG_DISPLAY_WIDTH - draw_width;
@@ -963,10 +970,7 @@ void display_picture(const Picture* imgbuf, int x, int y, dispWin_t area)
JADE_ASSERT(imgbuf->bytes_per_pixel == 1);
#ifdef CONFIG_DISPLAY_FULL_FRAME_BUFFER
- color_t* hw_buf = display_hw_get_buffer();
- const int offsetx = calculatedx - CONFIG_DISPLAY_OFFSET_X;
- const int offsety = calculatedy - CONFIG_DISPLAY_OFFSET_Y;
- uint16_t* disp_ptr = &hw_buf[offsetx + offsety * CONFIG_DISPLAY_WIDTH];
+ uint16_t* disp_ptr = get_display_buffer_at(calculatedx, calculatedy);
const uint8_t* src_ptr = imgbuf->data_8;
const uint32_t stride = CONFIG_DISPLAY_WIDTH - imgbuf->width;
for (size_t i = 0; i < imgbuf->height; ++i) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.