Skip to content

Commit 21da345

Browse files
josuahkartben
authored andcommitted
drivers: video: introduce video_bits_per_pixel(pixelformat) helper
This was present in the form of video_pix_fmt_bpp() inside ST and NXP drivers, and was returning the number of bytes, which does not allow support for 10-bits, 4-bits or non-byte aligned video formats. The helper leverages the VIDEO_PIX_FMT_*_BITS macros. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent a6d68d2 commit 21da345

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

drivers/video/video_mcux_csi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static inline void video_pix_fmt_convert(struct video_format *fmt, bool isGetFmt
123123
break;
124124
}
125125

126-
fmt->pitch = fmt->width * video_pix_fmt_bpp(fmt->pixelformat);
126+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
127127
}
128128
#endif
129129

@@ -132,7 +132,7 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_
132132
{
133133
const struct video_mcux_csi_config *config = dev->config;
134134
struct video_mcux_csi_data *data = dev->data;
135-
unsigned int bpp = video_pix_fmt_bpp(fmt->pixelformat);
135+
unsigned int bpp = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
136136
status_t ret;
137137
struct video_format format = *fmt;
138138

drivers/video/video_mcux_mipi_csi2rx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endp
7373
return -ENOTSUP;
7474
}
7575

76-
bpp = video_pix_fmt_bpp(fmt.pixelformat) * 8;
77-
sensor_byte_clk = sensor_pixel_rate * bpp / drv_data->csi2rxConfig.laneNum / 8;
76+
bpp = video_bits_per_pixel(fmt.pixelformat);
77+
sensor_byte_clk = sensor_pixel_rate * bpp / drv_data->csi2rxConfig.laneNum / BITS_PER_BYTE;
7878

7979
ret = clock_control_get_rate(drv_data->clock_dev, drv_data->clock_root, &root_clk_rate);
8080
if (ret) {
@@ -224,7 +224,7 @@ static int mipi_csi2rx_get_frmival(const struct device *dev, enum video_endpoint
224224

225225
static uint64_t mipi_csi2rx_cal_frame_size(const struct video_format *fmt)
226226
{
227-
return fmt->height * fmt->width * video_pix_fmt_bpp(fmt->pixelformat) * 8;
227+
return fmt->height * fmt->width * video_bits_per_pixel(fmt->pixelformat);
228228
}
229229

230230
static uint64_t mipi_csi2rx_estimate_pixel_rate(const struct video_frmival *cur_fmival,

drivers/video/video_stm32_dcmi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev,
198198
{
199199
const struct video_stm32_dcmi_config *config = dev->config;
200200
struct video_stm32_dcmi_data *data = dev->data;
201-
unsigned int bpp = video_pix_fmt_bpp(fmt->pixelformat);
201+
unsigned int bpp = video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
202202

203203
if (bpp == 0 || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) {
204204
return -EINVAL;

include/zephyr/drivers/video.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,14 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis
812812
void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
813813
struct video_frmival_enum *match);
814814

815+
/**
816+
* @defgroup video_pixel_formats Video pixel formats
817+
* The @c | characters separate the pixels, and spaces separate the bytes.
818+
* The uppercase letter represents the most significant bit.
819+
* The lowercase letters represent the rest of the bits.
820+
* @{
821+
*/
822+
815823
/**
816824
* @brief Four-character-code uniquely identifying the pixel format
817825
*/
@@ -829,14 +837,6 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
829837
*/
830838
#define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])
831839

832-
/**
833-
* @defgroup video_pixel_formats Video pixel formats
834-
* The @c | characters separate the pixels, and spaces separate the bytes.
835-
* The uppercase letter represents the most significant bit.
836-
* The lowercase letters represent the rest of the bits.
837-
* @{
838-
*/
839-
840840
/**
841841
* @name Bayer formats (R, G, B channels).
842842
*
@@ -966,33 +966,37 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
966966
*/
967967

968968
/**
969-
* @}
970-
*/
971-
972-
/**
973-
* @brief Get number of bytes per pixel of a pixel format
969+
* @brief Get number of bits per pixel of a pixel format
970+
*
971+
* @param pixfmt FourCC pixel format value (@ref video_pixel_formats).
974972
*
975-
* @param pixfmt FourCC pixel format value (\ref video_pixel_formats).
973+
* @retval 0 if the format is unhandled or if it is variable number of bits
974+
* @retval bit size of one pixel for this format
976975
*/
977-
static inline unsigned int video_pix_fmt_bpp(uint32_t pixfmt)
976+
static inline unsigned int video_bits_per_pixel(uint32_t pixfmt)
978977
{
979978
switch (pixfmt) {
980979
case VIDEO_PIX_FMT_BGGR8:
981980
case VIDEO_PIX_FMT_GBRG8:
982981
case VIDEO_PIX_FMT_GRBG8:
983982
case VIDEO_PIX_FMT_RGGB8:
984-
return 1;
983+
return 8;
985984
case VIDEO_PIX_FMT_RGB565:
986985
case VIDEO_PIX_FMT_YUYV:
987-
return 2;
986+
return 16;
988987
case VIDEO_PIX_FMT_XRGB32:
989988
case VIDEO_PIX_FMT_XYUV32:
990-
return 4;
989+
return 32;
991990
default:
991+
/* Variable number of bits per pixel or unknown format */
992992
return 0;
993993
}
994994
}
995995

996+
/**
997+
* @}
998+
*/
999+
9961000
#ifdef __cplusplus
9971001
}
9981002
#endif

0 commit comments

Comments
 (0)