diff --git a/src/omv/imlib/imlib.h b/src/omv/imlib/imlib.h index 5fa45ca32..71b2dd271 100644 --- a/src/omv/imlib/imlib.h +++ b/src/omv/imlib/imlib.h @@ -1393,7 +1393,6 @@ void imlib_replace(image_t *img, image_t *mask); void imlib_add(image_t *img, const char *path, image_t *other, int scalar, image_t *mask); void imlib_sub(image_t *img, const char *path, image_t *other, int scalar, bool reverse, image_t *mask); -void imlib_mul(image_t *img, const char *path, image_t *other, int scalar, bool invert, image_t *mask); void imlib_min(image_t *img, const char *path, image_t *other, int scalar, image_t *mask); void imlib_max(image_t *img, const char *path, image_t *other, int scalar, image_t *mask); void imlib_difference(image_t *img, const char *path, image_t *other, int scalar, image_t *mask); diff --git a/src/omv/imlib/mathop.c b/src/omv/imlib/mathop.c index bef065c1b..b6f0c86e3 100644 --- a/src/omv/imlib/mathop.c +++ b/src/omv/imlib/mathop.c @@ -335,88 +335,6 @@ void imlib_sub(image_t *img, const char *path, image_t *other, int scalar, bool imlib_image_operation(img, path, other, scalar, imlib_sub_line_op, &state); } -typedef struct imlib_mul_line_op_state { - bool invert; - image_t *mask; -} imlib_mul_line_op_state_t; - -static void imlib_mul_line_op(image_t *img, int line, void *other, void *data, bool vflipped) { - bool invert = ((imlib_mul_line_op_state_t *) data)->invert; - image_t *mask = ((imlib_mul_line_op_state_t *) data)->mask; - - switch (img->pixfmt) { - case PIXFORMAT_BINARY: { - uint32_t *data = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img, line); - float pScale = COLOR_BINARY_MAX - COLOR_BINARY_MIN; - float pDiv = 1 / pScale; - for (int i = 0, j = img->w; i < j; i++) { - if ((!mask) || image_get_mask_pixel(mask, i, line)) { - int dataPixel = IMAGE_GET_BINARY_PIXEL_FAST(data, i); - int otherPixel = IMAGE_GET_BINARY_PIXEL_FAST(((uint32_t *) other), i); - int p = invert ? (pScale - ((pScale - dataPixel) * (pScale - otherPixel) * pDiv)) - : (dataPixel * otherPixel * pDiv); - IMAGE_PUT_BINARY_PIXEL_FAST(data, i, p); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - uint8_t *data = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img, line); - float pScale = COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN; - float pDiv = 1 / pScale; - for (int i = 0, j = img->w; i < j; i++) { - if ((!mask) || image_get_mask_pixel(mask, i, line)) { - int dataPixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(data, i); - int otherPixel = IMAGE_GET_GRAYSCALE_PIXEL_FAST(((uint8_t *) other), i); - int p = invert ? (pScale - ((pScale - dataPixel) * (pScale - otherPixel) * pDiv)) - : (dataPixel * otherPixel * pDiv); - IMAGE_PUT_GRAYSCALE_PIXEL_FAST(data, i, p); - } - } - break; - } - case PIXFORMAT_RGB565: { - uint16_t *data = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, line); - float rScale = COLOR_R5_MAX - COLOR_R5_MIN; - float gScale = COLOR_G6_MAX - COLOR_G6_MIN; - float bScale = COLOR_B5_MAX - COLOR_B5_MIN; - float rDiv = 1 / rScale; - float gDiv = 1 / gScale; - float bDiv = 1 / bScale; - for (int i = 0, j = img->w; i < j; i++) { - if ((!mask) || image_get_mask_pixel(mask, i, line)) { - int dataPixel = IMAGE_GET_RGB565_PIXEL_FAST(data, i); - int otherPixel = IMAGE_GET_RGB565_PIXEL_FAST(((uint16_t *) other), i); - int dR = COLOR_RGB565_TO_R5(dataPixel); - int dG = COLOR_RGB565_TO_G6(dataPixel); - int dB = COLOR_RGB565_TO_B5(dataPixel); - int oR = COLOR_RGB565_TO_R5(otherPixel); - int oG = COLOR_RGB565_TO_G6(otherPixel); - int oB = COLOR_RGB565_TO_B5(otherPixel); - int r = invert ? (rScale - ((rScale - dR) * (rScale - oR) * rDiv)) - : (dR * oR * rDiv); - int g = invert ? (gScale - ((gScale - dG) * (gScale - oG) * gDiv)) - : (dG * oG * gDiv); - int b = invert ? (bScale - ((bScale - dB) * (bScale - oB) * bDiv)) - : (dB * oB * bDiv); - IMAGE_PUT_RGB565_PIXEL_FAST(data, i, COLOR_R5_G6_B5_TO_RGB565(r, g, b)); - } - } - break; - } - default: { - break; - } - } -} - -void imlib_mul(image_t *img, const char *path, image_t *other, int scalar, bool invert, image_t *mask) { - imlib_mul_line_op_state_t state; - state.invert = invert; - state.mask = mask; - imlib_image_operation(img, path, other, scalar, imlib_mul_line_op, &state); -} - static void imlib_min_line_op(image_t *img, int line, void *other, void *data, bool vflipped) { image_t *mask = (image_t *) data; diff --git a/src/omv/modules/py_image.c b/src/omv/modules/py_image.c index fcf426fad..8a57a5bb6 100644 --- a/src/omv/modules/py_image.c +++ b/src/omv/modules/py_image.c @@ -2289,32 +2289,6 @@ STATIC mp_obj_t py_image_sub(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_sub_obj, 2, py_image_sub); -STATIC mp_obj_t py_image_mul(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = - py_helper_arg_to_image(args[0], ARG_IMAGE_MUTABLE); - bool arg_invert = - py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_invert), false); - image_t *arg_msk = - py_helper_keyword_to_image(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_mask), NULL); - - fb_alloc_mark(); - - if (MP_OBJ_IS_STR(args[1])) { - imlib_mul(arg_img, mp_obj_str_get_str(args[1]), NULL, 0, arg_invert, arg_msk); - } else if (MP_OBJ_IS_TYPE(args[1], &py_image_type)) { - imlib_mul(arg_img, NULL, py_helper_arg_to_image(args[1], ARG_IMAGE_MUTABLE), 0, arg_invert, arg_msk); - } else { - imlib_mul(arg_img, NULL, NULL, - py_helper_keyword_color(arg_img, n_args, args, 1, NULL, 0), - arg_invert, arg_msk); - } - - fb_alloc_free_till_mark(); - - return args[0]; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_mul_obj, 2, py_image_mul); - STATIC mp_obj_t py_image_min(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { image_t *arg_img = py_helper_arg_to_image(args[0], ARG_IMAGE_MUTABLE); @@ -6511,7 +6485,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&py_image_replace_obj)}, {MP_ROM_QSTR(MP_QSTR_add), MP_ROM_PTR(&py_image_add_obj)}, {MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&py_image_sub_obj)}, - {MP_ROM_QSTR(MP_QSTR_mul), MP_ROM_PTR(&py_image_mul_obj)}, {MP_ROM_QSTR(MP_QSTR_min), MP_ROM_PTR(&py_image_min_obj)}, {MP_ROM_QSTR(MP_QSTR_max), MP_ROM_PTR(&py_image_max_obj)}, {MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&py_image_difference_obj)}, @@ -6523,7 +6496,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_add), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&py_func_unavailable_obj)}, - {MP_ROM_QSTR(MP_QSTR_mul), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_min), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_max), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&py_func_unavailable_obj)},