Skip to content

Commit 60ee85c

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 b326eac commit 60ee85c

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
@@ -977,6 +977,22 @@ void video_closest_frmival(const struct device *dev, struct video_frmival_enum *
977977
*/
978978
int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t lane_nb);
979979

980+
/**
981+
* @brief Set compose rectangle (if applicable) prior to setting format
982+
*
983+
* Some devices expose compose capabilities, allowing them to apply a transformation
984+
* (downscale / upscale) to the frame. For those devices, it is necessary to set the
985+
* compose rectangle before being able to apply the frame format (which must have the
986+
* same width / height and the compose rectangle width / height.
987+
* In order to allow non-compose aware application to be able to control such devices,
988+
* introduce a helper which, if available, will apply the compose rectangle prior to
989+
* setting the format.
990+
*
991+
* @param dev Video device to query.
992+
* @param fmt Video format structure pointer
993+
*/
994+
int video_set_compose_format(const struct device *dev, struct video_format *fmt);
995+
980996
/**
981997
* @defgroup video_pixel_formats Video pixel formats
982998
* The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.

0 commit comments

Comments
 (0)