mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
drivers: Refactor framebuffer API to accept a context.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
71689c4a4f
commit
e8fe828667
@ -143,13 +143,13 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
|
||||
int num_pixels = resolution[boson_framesize][0] * resolution[boson_framesize][1];
|
||||
|
||||
if (csi->color_palette && (framebuffer_get_buffer_size() >= (num_pixels * sizeof(uint16_t)))) {
|
||||
if (csi->color_palette && (framebuffer_get_buffer_size(csi->fb) >= (num_pixels * sizeof(uint16_t)))) {
|
||||
for (int32_t i = num_pixels - 1; i >= 0; i--) {
|
||||
((uint16_t *) image->data)[i] = csi->color_palette[image->data[i]];
|
||||
}
|
||||
|
||||
image->pixfmt = PIXFORMAT_RGB565;
|
||||
MAIN_FB()->pixfmt = PIXFORMAT_RGB565;
|
||||
csi->fb->pixfmt = PIXFORMAT_RGB565;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -244,7 +244,7 @@ static int set_framerate(omv_csi_t *csi, int framerate) {
|
||||
}
|
||||
|
||||
// Disable any ongoing frame capture.
|
||||
omv_csi_abort(true, false);
|
||||
omv_csi_abort(csi, true, false);
|
||||
|
||||
psee_sensor_write(EHC_INTEGRATION_PERIOD, us);
|
||||
psee_sensor_write(CPI_PACKET_TIME_CONTROL, ACTIVE_SENSOR_WIDTH << CPI_PACKET_TIME_CONTROL_PERIOD_Pos |
|
||||
@ -345,7 +345,7 @@ static void disable_hot_pixels(uint8_t *histogram) {
|
||||
}
|
||||
#endif // (OMV_GENX320_CAL_ENABLE == 1)
|
||||
|
||||
static void snapshot_post_process(image_t *image) {
|
||||
static void snapshot_post_process(omv_csi_t *csi, image_t *image) {
|
||||
#if (OMV_GENX320_EHC_ENABLE == 1)
|
||||
for (uint32_t i = 0; i < ACTIVE_SENSOR_SIZE; i++) {
|
||||
image->data[i] = __USAT((((int8_t *) image->data)[i] * contrast) + brightness, UINT8_T_BITS);
|
||||
@ -383,12 +383,13 @@ static void snapshot_post_process(image_t *image) {
|
||||
fb_free();
|
||||
#endif // (OMV_GENX320_EHC_ENABLE == 1)
|
||||
|
||||
if (csi.color_palette && (framebuffer_get_buffer_size() >= (ACTIVE_SENSOR_SIZE * sizeof(uint16_t)))) {
|
||||
if (csi->color_palette &&
|
||||
(framebuffer_get_buffer_size(csi->fb) >= (ACTIVE_SENSOR_SIZE * sizeof(uint16_t)))) {
|
||||
for (int32_t i = ACTIVE_SENSOR_SIZE - 1; i >= 0; i--) {
|
||||
((uint16_t *) image->data)[i] = csi.color_palette[image->data[i]];
|
||||
((uint16_t *) image->data)[i] = csi->color_palette[image->data[i]];
|
||||
}
|
||||
image->pixfmt = PIXFORMAT_RGB565;
|
||||
MAIN_FB()->pixfmt = PIXFORMAT_RGB565;
|
||||
csi->fb->pixfmt = PIXFORMAT_RGB565;
|
||||
}
|
||||
}
|
||||
|
||||
@ -440,7 +441,7 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
}
|
||||
#endif // (OMV_GENX320_EHC_ENABLE == 1)
|
||||
|
||||
snapshot_post_process(image);
|
||||
snapshot_post_process(csi, image);
|
||||
}
|
||||
|
||||
disable_hot_pixels(histogram);
|
||||
@ -456,7 +457,7 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
snapshot_post_process(image);
|
||||
snapshot_post_process(csi, image);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -380,10 +380,11 @@ static int reset(omv_csi_t *csi) {
|
||||
}
|
||||
|
||||
static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
framebuffer_update_jpeg_buffer();
|
||||
framebuffer_t *fb = csi->fb;
|
||||
framebuffer_update_jpeg_buffer(fb);
|
||||
|
||||
if (MAIN_FB()->n_buffers != 1) {
|
||||
framebuffer_set_buffers(1);
|
||||
if (fb->n_buffers != 1) {
|
||||
framebuffer_set_buffers(fb, 1);
|
||||
}
|
||||
|
||||
if (csi->pixformat == PIXFORMAT_INVALID) {
|
||||
@ -402,8 +403,8 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
return OMV_CSI_ERROR_FRAMEBUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
framebuffer_free_current_buffer();
|
||||
vbuffer_t *buffer = framebuffer_get_tail(FB_NO_FLAGS);
|
||||
framebuffer_free_current_buffer(fb);
|
||||
vbuffer_t *buffer = framebuffer_get_tail(fb, FB_NO_FLAGS);
|
||||
|
||||
if (!buffer) {
|
||||
return OMV_CSI_ERROR_FRAMEBUFFER_ERROR;
|
||||
@ -422,11 +423,11 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
}
|
||||
}
|
||||
|
||||
MAIN_FB()->w = MAIN_FB()->u;
|
||||
MAIN_FB()->h = MAIN_FB()->v;
|
||||
MAIN_FB()->pixfmt = csi->pixformat;
|
||||
fb->w = fb->u;
|
||||
fb->h = fb->v;
|
||||
fb->pixfmt = csi->pixformat;
|
||||
|
||||
framebuffer_init_image(image);
|
||||
framebuffer_init_image(fb, image);
|
||||
|
||||
float x_scale = resolution[csi->framesize][0] / ((float) lepton.h_res);
|
||||
float y_scale = resolution[csi->framesize][1] / ((float) lepton.v_res);
|
||||
@ -445,13 +446,13 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
}
|
||||
|
||||
for (int y = y_offset, yy = fast_ceilf(lepton.v_res * scale) + y_offset; y < yy; y++) {
|
||||
if ((MAIN_FB()->y <= y) && (y < (MAIN_FB()->y + MAIN_FB()->v))) {
|
||||
if ((fb->y <= y) && (y < (fb->y + fb->v))) {
|
||||
// user window cropping
|
||||
|
||||
uint16_t *row_ptr = _vospi_buf + (fast_floorf(y * scale_inv) * lepton.h_res);
|
||||
|
||||
for (int x = x_offset, xx = fast_ceilf(lepton.h_res * scale) + x_offset; x < xx; x++) {
|
||||
if ((MAIN_FB()->x <= x) && (x < (MAIN_FB()->x + MAIN_FB()->u))) {
|
||||
if ((fb->x <= x) && (x < (fb->x + fb->u))) {
|
||||
// user window cropping
|
||||
|
||||
// Value is the 14/16-bit value from the FLIR IR camera.
|
||||
@ -469,14 +470,14 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
(lepton.max_temp - lepton.min_temp)), 8);
|
||||
}
|
||||
|
||||
int t_x = x - MAIN_FB()->x;
|
||||
int t_y = y - MAIN_FB()->y;
|
||||
int t_x = x - fb->x;
|
||||
int t_y = y - fb->y;
|
||||
|
||||
if (lepton.hmirror) {
|
||||
t_x = MAIN_FB()->u - t_x - 1;
|
||||
t_x = fb->u - t_x - 1;
|
||||
}
|
||||
if (lepton.vflip) {
|
||||
t_y = MAIN_FB()->v - t_y - 1;
|
||||
t_y = fb->v - t_y - 1;
|
||||
}
|
||||
|
||||
switch (csi->pixformat) {
|
||||
|
@ -62,17 +62,16 @@ static int set_vflip(omv_csi_t *csi, int enable) {
|
||||
}
|
||||
|
||||
static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
uint32_t w = MAIN_FB()->u;
|
||||
uint32_t h = MAIN_FB()->v;
|
||||
framebuffer_t *fb = csi->fb;
|
||||
|
||||
if (!image) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
framebuffer_update_jpeg_buffer();
|
||||
framebuffer_update_jpeg_buffer(fb);
|
||||
|
||||
if (MAIN_FB()->n_buffers != 1) {
|
||||
framebuffer_set_buffers(1);
|
||||
if (fb->n_buffers != 1) {
|
||||
framebuffer_set_buffers(fb, 1);
|
||||
}
|
||||
|
||||
if (csi->pixformat == PIXFORMAT_INVALID) {
|
||||
@ -87,24 +86,23 @@ static int snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
return OMV_CSI_ERROR_FRAMEBUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
framebuffer_free_current_buffer();
|
||||
vbuffer_t *buffer = framebuffer_get_tail(FB_NO_FLAGS);
|
||||
framebuffer_free_current_buffer(fb);
|
||||
vbuffer_t *buffer = framebuffer_get_tail(fb, FB_NO_FLAGS);
|
||||
|
||||
if (!buffer) {
|
||||
return OMV_CSI_ERROR_FRAMEBUFFER_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if (!csi->transpose) {
|
||||
MAIN_FB()->w = w;
|
||||
MAIN_FB()->h = h;
|
||||
fb->w = fb->u;
|
||||
fb->h = fb->v;
|
||||
} else {
|
||||
MAIN_FB()->w = h;
|
||||
MAIN_FB()->h = w;
|
||||
fb->w = fb->v;
|
||||
fb->h = fb->u;
|
||||
}
|
||||
|
||||
MAIN_FB()->pixfmt = csi->pixformat;
|
||||
framebuffer_init_image(image);
|
||||
fb->pixfmt = csi->pixformat;
|
||||
framebuffer_init_image(fb, image);
|
||||
|
||||
static uint32_t step = 0;
|
||||
uint32_t offset = (step / 4);
|
||||
|
Loading…
Reference in New Issue
Block a user