Skip to content

Commit fcadb79

Browse files
ngphibangkartben
authored andcommitted
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 da12135 commit fcadb79

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
@@ -1183,7 +1183,7 @@ static int gc2145_init(const struct device *dev)
11831183
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
11841184
fmt.width = RESOLUTION_QVGA_W;
11851185
fmt.height = RESOLUTION_QVGA_H;
1186-
fmt.pitch = RESOLUTION_QVGA_W * 2;
1186+
fmt.pitch = RESOLUTION_QVGA_W * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
11871187

11881188
ret = gc2145_set_fmt(dev, &fmt);
11891189
if (ret) {

drivers/video/mt9m114.c

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

569569
ret = mt9m114_set_fmt(dev, &fmt);
570570
if (ret) {

drivers/video/ov2640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ static int ov2640_init(const struct device *dev)
10321032
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
10331033
fmt.width = SVGA_HSIZE;
10341034
fmt.height = SVGA_VSIZE;
1035-
fmt.pitch = SVGA_HSIZE * 2;
1035+
fmt.pitch = SVGA_HSIZE * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
10361036
ret = ov2640_set_fmt(dev, &fmt);
10371037
if (ret) {
10381038
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
@@ -1433,7 +1433,7 @@ static int ov5640_init(const struct device *dev)
14331433
fmt.width = 1280;
14341434
fmt.height = 720;
14351435
}
1436-
fmt.pitch = fmt.width * 2;
1436+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
14371437
ret = ov5640_set_fmt(dev, &fmt);
14381438
if (ret) {
14391439
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
@@ -554,7 +554,7 @@ static int ov7670_init(const struct device *dev)
554554
fmt.pixelformat = VIDEO_PIX_FMT_YUYV;
555555
fmt.width = 640;
556556
fmt.height = 480;
557-
fmt.pitch = fmt.width * 2;
557+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
558558
ret = ov7670_set_fmt(dev, &fmt);
559559
if (ret < 0) {
560560
return ret;

drivers/video/ov7725.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int ov7725_init(const struct device *dev)
592592
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
593593
fmt.width = 640;
594594
fmt.height = 480;
595-
fmt.pitch = 640 * 2;
595+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
596596
ret = ov7725_set_fmt(dev, &fmt);
597597
if (ret) {
598598
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
@@ -368,7 +368,7 @@ int emul_imager_init(const struct device *dev)
368368
fmt.pixelformat = fmts[0].pixelformat;
369369
fmt.width = fmts[0].width_min;
370370
fmt.height = fmts[0].height_min;
371-
fmt.pitch = fmt.width * 2;
371+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
372372

373373
ret = emul_imager_set_fmt(dev, &fmt);
374374
if (ret < 0) {

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

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

151151
#if CONFIG_VIDEO_FRAME_WIDTH
152152
fmt.width = CONFIG_VIDEO_FRAME_WIDTH;
153-
fmt.pitch = fmt.width * 2;
153+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
154154
#endif
155155

156156
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
@@ -79,7 +79,7 @@ int main(void)
7979
/* Set format */
8080
fmt.width = CONFIG_VIDEO_WIDTH;
8181
fmt.height = CONFIG_VIDEO_HEIGHT;
82-
fmt.pitch = fmt.width * 2;
82+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
8383
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;
8484

8585
if (video_set_format(video_dev, &fmt)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ZTEST(video_common, test_video_vbuf)
158158
fmt.pixelformat = caps.format_caps[0].pixelformat;
159159
fmt.width = caps.format_caps[0].width_max;
160160
fmt.height = caps.format_caps[0].height_max;
161-
fmt.pitch = fmt.width * 2;
161+
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / BITS_PER_BYTE;
162162
fmt.type = type;
163163
zexpect_ok(video_set_format(rx_dev, &fmt));
164164

0 commit comments

Comments
 (0)