mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #2140 from kwagyeman/kwabena/remove_slow_stuff
modules/py_image: Remove div() method.
This commit is contained in:
commit
78c7d1aa43
@ -1394,7 +1394,6 @@ void imlib_replace(image_t *img,
|
||||
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_div(image_t *img, const char *path, image_t *other, int scalar, bool invert, bool mod, 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);
|
||||
|
||||
@ -417,95 +417,6 @@ void imlib_mul(image_t *img, const char *path, image_t *other, int scalar, bool
|
||||
imlib_image_operation(img, path, other, scalar, imlib_mul_line_op, &state);
|
||||
}
|
||||
|
||||
typedef struct imlib_div_line_op_state {
|
||||
bool invert, mod;
|
||||
image_t *mask;
|
||||
} imlib_div_line_op_state_t;
|
||||
|
||||
static void imlib_div_line_op(image_t *img, int line, void *other, void *data, bool vflipped) {
|
||||
bool invert = ((imlib_div_line_op_state_t *) data)->invert;
|
||||
bool mod = ((imlib_div_line_op_state_t *) data)->mod;
|
||||
image_t *mask = ((imlib_div_line_op_state_t *) data)->mask;
|
||||
|
||||
switch (img->pixfmt) {
|
||||
case PIXFORMAT_BINARY: {
|
||||
uint32_t *data = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img, line);
|
||||
int pScale = COLOR_BINARY_MAX - COLOR_BINARY_MIN;
|
||||
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 = mod
|
||||
? IM_MOD((invert?otherPixel:dataPixel) * pScale, (invert?dataPixel:otherPixel))
|
||||
: IM_DIV((invert?otherPixel:dataPixel) * pScale, (invert?dataPixel:otherPixel));
|
||||
p = IM_MIN(p, COLOR_BINARY_MAX);
|
||||
IMAGE_PUT_BINARY_PIXEL_FAST(data, i, p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PIXFORMAT_GRAYSCALE: {
|
||||
uint8_t *data = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img, line);
|
||||
int pScale = COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN;
|
||||
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 = mod
|
||||
? IM_MOD((invert?otherPixel:dataPixel) * pScale, (invert?dataPixel:otherPixel))
|
||||
: IM_DIV((invert?otherPixel:dataPixel) * pScale, (invert?dataPixel:otherPixel));
|
||||
p = IM_MIN(p, COLOR_GRAYSCALE_MAX);
|
||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(data, i, p);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PIXFORMAT_RGB565: {
|
||||
uint16_t *data = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, line);
|
||||
int rScale = COLOR_R5_MAX - COLOR_R5_MIN;
|
||||
int gScale = COLOR_G6_MAX - COLOR_G6_MIN;
|
||||
int bScale = COLOR_B5_MAX - COLOR_B5_MIN;
|
||||
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 = mod
|
||||
? IM_MOD((invert?oR:dR) * rScale, (invert?dR:oR))
|
||||
: IM_DIV((invert?oR:dR) * rScale, (invert?dR:oR));
|
||||
int g = mod
|
||||
? IM_MOD((invert?oG:dG) * gScale, (invert?dG:oG))
|
||||
: IM_DIV((invert?oG:dG) * gScale, (invert?dG:oG));
|
||||
int b = mod
|
||||
? IM_MOD((invert?oB:dB) * bScale, (invert?dB:oB))
|
||||
: IM_DIV((invert?oB:dB) * bScale, (invert?dB:oB));
|
||||
r = IM_MIN(r, COLOR_R5_MAX);
|
||||
g = IM_MIN(g, COLOR_G6_MAX);
|
||||
b = IM_MIN(b, COLOR_B5_MAX);
|
||||
IMAGE_PUT_RGB565_PIXEL_FAST(data, i, COLOR_R5_G6_B5_TO_RGB565(r, g, b));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imlib_div(image_t *img, const char *path, image_t *other, int scalar, bool invert, bool mod, image_t *mask) {
|
||||
imlib_div_line_op_state_t state;
|
||||
state.invert = invert;
|
||||
state.mod = mod;
|
||||
state.mask = mask;
|
||||
imlib_image_operation(img, path, other, scalar, imlib_div_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;
|
||||
|
||||
|
||||
@ -2315,36 +2315,6 @@ STATIC mp_obj_t py_image_mul(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_mul_obj, 2, py_image_mul);
|
||||
|
||||
STATIC mp_obj_t py_image_div(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);
|
||||
bool arg_mod =
|
||||
py_helper_keyword_int(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_mod), false);
|
||||
image_t *arg_msk =
|
||||
py_helper_keyword_to_image(n_args, args, 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_mask), NULL);
|
||||
|
||||
fb_alloc_mark();
|
||||
|
||||
if (MP_OBJ_IS_STR(args[1])) {
|
||||
imlib_div(arg_img, mp_obj_str_get_str(args[1]), NULL, 0,
|
||||
arg_invert, arg_mod, arg_msk);
|
||||
} else if (MP_OBJ_IS_TYPE(args[1], &py_image_type)) {
|
||||
imlib_div(arg_img, NULL, py_helper_arg_to_image(args[1], ARG_IMAGE_MUTABLE), 0,
|
||||
arg_invert, arg_mod, arg_msk);
|
||||
} else {
|
||||
imlib_div(arg_img, NULL, NULL,
|
||||
py_helper_keyword_color(arg_img, n_args, args, 1, NULL, 0),
|
||||
arg_invert, arg_mod, arg_msk);
|
||||
}
|
||||
|
||||
fb_alloc_free_till_mark();
|
||||
|
||||
return args[0];
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_div_obj, 2, py_image_div);
|
||||
|
||||
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);
|
||||
@ -6565,7 +6535,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = {
|
||||
{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_div), MP_ROM_PTR(&py_image_div_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)},
|
||||
@ -6578,7 +6547,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = {
|
||||
{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_div), 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)},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user