mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #438 from openmv/use_stdint
Use stdint in color conversion functions.
This commit is contained in:
commit
0224693d63
@ -6493,15 +6493,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_imagereader_obj, py_image_imagereader)
|
||||
|
||||
mp_obj_t py_image_binary_to_grayscale(mp_obj_t arg)
|
||||
{
|
||||
char b = mp_obj_get_int(arg) & 1;
|
||||
int8_t b = mp_obj_get_int(arg) & 1;
|
||||
return mp_obj_new_int(COLOR_BINARY_TO_GRAYSCALE(b));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_binary_to_grayscale_obj, py_image_binary_to_grayscale);
|
||||
|
||||
mp_obj_t py_image_binary_to_rgb(mp_obj_t arg)
|
||||
{
|
||||
char b = mp_obj_get_int(arg) & 1;
|
||||
int rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
int8_t b = mp_obj_get_int(arg) & 1;
|
||||
uint16_t rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_R8(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_G8(rgb565)),
|
||||
@ -6511,8 +6511,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_binary_to_rgb_obj, py_image_binary_to_
|
||||
|
||||
mp_obj_t py_image_binary_to_lab(mp_obj_t arg)
|
||||
{
|
||||
char b = mp_obj_get_int(arg) & 1;
|
||||
int rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
int8_t b = mp_obj_get_int(arg) & 1;
|
||||
uint16_t rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_L(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_A(rgb565)),
|
||||
@ -6522,8 +6522,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_binary_to_lab_obj, py_image_binary_to_
|
||||
|
||||
mp_obj_t py_image_binary_to_yuv(mp_obj_t arg)
|
||||
{
|
||||
char b = mp_obj_get_int(arg) & 1;
|
||||
int rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
int8_t b = mp_obj_get_int(arg) & 1;
|
||||
uint16_t rgb565 = COLOR_BINARY_TO_RGB565(b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_Y(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_U(rgb565)),
|
||||
@ -6533,15 +6533,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_binary_to_yuv_obj, py_image_binary_to_
|
||||
|
||||
mp_obj_t py_image_grayscale_to_binary(mp_obj_t arg)
|
||||
{
|
||||
char g = mp_obj_get_int(arg) & 255;
|
||||
int8_t g = mp_obj_get_int(arg) & 255;
|
||||
return mp_obj_new_int(COLOR_GRAYSCALE_TO_BINARY(g));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_grayscale_to_binary_obj, py_image_grayscale_to_binary);
|
||||
|
||||
mp_obj_t py_image_grayscale_to_rgb(mp_obj_t arg)
|
||||
{
|
||||
char g = mp_obj_get_int(arg) & 255;
|
||||
int rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
int8_t g = mp_obj_get_int(arg) & 255;
|
||||
uint16_t rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_R8(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_G8(rgb565)),
|
||||
@ -6551,8 +6551,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_grayscale_to_rgb_obj, py_image_graysca
|
||||
|
||||
mp_obj_t py_image_grayscale_to_lab(mp_obj_t arg)
|
||||
{
|
||||
char g = mp_obj_get_int(arg) & 255;
|
||||
int rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
int8_t g = mp_obj_get_int(arg) & 255;
|
||||
uint16_t rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_L(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_A(rgb565)),
|
||||
@ -6562,8 +6562,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_grayscale_to_lab_obj, py_image_graysca
|
||||
|
||||
mp_obj_t py_image_grayscale_to_yuv(mp_obj_t arg)
|
||||
{
|
||||
char g = mp_obj_get_int(arg) & 255;
|
||||
int rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
int8_t g = mp_obj_get_int(arg) & 255;
|
||||
uint16_t rgb565 = COLOR_GRAYSCALE_TO_RGB565(g);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_Y(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_U(rgb565)),
|
||||
@ -6575,10 +6575,10 @@ mp_obj_t py_image_rgb_to_binary(uint n_args, const mp_obj_t *args, mp_map_t *kw_
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
int r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
int g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
uint8_t r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
uint8_t g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
uint8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_BINARY(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_rgb_to_binary_obj, 1, py_image_rgb_to_binary);
|
||||
@ -6587,10 +6587,10 @@ mp_obj_t py_image_rgb_to_grayscale(uint n_args, const mp_obj_t *args, mp_map_t *
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
int r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
int g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
uint8_t r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
uint8_t g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
uint8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_GRAYSCALE(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_rgb_to_grayscale_obj, 1, py_image_rgb_to_grayscale);
|
||||
@ -6599,10 +6599,10 @@ mp_obj_t py_image_rgb_to_lab(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
int r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
int g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
uint8_t r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
uint8_t g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
uint8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_L(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_A(rgb565)),
|
||||
@ -6614,10 +6614,10 @@ mp_obj_t py_image_rgb_to_yuv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
int r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
int g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
uint8_t r = mp_obj_get_int(arg_vec[0]) & 255;
|
||||
uint8_t g = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
uint8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_R8_G8_B8_TO_RGB565(r, g, b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_Y(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_U(rgb565)),
|
||||
@ -6629,10 +6629,10 @@ mp_obj_t py_image_lab_to_binary(uint n_args, const mp_obj_t *args, mp_map_t *kw_
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
char a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
int8_t l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
int8_t a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_BINARY(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_lab_to_binary_obj, 1, py_image_lab_to_binary);
|
||||
@ -6641,10 +6641,10 @@ mp_obj_t py_image_lab_to_grayscale(uint n_args, const mp_obj_t *args, mp_map_t *
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
char a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
int8_t l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
int8_t a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_GRAYSCALE(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_lab_to_grayscale_obj, 1, py_image_lab_to_grayscale);
|
||||
@ -6653,10 +6653,10 @@ mp_obj_t py_image_lab_to_rgb(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
char a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
int8_t l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
int8_t a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_R8(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_G8(rgb565)),
|
||||
@ -6668,10 +6668,10 @@ mp_obj_t py_image_lab_to_yuv(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
char a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
int8_t l = (mp_obj_get_int(arg_vec[0]) & 255) % 100;
|
||||
int8_t a = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t b = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_LAB_TO_RGB565(l, a, b);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_Y(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_U(rgb565)),
|
||||
@ -6683,10 +6683,10 @@ mp_obj_t py_image_yuv_to_binary(uint n_args, const mp_obj_t *args, mp_map_t *kw_
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
char u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
int8_t y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
int8_t u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_BINARY(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_yuv_to_binary_obj, 1, py_image_yuv_to_binary);
|
||||
@ -6695,10 +6695,10 @@ mp_obj_t py_image_yuv_to_grayscale(uint n_args, const mp_obj_t *args, mp_map_t *
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
char u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
int8_t y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
int8_t u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
return mp_obj_new_int(COLOR_RGB565_TO_GRAYSCALE(rgb565));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_yuv_to_grayscale_obj, 1, py_image_yuv_to_grayscale);
|
||||
@ -6707,10 +6707,10 @@ mp_obj_t py_image_yuv_to_rgb(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
char u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
int8_t y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
int8_t u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_R8(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_G8(rgb565)),
|
||||
@ -6722,10 +6722,10 @@ mp_obj_t py_image_yuv_to_lab(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
||||
{
|
||||
const mp_obj_t *arg_vec;
|
||||
py_helper_consume_array(n_args, args, 0, 3, &arg_vec);
|
||||
char y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
char u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
char v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
int rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
int8_t y = (mp_obj_get_int(arg_vec[0]) & 255) - 128;
|
||||
int8_t u = mp_obj_get_int(arg_vec[1]) & 255;
|
||||
int8_t v = mp_obj_get_int(arg_vec[2]) & 255;
|
||||
uint16_t rgb565 = COLOR_YUV_TO_RGB565(y, u, v);
|
||||
return mp_obj_new_tuple(3, (mp_obj_t[3])
|
||||
{mp_obj_new_int(COLOR_RGB565_TO_L(rgb565)),
|
||||
mp_obj_new_int(COLOR_RGB565_TO_A(rgb565)),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user