Merge pull request #2138 from kwagyeman/kwabena/move_ksize_helper

imlib: Add ksize helper.
This commit is contained in:
Ibrahim Abdelkader 2024-02-14 09:37:58 +02:00 committed by GitHub
commit 82b61a8553
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 9 deletions

View File

@ -906,13 +906,13 @@ void imlib_dilate(image_t *img, int ksize, int threshold, image_t *mask) {
}
void imlib_open(image_t *img, int ksize, int threshold, image_t *mask) {
imlib_erode(img, ksize, (((ksize * 2) + 1) * ((ksize * 2) + 1)) - 1 - threshold, mask);
imlib_erode(img, ksize, imlib_ksize_to_n(ksize) - 1 - threshold, mask);
imlib_dilate(img, ksize, 0 + threshold, mask);
}
void imlib_close(image_t *img, int ksize, int threshold, image_t *mask) {
imlib_dilate(img, ksize, 0 + threshold, mask);
imlib_erode(img, ksize, (((ksize * 2) + 1) * ((ksize * 2) + 1)) - 1 - threshold, mask);
imlib_erode(img, ksize, imlib_ksize_to_n(ksize) - 1 - threshold, mask);
}
void imlib_top_hat(image_t *img, int ksize, int threshold, image_t *mask) {

View File

@ -34,6 +34,10 @@ void imlib_deinit_all() {
#endif
}
int imlib_ksize_to_n(int ksize) {
return ((ksize * 2) + 1) * ((ksize * 2) + 1);
}
/////////////////
// Point Stuff //
/////////////////

View File

@ -101,6 +101,8 @@
#define IM_DEG2RAD(x) (((x) * M_PI) / 180)
#define IM_RAD2DEG(x) (((x) * 180) / M_PI)
int imlib_ksize_to_n(int ksize);
/////////////////
// Point Stuff //
/////////////////

View File

@ -441,10 +441,6 @@ int py_helper_arg_to_ksize(const mp_obj_t arg) {
return ksize;
}
int py_helper_ksize_to_n(int ksize) {
return ((ksize * 2) + 1) * ((ksize * 2) + 1);
}
mp_obj_t py_helper_keyword_object(uint n_args, const mp_obj_t *args,
uint arg_index, mp_map_t *kw_args, mp_obj_t kw, mp_obj_t default_val) {
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);

View File

@ -58,7 +58,6 @@ void py_helper_arg_to_thresholds(const mp_obj_t arg, list_t *thresholds);
void py_helper_keyword_thresholds(uint n_args, const mp_obj_t *args, uint arg_index,
mp_map_t *kw_args, list_t *thresholds);
int py_helper_arg_to_ksize(const mp_obj_t arg);
int py_helper_ksize_to_n(int ksize);
mp_obj_t py_helper_keyword_object(uint n_args, const mp_obj_t *args,
uint arg_index, mp_map_t *kw_args, mp_obj_t kw, mp_obj_t default_val);
const uint16_t *py_helper_keyword_color_palette(uint n_args, const mp_obj_t *args,

View File

@ -2123,7 +2123,7 @@ STATIC mp_obj_t py_image_erode(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
py_helper_arg_to_ksize(args[1]);
int arg_threshold =
py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold),
py_helper_ksize_to_n(arg_ksize) - 1);
imlib_ksize_to_n(arg_ksize) - 1);
image_t *arg_msk =
py_helper_keyword_to_image(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_mask), NULL);
@ -2607,7 +2607,7 @@ STATIC mp_obj_t py_image_morph(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
int arg_ksize =
py_helper_arg_to_ksize(args[1]);
int n = py_helper_ksize_to_n(arg_ksize);
int n = imlib_ksize_to_n(arg_ksize);
mp_obj_t *krn;
mp_obj_get_array_fixed_n(args[2], n, &krn);