From f7e691e3906a19035df74e168bc4ebaa35a0a8dd Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 27 Apr 2018 02:01:23 +0200 Subject: [PATCH] Remove line_filter function. --- src/omv/lepton.c | 2 +- src/omv/py/py_sensor.c | 39 +++------------------------------------ src/omv/py/qstrdefsomv.h | 1 - src/omv/sensor.c | 16 +--------------- src/omv/sensor.h | 13 ++----------- 5 files changed, 7 insertions(+), 64 deletions(-) diff --git a/src/omv/lepton.c b/src/omv/lepton.c index 3dd7b995b..647bd12e4 100644 --- a/src/omv/lepton.c +++ b/src/omv/lepton.c @@ -285,7 +285,7 @@ static int set_lens_correction(sensor_t *sensor, int enable, int radi, int coef) return 0; } -static int snapshot(sensor_t *sensor, image_t *image, line_filter_t line_filter_func, void *line_filter_args) +static int snapshot(sensor_t *sensor, image_t *image) { if ((!h_res) || (!v_res) || (!sensor->framesize) || (!sensor->pixformat)) { return -1; diff --git a/src/omv/py/py_sensor.c b/src/omv/py/py_sensor.c index 2e9ec6861..c97092267 100644 --- a/src/omv/py/py_sensor.c +++ b/src/omv/py/py_sensor.c @@ -38,47 +38,14 @@ static mp_obj_t py_sensor_flush() { return mp_const_none; } -/* - * Filter functions bypass the default line processing in sensor.c, and pre-process lines before anything else. - * Processing is done on the fly, i.e. line filters are called from sensor_snapshot after each line is readout. - * -* - * Note2: This double indirection is to decouple omv/img code from omv/py code as much as possible. - */ -static void py_line_filter(uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, void *args) -{ - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_call_function_2((mp_obj_t) args, // Callback function - mp_obj_new_bytearray_by_ref(src_stride, src), // Source line buffer - mp_obj_new_bytearray_by_ref(dst_stride, dst)); // Destination line buffer - nlr_pop(); - } else { - // Uncaught exception; disable the callback so it doesn't run again. - sensor_set_line_filter(NULL, NULL); - mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); - } -} - static mp_obj_t py_sensor_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { // Snapshot image mp_obj_t image = py_image(0, 0, 0, 0); - // Line pre-processing function and args - mp_obj_t line_filter_args = NULL; - line_filter_t line_filter_func = NULL; - // Sanity checks PY_ASSERT_TRUE_MSG((sensor.pixformat != PIXFORMAT_JPEG), "Operation not supported on JPEG"); - // Lookup filter function - mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_line_filter), MP_MAP_LOOKUP); - if (kw_arg != NULL) { - line_filter_args = kw_arg->value; - line_filter_func = py_line_filter; - } - - if (sensor.snapshot(&sensor, (struct image*) py_image_cobj(image), line_filter_func, line_filter_args)==-1) { + if (sensor.snapshot(&sensor, (image_t*) py_image_cobj(image))==-1) { nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!")); return mp_const_false; } @@ -99,7 +66,7 @@ static mp_obj_t py_sensor_skip_frames(uint n_args, const mp_obj_t *args, mp_map_ if (!n_args) { while ((systick_current_millis() - millis) < time) { // 32-bit math handles wrap arrounds... - if (sensor.snapshot(&sensor, NULL, NULL, NULL) == -1) { + if (sensor.snapshot(&sensor, NULL) == -1) { nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!")); } } @@ -109,7 +76,7 @@ static mp_obj_t py_sensor_skip_frames(uint n_args, const mp_obj_t *args, mp_map_ break; } - if (sensor.snapshot(&sensor, NULL, NULL, NULL) == -1) { + if (sensor.snapshot(&sensor, NULL) == -1) { nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!")); } } diff --git a/src/omv/py/qstrdefsomv.h b/src/omv/py/qstrdefsomv.h index cdb405172..7ea663bf7 100644 --- a/src/omv/py/qstrdefsomv.h +++ b/src/omv/py/qstrdefsomv.h @@ -131,7 +131,6 @@ Q(OV2640) Q(OV7725) Q(MT9V034) Q(LEPTON) -Q(line_filter) Q(value) // C/SIF Resolutions diff --git a/src/omv/sensor.c b/src/omv/sensor.c index 779e4fa54..b7233ec26 100644 --- a/src/omv/sensor.c +++ b/src/omv/sensor.c @@ -370,9 +370,6 @@ int sensor_reset() sensor.gainceiling = 0; sensor.vsync_gpio = NULL; - // Reset image filter - sensor_set_line_filter(NULL, NULL); - // Call sensor-specific reset function if (sensor.reset(&sensor) != 0) { return -1; @@ -693,14 +690,6 @@ int sensor_set_lens_correction(int enable, int radi, int coef) return 0; } -int sensor_set_line_filter(line_filter_t line_filter_func, void *line_filter_args) -{ - // Set line pre-processing function and args - sensor.line_filter_func = line_filter_func; - sensor.line_filter_args = line_filter_args; - return 0; -} - int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin) { sensor.vsync_pin = pin; @@ -803,7 +792,7 @@ void DCMI_DMAConvCpltUser(uint32_t addr) // This is the default snapshot function, which can be replaced in sensor_init functions. This function // uses the DCMI and DMA to capture frames and each line is processed in the DCMI_DMAConvCpltUser function. -int sensor_snapshot(sensor_t *sensor, image_t *image, line_filter_t line_filter_func, void *line_filter_args) +int sensor_snapshot(sensor_t *sensor, image_t *image) { uint32_t addr, length, tick_start; @@ -828,9 +817,6 @@ int sensor_snapshot(sensor_t *sensor, image_t *image, line_filter_t line_filter_ uint32_t w = resolution[sensor->framesize][0]; uint32_t h = resolution[sensor->framesize][1]; - // Set line filter function and args. - sensor_set_line_filter(line_filter_func, line_filter_args); - // Setup the size and address of the transfer switch (sensor->pixformat) { case PIXFORMAT_RGB565: diff --git a/src/omv/sensor.h b/src/omv/sensor.h index 5961f8205..cb152d82c 100644 --- a/src/omv/sensor.h +++ b/src/omv/sensor.h @@ -92,8 +92,6 @@ typedef enum { ACTIVE_HIGH } polarity_t; -typedef void (*line_filter_t) (uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, void *args); - #define SENSOR_HW_FLAGS_VSYNC (0) // vertical sync polarity. #define SENSOR_HW_FLAGS_HSYNC (1) // horizontal sync polarity. #define SENSOR_HW_FLAGS_PIXCK (2) // pixel clock edge. @@ -113,10 +111,6 @@ typedef struct _sensor { uint32_t vsync_pin; // VSYNC GPIO output pin. GPIO_TypeDef *vsync_gpio; // VSYNC GPIO output port. - // Line pre-processing function and args - void *line_filter_args; - line_filter_t line_filter_func; - polarity_t pwdn_pol; // PWDN polarity (TODO move to hw_flags) polarity_t reset_pol; // Reset polarity (TODO move to hw_flags) @@ -151,7 +145,7 @@ typedef struct _sensor { int (*set_vflip) (sensor_t *sensor, int enable); int (*set_special_effect) (sensor_t *sensor, sde_t sde); int (*set_lens_correction) (sensor_t *sensor, int enable, int radi, int coef); - int (*snapshot) (sensor_t *sensor, image_t *image, line_filter_t line_filter_func, void *line_filter_args); + int (*snapshot) (sensor_t *sensor, image_t *image); } sensor_t; // Resolution table @@ -239,12 +233,9 @@ int sensor_set_special_effect(sde_t sde); // Set lens shading correction int sensor_set_lens_correction(int enable, int radi, int coef); -// Set filter function. -int sensor_set_line_filter(line_filter_t line_filter_func, void *line_filter_args); - // Set vsync output pin int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin); // Default snapshot function. -int sensor_snapshot(sensor_t *sensor, image_t *image, line_filter_t line_filter_func, void *line_filter_args); +int sensor_snapshot(sensor_t *sensor, image_t *image); #endif /* __SENSOR_H__ */