From fff1964d9bf37d24539ffe6b2316d68ffbb42510 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 2 Feb 2019 21:33:31 -0500 Subject: [PATCH] Upgrade copy_to_fb for fir. --- src/omv/py/py_fir.c | 50 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/omv/py/py_fir.c b/src/omv/py/py_fir.c index 67eb6f869..f3de1a85d 100644 --- a/src/omv/py/py_fir.c +++ b/src/omv/py/py_fir.c @@ -722,8 +722,21 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) int pixformat = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_pixformat), PIXFORMAT_RGB565); PY_ASSERT_TRUE_MSG((pixformat == PIXFORMAT_GRAYSCALE) || (pixformat == PIXFORMAT_RGB565), "Invalid Pixformat!"); - bool copy_to_fb = py_helper_keyword_int(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), false); - if (copy_to_fb) fb_update_jpeg_buffer(); + mp_obj_t copy_to_fb_obj = py_helper_keyword_object(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb)); + bool copy_to_fb = false; + image_t *arg_other = NULL; + + if (copy_to_fb_obj) { + if (mp_obj_is_integer(copy_to_fb_obj)) { + copy_to_fb = mp_obj_get_int(copy_to_fb_obj); + } else { + arg_other = py_helper_arg_to_image_mutable(copy_to_fb_obj); + } + } + + if (copy_to_fb) { + fb_update_jpeg_buffer(); + } image_t image; image.w = width; @@ -732,15 +745,36 @@ mp_obj_t py_fir_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) image.data = NULL; if (copy_to_fb) { - PY_ASSERT_TRUE_MSG((image_size(&image) <= OMV_RAW_BUF_SIZE), "FB Overflow!"); - MAIN_FB()->w = image.w; - MAIN_FB()->h = image.h; - MAIN_FB()->bpp = image.bpp; - image.data = MAIN_FB()->pixels; + MAIN_FB()->w = 0; + MAIN_FB()->h = 0; + MAIN_FB()->bpp = 0; + PY_ASSERT_TRUE_MSG((image_size(&image) <= fb_avail()), "The new image won't fit in the main frame buffer!"); + MAIN_FB()->w = image.w; + MAIN_FB()->h = image.h; + MAIN_FB()->bpp = image.bpp; + image.data = MAIN_FB()->pixels; + } else if (arg_other) { + PY_ASSERT_TRUE_MSG((image_size(&image) <= image_size(arg_other)), "The new image won't fit in the target frame buffer!"); + image.data = arg_other->data; } else { - image.data = xalloc(image_size(&image)); + image.data = xalloc(image_size(&image)); } + // Zero the image we are about to draw on. + memset(image.data, 0, image_size(&image)); + + if (MAIN_FB()->pixels == image.data) { + MAIN_FB()->w = image.w; + MAIN_FB()->h = image.h; + MAIN_FB()->bpp = image.bpp; + } + + if (arg_other) { + arg_other->w = image.w; + arg_other->h = image.h; + arg_other->bpp = image.bpp; + } + mp_obj_t snapshot = py_image_from_struct(&image); mp_obj_t *new_args = xalloc((2 + n_args) * sizeof(mp_obj_t));