Skip to content

Commit

Permalink
drivers: video: Make VIDEO_FOURCC() a documented API
Browse files Browse the repository at this point in the history
Rename video_fourcc() to VIDEO_FOURCC(), differing from the Linux
implementation, but more compliant with the coding style.

Also introduce a VIDEO_FOURCC_FROM_STR() to generate a FOURCC format
code out of a 4-characters string.

Signed-off-by: Josuah Demangeon <[email protected]>
  • Loading branch information
josuah committed Oct 25, 2024
1 parent d83bd31 commit f0a647c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 15 additions & 2 deletions include/zephyr/drivers/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,23 @@ struct video_buffer *video_buffer_alloc(size_t size);
*/
void video_buffer_release(struct video_buffer *buf);

/* fourcc - four-character-code */
#define video_fourcc(a, b, c, d) \
/**
* @brief Four-character-code uniquely identifying the pixel format
*/
#define VIDEO_FOURCC(a, b, c, d) \
((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))

/**
* @brief Convert a four-character-string to a four-character-code
*
* Convert a string literal or variable into a four-character-code
* as defined by @ref VIDEO_FOURCC.
*
* @param str String to be converted
* @return Four-character-code.
*/
#define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])

/**
* @defgroup video_pixel_formats Video pixel formats
* The @c | characters separate the pixels, and spaces separate the bytes.
Expand Down
4 changes: 1 addition & 3 deletions samples/drivers/video/capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ int main(void)
#endif

if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
fmt.pixelformat =
video_fourcc(CONFIG_VIDEO_PIXEL_FORMAT[0], CONFIG_VIDEO_PIXEL_FORMAT[1],
CONFIG_VIDEO_PIXEL_FORMAT[2], CONFIG_VIDEO_PIXEL_FORMAT[3]);
fmt.pixelformat = VIDEO_FOURCC_FROM_STR(CONFIG_VIDEO_PIXEL_FORMAT);
}

LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,
Expand Down

0 comments on commit f0a647c

Please sign in to comment.