Skip to content

Commit 1942cd2

Browse files
author
Alain Volmat
committed
video: introduce video_set_compose_format helper
Some devices allow for downscale / upscale via the set_selection compose API. When using it, it is necessary to perform a set_selection of the compose target prior to setting the format. In order to allow non-compose aware application to benefit from it, introduce a helper which take care of setting the compose prior to setting the format. Signed-off-by: Alain Volmat <[email protected]>
1 parent b91b0e7 commit 1942cd2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/video/video_common.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,24 @@ int video_estimate_fmt_size(struct video_format *fmt)
468468

469469
return 0;
470470
}
471+
472+
int video_set_compose_format(const struct device *dev, struct video_format *fmt)
473+
{
474+
struct video_selection sel = {
475+
.type = fmt->type,
476+
.target = VIDEO_SEL_TGT_COMPOSE,
477+
.rect.left = 0,
478+
.rect.top = 0,
479+
.rect.width = fmt->width,
480+
.rect.height = fmt->height,
481+
};
482+
int ret;
483+
484+
ret = video_set_selection(dev, &sel);
485+
if (ret < 0 && ret != -ENOSYS) {
486+
LOG_ERR("Unable to set selection compose");
487+
return ret;
488+
}
489+
490+
return video_set_format(dev, fmt);
491+
}

include/zephyr/drivers/video.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,27 @@ int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t l
982982
*/
983983
int video_estimate_fmt_size(struct video_format *fmt);
984984

985+
/**
986+
* @brief Set compose rectangle (if applicable) prior to setting format
987+
*
988+
* Some devices expose compose capabilities, allowing them to apply a transformation
989+
* (downscale / upscale) to the frame. For those devices, it is necessary to set the
990+
* compose rectangle before being able to apply the frame format (which must have the
991+
* same width / height as the compose rectangle width / height).
992+
* In order to allow non-compose aware application to be able to control such devices,
993+
* introduce a helper which, if available, will apply the compose rectangle prior to
994+
* setting the format.
995+
*
996+
* @param dev Pointer to the video device struct to set format
997+
* @param fmt Pointer to a video format struct.
998+
*
999+
* @retval 0 Is successful.
1000+
* @retval -EINVAL If parameters are invalid.
1001+
* @retval -ENOTSUP If format is not supported.
1002+
* @retval -EIO General input / output error.
1003+
*/
1004+
int video_set_compose_format(const struct device *dev, struct video_format *fmt);
1005+
9851006
/**
9861007
* @defgroup video_pixel_formats Video pixel formats
9871008
* The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.

0 commit comments

Comments
 (0)