Skip to content

Commit 7316e7f

Browse files
committed
drivers: video: Compute bits per pixel according to format
Compute bits per pixel according to the pixel format instead of hardcoding it. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 45fc595 commit 7316e7f

File tree

10 files changed

+10
-10
lines changed

10 files changed

+10
-10
lines changed

drivers/video/gc2145.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ static int gc2145_init(const struct device *dev)
11861186
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
11871187
fmt.width = RESOLUTION_QVGA_W;
11881188
fmt.height = RESOLUTION_QVGA_H;
1189-
fmt.pitch = RESOLUTION_QVGA_W * 2;
1189+
fmt.pitch = RESOLUTION_QVGA_W * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
11901190

11911191
ret = gc2145_set_fmt(dev, VIDEO_EP_OUT, &fmt);
11921192
if (ret) {

drivers/video/mt9m114.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static int mt9m114_init(const struct device *dev)
567567
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
568568
fmt.width = 480;
569569
fmt.height = 272;
570-
fmt.pitch = fmt.width * 2;
570+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
571571

572572
ret = mt9m114_set_fmt(dev, VIDEO_EP_OUT, &fmt);
573573
if (ret) {

drivers/video/ov2640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static int ov2640_init(const struct device *dev)
10361036
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
10371037
fmt.width = SVGA_HSIZE;
10381038
fmt.height = SVGA_VSIZE;
1039-
fmt.pitch = SVGA_HSIZE * 2;
1039+
fmt.pitch = SVGA_HSIZE * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
10401040
ret = ov2640_set_fmt(dev, VIDEO_EP_OUT, &fmt);
10411041
if (ret) {
10421042
LOG_ERR("Unable to configure default format");

drivers/video/ov5640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ static int ov5640_init(const struct device *dev)
14391439
fmt.width = 1280;
14401440
fmt.height = 720;
14411441
}
1442-
fmt.pitch = fmt.width * 2;
1442+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
14431443
ret = ov5640_set_fmt(dev, VIDEO_EP_OUT, &fmt);
14441444
if (ret) {
14451445
LOG_ERR("Unable to configure default format");

drivers/video/ov7670.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int ov7670_init(const struct device *dev)
557557
fmt.pixelformat = VIDEO_PIX_FMT_YUYV;
558558
fmt.width = 640;
559559
fmt.height = 480;
560-
fmt.pitch = fmt.width * 2;
560+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
561561
ret = ov7670_set_fmt(dev, VIDEO_EP_OUT, &fmt);
562562
if (ret < 0) {
563563
return ret;

drivers/video/ov7725.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static int ov7725_init(const struct device *dev)
598598
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
599599
fmt.width = 640;
600600
fmt.height = 480;
601-
fmt.pitch = 640 * 2;
601+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
602602
ret = ov7725_set_fmt(dev, VIDEO_EP_OUT, &fmt);
603603
if (ret) {
604604
LOG_ERR("Unable to configure default format");

drivers/video/video_emul_imager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int emul_imager_init(const struct device *dev)
398398
fmt.pixelformat = fmts[0].pixelformat;
399399
fmt.width = fmts[0].width_min;
400400
fmt.height = fmts[0].height_min;
401-
fmt.pitch = fmt.width * 2;
401+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
402402

403403
ret = emul_imager_set_fmt(dev, VIDEO_EP_OUT, &fmt);
404404
if (ret < 0) {

samples/drivers/video/capture/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int main(void)
147147

148148
#if CONFIG_VIDEO_FRAME_WIDTH
149149
fmt.width = CONFIG_VIDEO_FRAME_WIDTH;
150-
fmt.pitch = fmt.width * 2;
150+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
151151
#endif
152152

153153
if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(void)
7676
/* Set format */
7777
fmt.width = CONFIG_VIDEO_WIDTH;
7878
fmt.height = CONFIG_VIDEO_HEIGHT;
79-
fmt.pitch = fmt.width * 2;
79+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
8080
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
8181

8282
if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {

tests/drivers/video/api/src/video_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ZTEST(video_common, test_video_vbuf)
156156
fmt.pixelformat = caps.format_caps[0].pixelformat;
157157
fmt.width = caps.format_caps[0].width_max;
158158
fmt.height = caps.format_caps[0].height_max;
159-
fmt.pitch = fmt.width * 2;
159+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
160160
zexpect_ok(video_set_format(rx_dev, VIDEO_EP_OUT, &fmt));
161161

162162
/* Allocate a buffer, assuming prj.conf gives enough memory for it */

0 commit comments

Comments
 (0)