mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
modules: Use the new framebuffer API.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com> modules
This commit is contained in:
parent
af711cfc90
commit
85a1096986
@ -211,7 +211,7 @@ static mp_obj_t py_omv_csi_get_fb() {
|
||||
image_t image;
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
|
||||
if (framebuffer_get_depth(csi->fb) < 0) {
|
||||
if (csi->fb->bpp < 0) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -229,7 +229,8 @@ static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_get_id_obj, py_omv_csi_get_id);
|
||||
static mp_obj_t py_omv_csi_get_frame_available() {
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
framebuffer_t *fb = csi->fb;
|
||||
return mp_obj_new_bool(fb->tail != fb->head);
|
||||
|
||||
return mp_obj_new_bool(framebuffer_readable(fb));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_get_frame_available_obj, py_omv_csi_get_frame_available);
|
||||
|
||||
@ -378,10 +379,10 @@ static mp_obj_t py_omv_csi_get_windowing() {
|
||||
omv_csi_raise_error(OMV_CSI_ERROR_INVALID_FRAMESIZE);
|
||||
}
|
||||
|
||||
return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(framebuffer_get_x(csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_y(csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_u(csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_v(csi->fb))});
|
||||
return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(csi->fb->x),
|
||||
mp_obj_new_int(csi->fb->y),
|
||||
mp_obj_new_int(csi->fb->u),
|
||||
mp_obj_new_int(csi->fb->v)});
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_get_windowing_obj, py_omv_csi_get_windowing);
|
||||
|
||||
@ -704,7 +705,7 @@ static mp_obj_t py_omv_csi_set_framebuffers(mp_obj_t count) {
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
mp_int_t c = mp_obj_get_int(count);
|
||||
|
||||
if (c == csi->fb->n_buffers) {
|
||||
if (c == csi->fb->buf_count) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
@ -712,7 +713,7 @@ static mp_obj_t py_omv_csi_set_framebuffers(mp_obj_t count) {
|
||||
omv_csi_raise_error(OMV_CSI_ERROR_INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
int error = omv_csi_set_framebuffers(csi, c);
|
||||
int error = omv_csi_set_framebuffers(csi, c, false);
|
||||
if (error != 0) {
|
||||
omv_csi_raise_error(error);
|
||||
}
|
||||
@ -723,7 +724,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_omv_csi_set_framebuffers_obj, py_omv_csi_set
|
||||
|
||||
static mp_obj_t py_omv_csi_get_framebuffers() {
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
return mp_obj_new_int(csi->fb->n_buffers);
|
||||
return mp_obj_new_int(csi->fb->buf_count);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_get_framebuffers_obj, py_omv_csi_get_framebuffers);
|
||||
|
||||
|
||||
@ -62,7 +62,6 @@ typedef struct _py_csi_obj_t {
|
||||
omv_csi_t *csi;
|
||||
mp_obj_t vsync_cb;
|
||||
mp_obj_t frame_cb;
|
||||
framebuffer_t *fb; // Track dynamically allocated FBs.
|
||||
} py_csi_obj_t;
|
||||
|
||||
const mp_obj_type_t py_csi_type;
|
||||
@ -123,7 +122,6 @@ static mp_obj_t py_csi_deinit(mp_obj_t self_in) {
|
||||
|
||||
// Reset FB pointer (realloc'd in make_new).
|
||||
if (self->csi->fb->dynamic) {
|
||||
self->fb = NULL;
|
||||
self->csi->fb = NULL;
|
||||
}
|
||||
|
||||
@ -284,8 +282,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_csi_cid_obj, py_csi_cid);
|
||||
|
||||
static mp_obj_t py_csi_readable(mp_obj_t self_in) {
|
||||
py_csi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vbuffer_t *head = framebuffer_get_head(self->csi->fb, FB_PEEK);
|
||||
return mp_obj_new_bool(head != NULL);
|
||||
framebuffer_t *fb = self->csi->fb;
|
||||
|
||||
return mp_obj_new_bool(framebuffer_readable(fb));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_csi_readable_obj, py_csi_readable);
|
||||
|
||||
@ -355,10 +354,10 @@ static mp_obj_t py_csi_window(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(framebuffer_get_x(self->csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_y(self->csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_u(self->csi->fb)),
|
||||
mp_obj_new_int(framebuffer_get_v(self->csi->fb))});
|
||||
return mp_obj_new_tuple(4, (mp_obj_t []) {mp_obj_new_int(self->csi->fb->x),
|
||||
mp_obj_new_int(self->csi->fb->y),
|
||||
mp_obj_new_int(self->csi->fb->u),
|
||||
mp_obj_new_int(self->csi->fb->v)});
|
||||
}
|
||||
|
||||
mp_obj_t *array;
|
||||
@ -750,19 +749,26 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_csi_auto_rotation_obj, 1, 2, py_cs
|
||||
static mp_obj_t py_csi_framebuffers(size_t n_args, const mp_obj_t *args) {
|
||||
py_csi_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
framebuffer_t *fb = self->csi->fb;
|
||||
bool expand = false;
|
||||
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_int(fb->n_buffers);
|
||||
return mp_obj_new_int(fb->buf_count);
|
||||
}
|
||||
|
||||
mp_int_t num = mp_obj_get_int(args[1]);
|
||||
|
||||
if (n_args == 3) {
|
||||
expand = mp_obj_is_true(args[2]);
|
||||
}
|
||||
|
||||
if (num < 1) {
|
||||
omv_csi_raise_error(OMV_CSI_ERROR_INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
if (num != fb->n_buffers) {
|
||||
int error = omv_csi_set_framebuffers(self->csi, num);
|
||||
// Reconfigure the FB only if changing the number
|
||||
// of buffers or reconfiguring the memory expansion.
|
||||
if (fb->expanded != expand || num != fb->buf_count) {
|
||||
int error = omv_csi_set_framebuffers(self->csi, num, expand);
|
||||
if (error != 0) {
|
||||
omv_csi_raise_error(error);
|
||||
}
|
||||
@ -770,7 +776,7 @@ static mp_obj_t py_csi_framebuffers(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_csi_framebuffers_obj, 1, 2, py_csi_framebuffers);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_csi_framebuffers_obj, 1, 3, py_csi_framebuffers);
|
||||
|
||||
static mp_obj_t py_csi_special_effect(mp_obj_t self_in, mp_obj_t sde) {
|
||||
py_csi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
@ -1281,9 +1287,8 @@ mp_obj_t py_csi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||
|
||||
if (csi->fb == NULL) {
|
||||
size_t fb_size = args[ARG_fb_size].u_int;
|
||||
csi->fb = (framebuffer_t *) m_new(uint8_t, fb_size + sizeof(framebuffer_t));
|
||||
framebuffer_init_fb(csi->fb, fb_size, true);
|
||||
self->fb = csi->fb; // Track GC heap alloc
|
||||
csi->fb = (framebuffer_t *) m_malloc(sizeof(framebuffer_t));
|
||||
framebuffer_init(csi->fb, m_malloc(fb_size), fb_size, true);
|
||||
}
|
||||
|
||||
#if MICROPY_PY_IMU
|
||||
|
||||
@ -548,7 +548,9 @@ const uint8_t *py_helper_keyword_alpha_palette(size_t n_args, const mp_obj_t *ar
|
||||
|
||||
bool py_helper_is_equal_to_framebuffer(image_t *img) {
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
return framebuffer_get_buffer(fb, fb->head)->data == img->data;
|
||||
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_USED | FB_FLAG_PEEK);
|
||||
|
||||
return (buffer != NULL) && (img->data == buffer->data);
|
||||
}
|
||||
|
||||
void py_helper_update_framebuffer(image_t *img) {
|
||||
@ -557,20 +559,27 @@ void py_helper_update_framebuffer(image_t *img) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO need to pass a CSI here.
|
||||
void py_helper_set_to_framebuffer(image_t *img) {
|
||||
#if MICROPY_PY_CSI
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
framebuffer_t *fb = csi->fb;
|
||||
|
||||
omv_csi_set_framebuffers(csi, 1);
|
||||
omv_csi_abort(csi, true, false);
|
||||
#else
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
|
||||
framebuffer_set_buffers(fb, 1);
|
||||
#endif
|
||||
|
||||
// Resize the frame buffer to use all memory for one buffer.
|
||||
framebuffer_resize(fb, 1, true);
|
||||
|
||||
// This should never be NULL after resizing the frame buffer.
|
||||
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_FREE | FB_FLAG_PEEK);
|
||||
|
||||
PY_ASSERT_TRUE_MSG(buffer, "No free buffers!");
|
||||
PY_ASSERT_TRUE_MSG((image_size(img) <= framebuffer_get_buffer_size(fb)),
|
||||
"The image doesn't fit in the frame buffer!");
|
||||
|
||||
framebuffer_init_from_image(fb, img);
|
||||
img->data = framebuffer_get_buffer(fb, fb->head)->data;
|
||||
img->data = buffer->data;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user