Skip to content

Commit a33e48c

Browse files
committed
framebufferio: add "first pixel offset" and "row stride"
1 parent 8021f3b commit a33e48c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
7070
false // reverse_bytes_in_word
7171
);
7272

73+
self->first_pixel_offset = self->framebuffer_protocol->get_first_pixel_offset
74+
? self->framebuffer_protocol->get_first_pixel_offset(self->framebuffer)
75+
: 0;
76+
self->row_stride = self->framebuffer_protocol->get_row_stride
77+
? self->framebuffer_protocol->get_row_stride(self->framebuffer)
78+
: 0;
79+
if (self->row_stride == 0) {
80+
self->row_stride = self->core.width * self->core.colorspace.depth/8;
81+
}
7382
self->first_manual_refresh = !auto_refresh;
7483

7584
self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
@@ -209,11 +218,13 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
209218

210219
uint8_t *buf = (uint8_t *)self->bufinfo.buf, *endbuf = buf + self->bufinfo.len;
211220
(void)endbuf; // Hint to compiler that endbuf is "used" even if NDEBUG
221+
buf += self->first_pixel_offset;
212222

213-
uint8_t *dest = self->bufinfo.buf + (subrectangle.y1 * self->core.width + subrectangle.x1) * self->core.colorspace.depth / 8;
223+
size_t rowstride = self->row_stride;
224+
uint8_t *dest = buf + subrectangle.y1 * rowstride + subrectangle.x1 * self->core.colorspace.depth / 8;
214225
uint8_t *src = (uint8_t*)buffer;
215226
size_t rowsize = (subrectangle.x2 - subrectangle.x1) * self->core.colorspace.depth / 8;
216-
size_t rowstride = self->core.width * self->core.colorspace.depth/8;
227+
217228
for (uint16_t i = subrectangle.y1; i < subrectangle.y2; i++) {
218229
assert(dest >= buf && dest < endbuf && dest+rowsize <= endbuf);
219230
memcpy(dest, src, rowsize);
@@ -230,9 +241,9 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
230241

231242
STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t* self) {
232243
displayio_display_core_start_refresh(&self->core);
233-
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
234244
const displayio_area_t* current_area = _get_refresh_areas(self);
235245
if (current_area) {
246+
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
236247
while (current_area != NULL) {
237248
_refresh_area(self, current_area);
238249
current_area = current_area->next;

shared-module/framebufferio/FramebufferDisplay.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct {
4848
uint64_t last_refresh_call;
4949
uint16_t native_frames_per_second;
5050
uint16_t native_ms_per_frame;
51+
uint16_t first_pixel_offset, row_stride;
5152
bool auto_refresh;
5253
bool first_manual_refresh;
5354
} framebufferio_framebufferdisplay_obj_t;
@@ -70,6 +71,8 @@ typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
7071
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
7172
typedef int (*framebuffer_get_width_fun)(mp_obj_t);
7273
typedef int (*framebuffer_get_height_fun)(mp_obj_t);
74+
typedef int (*framebuffer_get_row_stride_fun)(mp_obj_t);
75+
typedef int (*framebuffer_get_first_pixel_offset_fun)(mp_obj_t);
7376
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
7477
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
7578
typedef int (*framebuffer_get_native_frames_per_second_fun)(mp_obj_t);
@@ -86,6 +89,8 @@ typedef struct _framebuffer_p_t {
8689
framebuffer_get_native_frames_per_second_fun get_native_frames_per_second;
8790
framebuffer_get_brightness_fun get_brightness;
8891
framebuffer_set_brightness_fun set_brightness;
92+
framebuffer_get_row_stride_fun get_row_stride;
93+
framebuffer_get_first_pixel_offset_fun get_first_pixel_offset;
8994
framebuffer_get_auto_brightness_fun get_auto_brightness;
9095
framebuffer_set_auto_brightness_fun set_auto_brightness;
9196
} framebuffer_p_t;

0 commit comments

Comments
 (0)