Skip to content

Commit 29f38b8

Browse files
ngphibanghenrikbrixandersen
authored andcommitted
include: video: Add an utility function to get bytes per pixel
As getting bytes per pixel of a pixel format is a very common operation, add an utility function for it instead of repeating the same codes in different drivers. Signed-off-by: Phi Bang Nguyen <[email protected]>
1 parent 8053b72 commit 29f38b8

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

drivers/video/video_mcux_csi.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,6 @@ struct video_mcux_csi_data {
3232
struct k_poll_signal *signal;
3333
};
3434

35-
static inline unsigned int video_pix_fmt_bpp(uint32_t pixelformat)
36-
{
37-
switch (pixelformat) {
38-
case VIDEO_PIX_FMT_BGGR8:
39-
case VIDEO_PIX_FMT_GBRG8:
40-
case VIDEO_PIX_FMT_GRBG8:
41-
case VIDEO_PIX_FMT_RGGB8:
42-
return 1;
43-
case VIDEO_PIX_FMT_RGB565:
44-
case VIDEO_PIX_FMT_YUYV:
45-
return 2;
46-
case VIDEO_PIX_FMT_XRGB32:
47-
case VIDEO_PIX_FMT_XYUV32:
48-
return 4;
49-
default:
50-
return 0;
51-
}
52-
}
53-
5435
static void __frame_done_cb(CSI_Type *base, csi_handle_t *handle, status_t status, void *user_data)
5536
{
5637
struct video_mcux_csi_data *data = user_data;

drivers/video/video_stm32_dcmi.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ struct video_stm32_dcmi_config {
5454
const struct stream dma;
5555
};
5656

57-
static inline unsigned int video_pix_fmt_bpp(uint32_t pixelformat)
58-
{
59-
switch (pixelformat) {
60-
case VIDEO_PIX_FMT_BGGR8:
61-
case VIDEO_PIX_FMT_GBRG8:
62-
case VIDEO_PIX_FMT_GRBG8:
63-
case VIDEO_PIX_FMT_RGGB8:
64-
return 1;
65-
case VIDEO_PIX_FMT_RGB565:
66-
case VIDEO_PIX_FMT_YUYV:
67-
return 2;
68-
default:
69-
return 0;
70-
}
71-
}
72-
7357
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
7458
{
7559
LOG_WRN("%s", __func__);

include/zephyr/drivers/video.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,30 @@ void video_buffer_release(struct video_buffer *buf);
827827
* @}
828828
*/
829829

830+
/**
831+
* @brief Get number of bytes per pixel of a pixel format
832+
*
833+
* @param pixfmt FourCC pixel format value (\ref video_pixel_formats).
834+
*/
835+
static inline unsigned int video_pix_fmt_bpp(uint32_t pixfmt)
836+
{
837+
switch (pixfmt) {
838+
case VIDEO_PIX_FMT_BGGR8:
839+
case VIDEO_PIX_FMT_GBRG8:
840+
case VIDEO_PIX_FMT_GRBG8:
841+
case VIDEO_PIX_FMT_RGGB8:
842+
return 1;
843+
case VIDEO_PIX_FMT_RGB565:
844+
case VIDEO_PIX_FMT_YUYV:
845+
return 2;
846+
case VIDEO_PIX_FMT_XRGB32:
847+
case VIDEO_PIX_FMT_XYUV32:
848+
return 4;
849+
default:
850+
return 0;
851+
}
852+
}
853+
830854
#ifdef __cplusplus
831855
}
832856
#endif

0 commit comments

Comments
 (0)