Browse Source

samples: video: capture_to_lvgl: add crop/compose support

Demonstrate the crop/compose API by introducing 4 new
CONFIG options in order to define the crop area.
Moreover, if the selection API is available and if
the targetted size is different from the current crop
size, then try to apply a compose in order to reach
the targetted format size.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
pull/85254/merge
Alain Volmat 1 week ago committed by Daniel DeGrasse
parent
commit
706895cc27
  1. 26
      samples/drivers/video/capture_to_lvgl/Kconfig
  2. 45
      samples/drivers/video/capture_to_lvgl/src/main.c

26
samples/drivers/video/capture_to_lvgl/Kconfig

@ -7,6 +7,32 @@ mainmenu "Video capture to LVGL sample application" @@ -7,6 +7,32 @@ mainmenu "Video capture to LVGL sample application"
menu "Video capture configuration"
config VIDEO_SOURCE_CROP_LEFT
int "Crop area left value"
default 0
help
Left value of the crop area within the video source.
config VIDEO_SOURCE_CROP_TOP
int "Crop area top value"
default 0
help
Top value of the crop area within the video source.
config VIDEO_SOURCE_CROP_WIDTH
int "Crop area width value"
default 0
help
Width value of the crop area within the video source.
If set to 0, the crop is not applied.
config VIDEO_SOURCE_CROP_HEIGHT
int "Crop area height value"
default 0
help
Height value of the crop area within the video source.
If set to 0, the crop is not applied.
config VIDEO_WIDTH
int "Define the width of the video"
default 320

45
samples/drivers/video/capture_to_lvgl/src/main.c

@ -31,8 +31,12 @@ int main(void) @@ -31,8 +31,12 @@ int main(void)
struct video_format fmt;
struct video_caps caps;
enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT;
struct video_selection sel = {
.type = VIDEO_BUF_TYPE_OUTPUT,
};
size_t bsize;
int i = 0;
int err;
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
@ -74,11 +78,50 @@ int main(void) @@ -74,11 +78,50 @@ int main(void)
return 0;
}
/* Set the crop setting if necessary */
#if CONFIG_VIDEO_SOURCE_CROP_WIDTH && CONFIG_VIDEO_SOURCE_CROP_HEIGHT
sel.target = VIDEO_SEL_TGT_CROP;
sel.rect.left = CONFIG_VIDEO_SOURCE_CROP_LEFT;
sel.rect.top = CONFIG_VIDEO_SOURCE_CROP_TOP;
sel.rect.width = CONFIG_VIDEO_SOURCE_CROP_WIDTH;
sel.rect.height = CONFIG_VIDEO_SOURCE_CROP_HEIGHT;
if (video_set_selection(video_dev, &sel)) {
LOG_ERR("Unable to set selection crop");
return 0;
}
LOG_INF("Selection crop set to (%u,%u)/%ux%u",
sel.rect.left, sel.rect.top, sel.rect.width, sel.rect.height);
#endif
/* Set format */
fmt.width = CONFIG_VIDEO_WIDTH;
fmt.height = CONFIG_VIDEO_HEIGHT;
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
/*
* Check (if possible) if targeted size is same as crop
* and if compose is necessary
*/
sel.target = VIDEO_SEL_TGT_CROP;
err = video_get_selection(video_dev, &sel);
if (err < 0 && err != -ENOSYS) {
LOG_ERR("Unable to get selection crop");
return 0;
}
if (err == 0 && (sel.rect.width != fmt.width || sel.rect.height != fmt.height)) {
sel.target = VIDEO_SEL_TGT_COMPOSE;
sel.rect.left = 0;
sel.rect.top = 0;
sel.rect.width = fmt.width;
sel.rect.height = fmt.height;
err = video_set_selection(video_dev, &sel);
if (err < 0 && err != -ENOSYS) {
LOG_ERR("Unable to set selection compose");
return 0;
}
}
if (video_set_format(video_dev, &fmt)) {
LOG_ERR("Unable to set up video format");
return 0;
@ -142,8 +185,6 @@ int main(void) @@ -142,8 +185,6 @@ int main(void)
/* Grab video frames */
vbuf->type = type;
while (1) {
int err;
err = video_dequeue(video_dev, &vbuf, K_FOREVER);
if (err) {
LOG_ERR("Unable to dequeue video buf");

Loading…
Cancel
Save