mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
modules: Update framebuffer API.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
66c8e7e8d5
commit
fbc8d14cda
@ -138,8 +138,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_omv_csi_shutdown_obj, py_omv_csi_shutdown);
|
||||
static mp_obj_t py_omv_csi_flush() {
|
||||
omv_csi_t *csi = omv_csi_get(-1);
|
||||
image_t tmp;
|
||||
framebuffer_init_image(csi->fb, &tmp);
|
||||
framebuffer_update_jpeg_buffer(&tmp);
|
||||
framebuffer_to_image(csi->fb, &tmp);
|
||||
framebuffer_update_preview(&tmp);
|
||||
return mp_const_none;
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_flush_obj, py_omv_csi_flush);
|
||||
@ -215,7 +215,7 @@ static mp_obj_t py_omv_csi_get_fb() {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
framebuffer_init_image(csi->fb, &image);
|
||||
framebuffer_to_image(csi->fb, &image);
|
||||
return py_image_from_struct(&image);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_0(py_omv_csi_get_fb_obj, py_omv_csi_get_fb);
|
||||
|
@ -179,8 +179,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(py_csi_sleep_obj, py_csi_sleep);
|
||||
static mp_obj_t py_csi_flush(mp_obj_t self_in) {
|
||||
py_csi_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
image_t tmp;
|
||||
framebuffer_init_image(self->csi->fb, &tmp);
|
||||
framebuffer_update_jpeg_buffer(&tmp);
|
||||
framebuffer_to_image(self->csi->fb, &tmp);
|
||||
framebuffer_update_preview(&tmp);
|
||||
return mp_const_none;
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_csi_flush_obj, py_csi_flush);
|
||||
@ -1350,7 +1350,7 @@ 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_malloc(sizeof(framebuffer_t));
|
||||
framebuffer_init(csi->fb, m_malloc(fb_size), fb_size, true);
|
||||
framebuffer_init(csi->fb, m_malloc(fb_size), fb_size, true, true);
|
||||
}
|
||||
|
||||
#if MICROPY_PY_IMU
|
||||
@ -1383,7 +1383,6 @@ static void py_csi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin
|
||||
mp_printf(print, " Expanded : %s\n", csi->fb->expanded ? "true" : "false");
|
||||
mp_printf(print, " Raw Buffer Size : %u\n", (unsigned) csi->fb->raw_size);
|
||||
mp_printf(print, " Raw Buffer Addr : 0x%p\n", csi->fb->raw_base);
|
||||
mp_printf(print, " Frame Size : %u\n", (unsigned) csi->fb->frame_size);
|
||||
mp_printf(print, " Vbuffer Size : %u\n", (unsigned) csi->fb->buf_size);
|
||||
mp_printf(print, " Vbuffer Count : %u\n", (unsigned) csi->fb->buf_count);
|
||||
mp_printf(print, " Used Queue Size : %u\n", queue_size(csi->fb->used_queue));
|
||||
|
@ -977,7 +977,7 @@ mp_obj_t py_fir_snapshot(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||
fb_alloc_free_till_mark();
|
||||
|
||||
if (args[ARG_copy_to_fb].u_bool) {
|
||||
framebuffer_update_jpeg_buffer(&dst_img);
|
||||
framebuffer_update_preview(&dst_img);
|
||||
}
|
||||
return py_image_from_struct(&dst_img);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ static mp_obj_t py_gif_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
py_gif_obj_t *gif = mp_obj_malloc_with_finaliser(py_gif_obj_t, &py_gif_type);
|
||||
|
||||
gif->width = (args[ARG_width].u_int == -1) ? fb->w : args[ARG_width].u_int;
|
||||
|
@ -584,7 +584,7 @@ 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);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_USED | FB_FLAG_PEEK);
|
||||
|
||||
return (buffer != NULL) && (img->data == buffer->data);
|
||||
@ -592,7 +592,7 @@ bool py_helper_is_equal_to_framebuffer(image_t *img) {
|
||||
|
||||
void py_helper_update_framebuffer(image_t *img) {
|
||||
if (py_helper_is_equal_to_framebuffer(img)) {
|
||||
framebuffer_init_from_image(framebuffer_get(0), img);
|
||||
framebuffer_from_image(framebuffer_get(FB_MAINFB_ID), img);
|
||||
}
|
||||
}
|
||||
|
||||
@ -604,11 +604,11 @@ void py_helper_set_to_framebuffer(image_t *img) {
|
||||
|
||||
omv_csi_abort(csi, true, false);
|
||||
#else
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
#endif
|
||||
|
||||
// Resize the frame buffer to use all memory for one buffer.
|
||||
framebuffer_resize(fb, 1, true);
|
||||
framebuffer_resize(fb, 1, 0, true);
|
||||
|
||||
// This should never be NULL after resizing the frame buffer.
|
||||
vbuffer_t *buffer = framebuffer_acquire(fb, FB_FLAG_FREE | FB_FLAG_PEEK);
|
||||
@ -617,6 +617,6 @@ void py_helper_set_to_framebuffer(image_t *img) {
|
||||
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);
|
||||
framebuffer_from_image(fb, img);
|
||||
img->data = buffer->data;
|
||||
}
|
||||
|
@ -1082,10 +1082,10 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
|
||||
float *transform = py_helper_arg_to_transform(args[ARG_transform].u_obj);
|
||||
|
||||
if (args[ARG_copy_to_fb].u_bool) {
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
image_t tmp;
|
||||
framebuffer_init_image(fb, &tmp);
|
||||
framebuffer_update_jpeg_buffer(&tmp);
|
||||
framebuffer_to_image(fb, &tmp);
|
||||
framebuffer_update_preview(&tmp);
|
||||
}
|
||||
|
||||
image_t dst_img = {
|
||||
@ -1185,7 +1185,7 @@ static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palet
|
||||
image_alloc(&dst_img, size);
|
||||
} else {
|
||||
// Convert in place.
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
bool is_fb = py_helper_is_equal_to_framebuffer(src_img);
|
||||
size_t buf_size = is_fb ? framebuffer_get_buffer_size(fb) : image_size(src_img);
|
||||
PY_ASSERT_TRUE_MSG((size <= buf_size), "The image doesn't fit in the frame buffer!");
|
||||
@ -1297,7 +1297,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_obj, 2, py_image_save);
|
||||
#endif //IMLIB_ENABLE_IMAGE_FILE_IO
|
||||
|
||||
static mp_obj_t py_image_flush(mp_obj_t img_obj) {
|
||||
framebuffer_update_jpeg_buffer(py_image_cobj(img_obj));
|
||||
framebuffer_update_preview(py_image_cobj(img_obj));
|
||||
return mp_const_none;
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_image_flush_obj, py_image_flush);
|
||||
@ -6305,7 +6305,7 @@ mp_obj_t py_image_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw
|
||||
}
|
||||
|
||||
if (args[ARG_copy_to_fb].u_bool) {
|
||||
framebuffer_update_jpeg_buffer(&image);
|
||||
framebuffer_update_preview(&image);
|
||||
}
|
||||
return py_image_from_struct(&image);
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ static mp_obj_t py_imageio_read(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||
py_helper_update_framebuffer(&image);
|
||||
|
||||
if (args[ARG_copy_to_fb].u_bool) {
|
||||
framebuffer_update_jpeg_buffer(&image);
|
||||
framebuffer_update_preview(&image);
|
||||
}
|
||||
return py_image_from_struct(&image);
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ static mp_obj_t py_mjpeg_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
py_mjpeg_obj_t *mjpeg = mp_obj_malloc_with_finaliser(py_mjpeg_obj_t, &py_mjpeg_type);
|
||||
|
||||
mjpeg->frames = 0;
|
||||
|
@ -590,7 +590,7 @@ mp_obj_t py_tof_snapshot(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
||||
fb_alloc_free_till_mark();
|
||||
|
||||
if (args[ARG_copy_to_fb].u_bool) {
|
||||
framebuffer_update_jpeg_buffer(&dst_img);
|
||||
framebuffer_update_preview(&dst_img);
|
||||
}
|
||||
return py_image_from_struct(&dst_img);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user