Skip to content

Commit 5e90e13

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 2ab24f9 commit 5e90e13

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

drivers/video/video_common.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,24 @@ int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t l
443443
/* CSI D-PHY is using a DDR data bus so bitrate is twice the frequency */
444444
return ctrl.val64 * bpp / (2 * lane_nb);
445445
}
446+
447+
int video_set_compose_format(const struct device *dev, struct video_format *fmt)
448+
{
449+
struct video_selection sel = {
450+
.type = fmt->type,
451+
.target = VIDEO_SEL_TGT_COMPOSE,
452+
.rect.left = 0,
453+
.rect.top = 0,
454+
.rect.width = fmt->width,
455+
.rect.height = fmt->height,
456+
};
457+
int ret;
458+
459+
ret = video_set_selection(dev, &sel);
460+
if (ret < 0 && ret != -ENOSYS) {
461+
LOG_ERR("Unable to set selection compose");
462+
return ret;
463+
}
464+
465+
return video_set_format(dev, fmt);
466+
}

include/zephyr/drivers/video.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,22 @@ void video_closest_frmival(const struct device *dev, struct video_frmival_enum *
988988
*/
989989
int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t lane_nb);
990990

991+
/**
992+
* @brief Set compose rectangle (if applicable) prior to setting format
993+
*
994+
* Some devices expose compose capabilities, allowing them to apply a transformation
995+
* (downscale / upscale) to the frame. For those devices, it is necessary to set the
996+
* compose rectangle before being able to apply the frame format (which must have the
997+
* same width / height and the compose rectangle width / height.
998+
* In order to allow non-compose aware application to be able to control such devices,
999+
* introduce a helper which, if available, will apply the compose rectangle prior to
1000+
* setting the format.
1001+
*
1002+
* @param dev Video device to query.
1003+
* @param fmt Video format structure pointer
1004+
*/
1005+
int video_set_compose_format(const struct device *dev, struct video_format *fmt);
1006+
9911007
/**
9921008
* @defgroup video_pixel_formats Video pixel formats
9931009
* The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.

0 commit comments

Comments
 (0)