mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Move helper functions to new files.
This commit is contained in:
parent
0f48c12a89
commit
5860695f5d
@ -152,6 +152,7 @@ OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\
|
||||
)
|
||||
|
||||
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/, \
|
||||
py_helper.o \
|
||||
py_sensor.o \
|
||||
py_image.o \
|
||||
py_time.o \
|
||||
|
||||
@ -55,6 +55,7 @@ SRCS += $(addprefix img/, \
|
||||
)
|
||||
|
||||
SRCS += $(addprefix py/, \
|
||||
py_helper.c \
|
||||
py_sensor.c \
|
||||
py_image.c \
|
||||
py_time.c \
|
||||
|
||||
62
src/omv/py/py_helper.c
Normal file
62
src/omv/py/py_helper.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include "mp.h"
|
||||
#include "imlib.h"
|
||||
#include "py_helper.h"
|
||||
|
||||
int get_int_kw(mp_map_t *kw_args, mp_obj_t kw, int default_val)
|
||||
{
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg != NULL) {
|
||||
default_val = mp_obj_get_int(kw_arg->value);
|
||||
}
|
||||
return default_val;
|
||||
}
|
||||
|
||||
float get_float_kw(mp_map_t *kw_args, mp_obj_t kw, float default_val)
|
||||
{
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg != NULL) {
|
||||
default_val = mp_obj_get_float(kw_arg->value);
|
||||
}
|
||||
return default_val;
|
||||
}
|
||||
|
||||
int get_color_kw(mp_map_t *kw_args, int default_color)
|
||||
{
|
||||
mp_map_elem_t *kw_color = mp_map_lookup(kw_args,
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_color), MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_color != NULL) {
|
||||
if (mp_obj_is_integer(kw_color->value)) {
|
||||
default_color = mp_obj_get_int(kw_color->value);
|
||||
} else {
|
||||
mp_obj_t *arg_color;
|
||||
mp_obj_get_array_fixed_n(kw_color->value, 3, &arg_color);
|
||||
default_color = IM_RGB565(IM_R825(mp_obj_get_int(arg_color[0])),
|
||||
IM_G826(mp_obj_get_int(arg_color[1])),
|
||||
IM_B825(mp_obj_get_int(arg_color[2])));
|
||||
}
|
||||
}
|
||||
return default_color;
|
||||
}
|
||||
|
||||
void get_rectangle_kw(mp_map_t *kw_args, image_t *img, rectangle_t *r)
|
||||
{
|
||||
mp_map_elem_t *kw_rectangle = mp_map_lookup(kw_args,
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_roi), MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_rectangle == NULL) {
|
||||
r->x = 0;
|
||||
r->y = 0;
|
||||
r->w = img->w;
|
||||
r->h = img->h;
|
||||
} else {
|
||||
mp_obj_t *arg_rectangle;
|
||||
mp_obj_get_array_fixed_n(kw_rectangle->value, 4, &arg_rectangle);
|
||||
r->x = mp_obj_get_int(arg_rectangle[0]);
|
||||
r->y = mp_obj_get_int(arg_rectangle[1]);
|
||||
r->w = mp_obj_get_int(arg_rectangle[2]);
|
||||
r->h = mp_obj_get_int(arg_rectangle[3]);
|
||||
}
|
||||
}
|
||||
15
src/omv/py/py_helper.h
Normal file
15
src/omv/py/py_helper.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* MicroPython helper functions.
|
||||
*
|
||||
*/
|
||||
#ifndef __PY_HELPER_H__
|
||||
#define __PY_HELPER_H__
|
||||
int get_int_kw(mp_map_t *kw_args, mp_obj_t kw, int default_val);
|
||||
float get_float_kw(mp_map_t *kw_args, mp_obj_t kw, float default_val);
|
||||
int get_color_kw(mp_map_t *kw_args, int default_color);
|
||||
void get_rectangle_kw(mp_map_t *kw_args, image_t *img, rectangle_t *r);
|
||||
#endif // __PY_HELPER__
|
||||
@ -12,9 +12,10 @@
|
||||
#include "sensor.h"
|
||||
#include "ff.h"
|
||||
#include "xalloc.h"
|
||||
#include "py_assert.h"
|
||||
#include "py_image.h"
|
||||
#include "arm_math.h"
|
||||
#include "py_assert.h"
|
||||
#include "py_helper.h"
|
||||
#include "py_image.h"
|
||||
#include "omv_boardconfig.h"
|
||||
|
||||
#define JPEG_INIT_BUF (5*1024)
|
||||
@ -156,69 +157,6 @@ static mp_obj_t py_image_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t va
|
||||
}
|
||||
}
|
||||
|
||||
// Start Helper Functions /////////////////////////////////////////////////////
|
||||
|
||||
static int get_int_kw(mp_map_t *kw_args, mp_obj_t kw, int default_val)
|
||||
{
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg != NULL) {
|
||||
default_val = mp_obj_get_int(kw_arg->value);
|
||||
}
|
||||
return default_val;
|
||||
}
|
||||
|
||||
static float get_float_kw(mp_map_t *kw_args, mp_obj_t kw, float default_val)
|
||||
{
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg != NULL) {
|
||||
default_val = mp_obj_get_float(kw_arg->value);
|
||||
}
|
||||
return default_val;
|
||||
}
|
||||
|
||||
static int get_color_kw(mp_map_t *kw_args, int default_color)
|
||||
{
|
||||
mp_map_elem_t *kw_color = mp_map_lookup(kw_args,
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_color), MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_color != NULL) {
|
||||
if (mp_obj_is_integer(kw_color->value)) {
|
||||
default_color = mp_obj_get_int(kw_color->value);
|
||||
} else {
|
||||
mp_obj_t *arg_color;
|
||||
mp_obj_get_array_fixed_n(kw_color->value, 3, &arg_color);
|
||||
default_color = IM_RGB565(IM_R825(mp_obj_get_int(arg_color[0])),
|
||||
IM_G826(mp_obj_get_int(arg_color[1])),
|
||||
IM_B825(mp_obj_get_int(arg_color[2])));
|
||||
}
|
||||
}
|
||||
return default_color;
|
||||
}
|
||||
|
||||
static void get_rectangle_kw(mp_map_t *kw_args, image_t *img, rectangle_t *r)
|
||||
{
|
||||
mp_map_elem_t *kw_rectangle = mp_map_lookup(kw_args,
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_roi), MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_rectangle == NULL) {
|
||||
r->x = 0;
|
||||
r->y = 0;
|
||||
r->w = img->w;
|
||||
r->h = img->h;
|
||||
} else {
|
||||
mp_obj_t *arg_rectangle;
|
||||
mp_obj_get_array_fixed_n(kw_rectangle->value, 4, &arg_rectangle);
|
||||
r->x = mp_obj_get_int(arg_rectangle[0]);
|
||||
r->y = mp_obj_get_int(arg_rectangle[1]);
|
||||
r->w = mp_obj_get_int(arg_rectangle[2]);
|
||||
r->h = mp_obj_get_int(arg_rectangle[3]);
|
||||
}
|
||||
}
|
||||
|
||||
// End Helper Functions ///////////////////////////////////////////////////////
|
||||
|
||||
static mp_obj_t py_image_width(mp_obj_t img_obj)
|
||||
{
|
||||
image_t *arg_img = py_image_cobj(img_obj);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user