Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion drivers/video/gc2145.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,6 @@ static int gc2145_init(const struct device *dev)
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
fmt.width = RESOLUTION_QVGA_W;
fmt.height = RESOLUTION_QVGA_H;
fmt.pitch = RESOLUTION_QVGA_W * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;

ret = gc2145_set_fmt(dev, &fmt);
if (ret) {
Expand Down
1 change: 0 additions & 1 deletion drivers/video/mt9m114.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ static int mt9m114_init(const struct device *dev)
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
fmt.width = 480;
fmt.height = 272;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;

ret = mt9m114_set_fmt(dev, &fmt);
if (ret) {
Expand Down
1 change: 0 additions & 1 deletion drivers/video/ov2640.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,6 @@ static int ov2640_init(const struct device *dev)
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
fmt.width = SVGA_HSIZE;
fmt.height = SVGA_VSIZE;
fmt.pitch = SVGA_HSIZE * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
ret = ov2640_set_fmt(dev, &fmt);
if (ret) {
LOG_ERR("Unable to configure default format");
Expand Down
1 change: 0 additions & 1 deletion drivers/video/ov5640.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,6 @@ static int ov5640_init(const struct device *dev)
fmt.width = 1280;
fmt.height = 720;
}
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
ret = ov5640_set_fmt(dev, &fmt);
if (ret) {
LOG_ERR("Unable to configure default format");
Expand Down
1 change: 0 additions & 1 deletion drivers/video/ov7670.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ static int ov7670_init(const struct device *dev)
fmt.pixelformat = VIDEO_PIX_FMT_YUYV;
fmt.width = 640;
fmt.height = 480;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
ret = ov7670_set_fmt(dev, &fmt);
if (ret < 0) {
return ret;
Expand Down
1 change: 0 additions & 1 deletion drivers/video/ov7725.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ static int ov7725_init(const struct device *dev)
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
fmt.width = 640;
fmt.height = 480;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
ret = ov7725_set_fmt(dev, &fmt);
if (ret) {
LOG_ERR("Unable to configure default format");
Expand Down
1 change: 0 additions & 1 deletion drivers/video/video_emul_imager.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ int emul_imager_init(const struct device *dev)
fmt.pixelformat = fmts[0].pixelformat;
fmt.width = fmts[0].width_min;
fmt.height = fmts[0].height_min;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;

ret = emul_imager_set_fmt(dev, &fmt);
if (ret < 0) {
Expand Down
5 changes: 5 additions & 0 deletions drivers/video/video_emul_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ static int emul_rx_set_fmt(const struct device *const dev, struct video_format *
}

/* Cache the format selected locally to use it for getting the size of the buffer */
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
Copy link
Contributor

@josuah josuah May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small semantic change and I proposed a migration-guide entry here to avoid getting in the way of this PR:

This is not a breaking change, and a migration guide entry is only a hint for how to simplify applications after 4.2.

data->fmt = *fmt;

return 0;
}

Expand Down Expand Up @@ -216,6 +218,9 @@ int emul_rx_init(const struct device *dev)
return ret;
}

data->fmt.pitch =
data->fmt.width * video_bits_per_pixel(data->fmt.pixelformat) / BITS_PER_BYTE;

k_fifo_init(&data->fifo_in);
k_fifo_init(&data->fifo_out);
k_work_init(&data->work, &emul_rx_worker);
Expand Down
12 changes: 11 additions & 1 deletion drivers/video/video_esp32_dvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,31 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
return ret;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

return 0;
}

static int video_esp32_set_fmt(const struct device *dev, struct video_format *fmt)
{
const struct video_esp32_config *cfg = dev->config;
struct video_esp32_data *data = dev->data;
int ret;

if (fmt == NULL) {
return -EINVAL;
}

ret = video_set_format(cfg->source_dev, fmt);
if (ret < 0) {
return ret;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

data->video_format = *fmt;

return video_set_format(cfg->source_dev, fmt);
return 0;
}

static int video_esp32_enqueue(const struct device *dev, struct video_buffer *vbuf)
Expand Down
11 changes: 4 additions & 7 deletions drivers/video/video_mcux_csi.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,11 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
{
const struct video_mcux_csi_config *config = dev->config;
struct video_mcux_csi_data *data = dev->data;
unsigned int bpp = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
status_t ret;
struct video_format format = *fmt;

if (bpp == 0) {
return -EINVAL;
}

data->csi_config.bytesPerPixel = bpp;
data->csi_config.linePitch_Bytes = fmt->pitch;
data->csi_config.bytesPerPixel = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
data->csi_config.linePitch_Bytes = fmt->width * data->csi_config.bytesPerPixel;
#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX)
if (fmt->pixelformat != VIDEO_PIX_FMT_XRGB32 && fmt->pixelformat != VIDEO_PIX_FMT_XYUV32) {
return -ENOTSUP;
Expand Down Expand Up @@ -172,6 +167,8 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
return -EIO;
}

fmt->pitch = data->csi_config.linePitch_Bytes;

return 0;
}

Expand Down
18 changes: 13 additions & 5 deletions drivers/video/video_mcux_smartdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static const struct video_format_cap fmts[] = {
static int nxp_video_sdma_set_format(const struct device *dev, struct video_format *fmt)
{
const struct nxp_video_sdma_config *config = dev->config;
int ret;

if (fmt == NULL) {
return -EINVAL;
Expand All @@ -230,14 +231,20 @@ static int nxp_video_sdma_set_format(const struct device *dev, struct video_form

if ((fmt->pixelformat != fmts[0].pixelformat) ||
(fmt->width != fmts[0].width_min) ||
(fmt->height != fmts[0].height_min) ||
(fmt->pitch != fmts[0].width_min * 2)) {
(fmt->height != fmts[0].height_min)) {
LOG_ERR("Unsupported format");
return -ENOTSUP;
}

/* Forward format to sensor device */
return video_set_format(config->sensor_dev, fmt);
ret = video_set_format(config->sensor_dev, fmt);
if (ret < 0) {
return ret;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

return 0;
}

static int nxp_video_sdma_get_format(const struct device *dev, struct video_format *fmt)
Expand Down Expand Up @@ -267,8 +274,7 @@ static int nxp_video_sdma_get_format(const struct device *dev, struct video_form
/* Verify that format is RGB565 */
if ((fmt->pixelformat != fmts[0].pixelformat) ||
(fmt->width != fmts[0].width_min) ||
(fmt->height != fmts[0].height_min) ||
(fmt->pitch != fmts[0].width_min * 2)) {
(fmt->height != fmts[0].height_min)) {
/* Update format of sensor */
fmt->pixelformat = fmts[0].pixelformat;
fmt->width = fmts[0].width_min;
Expand All @@ -281,6 +287,8 @@ static int nxp_video_sdma_get_format(const struct device *dev, struct video_form
}
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/video/video_stm32_dcmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_forma
return ret;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

data->fmt = *fmt;

return 0;
Expand All @@ -218,6 +220,8 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_forma
return ret;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

data->fmt = *fmt;

return 0;
Expand Down
2 changes: 2 additions & 0 deletions drivers/video/video_sw_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static int video_sw_generator_set_fmt(const struct device *dev, struct video_for
return -ENOTSUP;
}

fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;

data->fmt = *fmt;

return 0;
Expand Down
1 change: 0 additions & 1 deletion samples/drivers/video/capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ int main(void)

#if CONFIG_VIDEO_FRAME_WIDTH
fmt.width = CONFIG_VIDEO_FRAME_WIDTH;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
#endif

if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
Expand Down
1 change: 0 additions & 1 deletion samples/drivers/video/capture_to_lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ int main(void)
/* Set format */
fmt.width = CONFIG_VIDEO_WIDTH;
fmt.height = CONFIG_VIDEO_HEIGHT;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;

if (video_set_format(video_dev, &fmt)) {
Expand Down
8 changes: 0 additions & 8 deletions tests/drivers/video/api/src/video_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,34 @@ ZTEST(video_common, test_video_format_caps_index)

fmt.width = 100;
fmt.height = 100;
fmt.pitch = 100 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_ok(ret, "expecting minimum value to match");
zassert_equal(idx, YUYV_A);

fmt.width = 1000;
fmt.height = 1000;
fmt.pitch = 1000 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_ok(ret, "expecting maximum value to match");
zassert_equal(idx, YUYV_A);

fmt.width = 1920;
fmt.height = 1080;
fmt.pitch = 1920 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_ok(ret, "expecting exact match to work");
zassert_equal(idx, YUYV_B);

fmt.width = 1001;
fmt.height = 1000;
fmt.pitch = 1001 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_not_ok(ret, "expecting 1 above maximum width to mismatch");

fmt.width = 1000;
fmt.height = 1001;
fmt.pitch = 1000 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_not_ok(ret, "expecting 1 above maximum height to mismatch");

fmt.width = 1280;
fmt.height = 720;
fmt.pitch = 1280 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_not_ok(ret);
zassert_not_ok(ret, "expecting wrong format to mismatch");
Expand All @@ -78,13 +72,11 @@ ZTEST(video_common, test_video_format_caps_index)

fmt.width = 1000;
fmt.height = 1000;
fmt.pitch = 1000 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_not_ok(ret, "expecting wrong format to mismatch");

fmt.width = 1280;
fmt.height = 720;
fmt.pitch = 1280 * 2;
ret = video_format_caps_index(fmts, &fmt, &idx);
zassert_ok(ret, "expecting exact match to work");
zassert_equal(idx, RGB565);
Expand Down
1 change: 0 additions & 1 deletion tests/drivers/video/api/src/video_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ ZTEST(video_common, test_video_vbuf)
fmt.pixelformat = caps.format_caps[0].pixelformat;
fmt.width = caps.format_caps[0].width_max;
fmt.height = caps.format_caps[0].height_max;
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
fmt.type = type;
zexpect_ok(video_set_format(rx_dev, &fmt));

Expand Down