Remove line_filter function.

This commit is contained in:
iabdalkader 2018-04-27 02:01:23 +02:00
parent 6c208b52c9
commit f7e691e390
5 changed files with 7 additions and 64 deletions

View File

@ -285,7 +285,7 @@ static int set_lens_correction(sensor_t *sensor, int enable, int radi, int coef)
return 0; 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)) { if ((!h_res) || (!v_res) || (!sensor->framesize) || (!sensor->pixformat)) {
return -1; return -1;

View File

@ -38,47 +38,14 @@ static mp_obj_t py_sensor_flush() {
return mp_const_none; 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) { static mp_obj_t py_sensor_snapshot(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// Snapshot image // Snapshot image
mp_obj_t image = py_image(0, 0, 0, 0); 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 // Sanity checks
PY_ASSERT_TRUE_MSG((sensor.pixformat != PIXFORMAT_JPEG), "Operation not supported on JPEG"); PY_ASSERT_TRUE_MSG((sensor.pixformat != PIXFORMAT_JPEG), "Operation not supported on JPEG");
// Lookup filter function if (sensor.snapshot(&sensor, (image_t*) py_image_cobj(image))==-1) {
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) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!")); nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!"));
return mp_const_false; 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) { if (!n_args) {
while ((systick_current_millis() - millis) < time) { // 32-bit math handles wrap arrounds... 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!!")); 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; 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!!")); nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!"));
} }
} }

View File

@ -131,7 +131,6 @@ Q(OV2640)
Q(OV7725) Q(OV7725)
Q(MT9V034) Q(MT9V034)
Q(LEPTON) Q(LEPTON)
Q(line_filter)
Q(value) Q(value)
// C/SIF Resolutions // C/SIF Resolutions

View File

@ -370,9 +370,6 @@ int sensor_reset()
sensor.gainceiling = 0; sensor.gainceiling = 0;
sensor.vsync_gpio = NULL; sensor.vsync_gpio = NULL;
// Reset image filter
sensor_set_line_filter(NULL, NULL);
// Call sensor-specific reset function // Call sensor-specific reset function
if (sensor.reset(&sensor) != 0) { if (sensor.reset(&sensor) != 0) {
return -1; return -1;
@ -693,14 +690,6 @@ int sensor_set_lens_correction(int enable, int radi, int coef)
return 0; 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) int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin)
{ {
sensor.vsync_pin = 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 // 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. // 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; 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 w = resolution[sensor->framesize][0];
uint32_t h = resolution[sensor->framesize][1]; 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 // Setup the size and address of the transfer
switch (sensor->pixformat) { switch (sensor->pixformat) {
case PIXFORMAT_RGB565: case PIXFORMAT_RGB565:

View File

@ -92,8 +92,6 @@ typedef enum {
ACTIVE_HIGH ACTIVE_HIGH
} polarity_t; } 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_VSYNC (0) // vertical sync polarity.
#define SENSOR_HW_FLAGS_HSYNC (1) // horizontal sync polarity. #define SENSOR_HW_FLAGS_HSYNC (1) // horizontal sync polarity.
#define SENSOR_HW_FLAGS_PIXCK (2) // pixel clock edge. #define SENSOR_HW_FLAGS_PIXCK (2) // pixel clock edge.
@ -113,10 +111,6 @@ typedef struct _sensor {
uint32_t vsync_pin; // VSYNC GPIO output pin. uint32_t vsync_pin; // VSYNC GPIO output pin.
GPIO_TypeDef *vsync_gpio; // VSYNC GPIO output port. 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 pwdn_pol; // PWDN polarity (TODO move to hw_flags)
polarity_t reset_pol; // Reset 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_vflip) (sensor_t *sensor, int enable);
int (*set_special_effect) (sensor_t *sensor, sde_t sde); int (*set_special_effect) (sensor_t *sensor, sde_t sde);
int (*set_lens_correction) (sensor_t *sensor, int enable, int radi, int coef); 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; } sensor_t;
// Resolution table // Resolution table
@ -239,12 +233,9 @@ int sensor_set_special_effect(sde_t sde);
// Set lens shading correction // Set lens shading correction
int sensor_set_lens_correction(int enable, int radi, int coef); 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 // Set vsync output pin
int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin); int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin);
// Default snapshot function. // 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__ */ #endif /* __SENSOR_H__ */