Skip to content

Commit

Permalink
drivers: video: split the video formats out of video.h
Browse files Browse the repository at this point in the history
Split the video formats in a separate file, allowing the list to grow
without cluttering <zephyr/drivers/video.h>, as well as being included
from other files than do not support C declarations such as the
devicetree.

Signed-off-by: Josuah Demangeon <[email protected]>
  • Loading branch information
josuah committed Oct 20, 2024
1 parent a9587f1 commit 12ca486
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 154 deletions.
163 changes: 9 additions & 154 deletions include/zephyr/drivers/video.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* @file
*
* @brief Public APIs for Video.
*/

/*
* Copyright (c) 2019 Linaro Limited.
* Copyright (c) 2024 tinyVision.ai Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_VIDEO_H_
#define ZEPHYR_INCLUDE_VIDEO_H_

/**
* @file
* @brief Public APIs for Video.
*/

#ifndef ZEPHYR_INCLUDE_DRIVERS_VIDEO_H_
#define ZEPHYR_INCLUDE_DRIVERS_VIDEO_H_

/**
* @brief Video Interface
Expand Down Expand Up @@ -750,151 +750,6 @@ struct video_buffer *video_buffer_alloc(size_t size);
*/
void video_buffer_release(struct video_buffer *buf);

/**
* @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
*
* This converts 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 | character separate the pixel, and spaces separate the bytes.
* The uppercase letter represents the most significant bit.
* The lowercase letters represent the rest of the bits.
* @{
*/

/**
* @name Bayer formats (R, G, B channels).
* @{
*/

/**
* @verbatim
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_BGGR8 VIDEO_FOURCC('B', 'A', '8', '1')
#define VIDEO_PIX_FMT_BGGR8_BPP 8

/**
* @verbatim
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_GBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')
#define VIDEO_PIX_FMT_BGRG8_BPP 8

/**
* @verbatim
* | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_GRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')
#define VIDEO_PIX_FMT_GRBG8_BPP 8

/**
* @verbatim
* | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
* | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_RGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')
#define VIDEO_PIX_FMT_RGGB8_BPP 8

/**
* @}
*/

/**
* @name RGB formats
* Per-color (R, G, B) channels.
* @{
*/

/**
* 5-bit blue followed by 6-bit green followed by 5-bit red, in little-endian over two bytes.
* @verbatim
* | gggRrrrr | BbbbbGgg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')
#define VIDEO_PIX_FMT_RGB565_BPP 16

/**
* There is an empty (X) byte for each pixel.
* @verbatim
* | Xxxxxxxx Rrrrrrrr Gggggggg Bbbbbbbb | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')
#define VIDEO_PIX_FMT_XRGB32_BPP 32

/**
* @}
*/

/**
* @name YUV formats
* Luminance (Y) and chrominance (U, V) channels.
* @{
*/

/**
* There is either a missing channel per pixel, U or V.
* The value is to be averaged over 2 pixels to get the value of individual pixel.
* @verbatim
* | Yyyyyyyy Uuuuuuuu | Yyyyyyyy Vvvvvvvv | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')
#define VIDEO_PIX_FMT_YUYV_BPP 16

/**
* There is an empty (X) byte for each pixel.
* @verbatim
* | Xxxxxxxx Yyyyyyyy Uuuuuuuu Vvvvvvvv | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')
#define VIDEO_PIX_FMT_XYUV32_BPP 32

/**
* @}
*/

/**
* @name Compressed formats
* @{
*/

/**
* Both JPEG (single frame) and Motion-JPEG (MJPEG, multiple JPEG frames concatenated)
*/
#define VIDEO_PIX_FMT_JPEG VIDEO_FOURCC('J', 'P', 'E', 'G')

/**
* @}
*/

/**
* @}
*/

#ifdef __cplusplus
}
#endif
Expand All @@ -903,4 +758,4 @@ void video_buffer_release(struct video_buffer *buf);
* @}
*/

#endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
#endif /* ZEPHYR_INCLUDE_DRIVERS_VIDEO_H_ */
187 changes: 187 additions & 0 deletions include/zephyr/drivers/video/formats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright (c) 2024 tinyVision.ai Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Public definitions of Video formats.
*/

#ifndef ZEPHYR_INCLUDE_VIDEO_FORMATS_H_
#define ZEPHYR_INCLUDE_VIDEO_FORMATS_H_

/**
* @brief Video Formats
* @defgroup video_formats Video Formats
* @since 4.0
* @version 1.0.0
* @ingroup video_interface
* @{
*/

#include <zephyr/device.h>
#include <stddef.h>
#include <zephyr/kernel.h>

#include <zephyr/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @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
*
* This converts 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 | character separate the pixel, and spaces separate the bytes.
* The uppercase letter represents the most significant bit.
* The lowercase letters represent the rest of the bits.
* @{
*/

/**
* @name Bayer formats (R, G, B channels).
* @{
*/

/**
* @verbatim
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_BGGR8 VIDEO_FOURCC('B', 'A', '8', '1')
#define VIDEO_PIX_FMT_BGGR8_BITS 8

Check notice on line 71 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:71 -#define VIDEO_PIX_FMT_BGGR8 VIDEO_FOURCC('B', 'A', '8', '1') +#define VIDEO_PIX_FMT_BGGR8 VIDEO_FOURCC('B', 'A', '8', '1')

/**
* @verbatim
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_GBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')
#define VIDEO_PIX_FMT_BGRG8_BITS 8

Check notice on line 80 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:80 -#define VIDEO_PIX_FMT_GBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G') +#define VIDEO_PIX_FMT_GBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')

/**
* @verbatim
* | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
* | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_GRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')
#define VIDEO_PIX_FMT_GRBG8_BITS 8

Check notice on line 89 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:89 -#define VIDEO_PIX_FMT_GRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G') +#define VIDEO_PIX_FMT_GRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')

/**
* @verbatim
* | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
* | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_RGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')
#define VIDEO_PIX_FMT_RGGB8_BITS 8

Check notice on line 98 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:98 -#define VIDEO_PIX_FMT_RGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B') +#define VIDEO_PIX_FMT_RGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')

/**
* @}
*/

/**
* @name RGB formats
* Per-color (R, G, B) channels.
* @{
*/

/**
* 5-bit blue followed by 6-bit green followed by 5-bit red, in little-endian over two bytes.
* @verbatim
* | gggRrrrr | BbbbbGgg | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')
#define VIDEO_PIX_FMT_RGB565_BITS 16

Check notice on line 117 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:117 -#define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P') +#define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')

/**
* There is an empty (X) byte for each pixel.
* @verbatim
* | Xxxxxxxx Rrrrrrrr Gggggggg Bbbbbbbb | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')
#define VIDEO_PIX_FMT_XRGB32_BITS 32

Check notice on line 126 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:126 -#define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4') +#define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')

/**
* @}
*/

/**
* @name YUV formats
* Luminance (Y) and chrominance (U, V) channels.
* @{
*/

/**
* There is either a missing channel per pixel, U or V.
* The value is to be averaged over 2 pixels to get the value of individual pixel.
* @verbatim
* | Yyyyyyyy Uuuuuuuu | Yyyyyyyy Vvvvvvvv | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')
#define VIDEO_PIX_FMT_YUYV_BITS 16

Check notice on line 146 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:146 -#define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V') +#define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')

/**
* There is an empty (X) byte for each pixel.
* @verbatim
* | Xxxxxxxx Yyyyyyyy Uuuuuuuu Vvvvvvvv | ...
* @endverbatim
*/
#define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')
#define VIDEO_PIX_FMT_XYUV32_BITS 32

Check notice on line 155 in include/zephyr/drivers/video/formats.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video/formats.h:155 -#define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V') +#define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')

/**
* @}
*/

/**
* @name Compressed formats
* @{
*/

/**
* Both JPEG (single frame) and Motion-JPEG (MJPEG, multiple JPEG frames concatenated)
*/
#define VIDEO_PIX_FMT_JPEG VIDEO_FOURCC('J', 'P', 'E', 'G')

/**
* @}
*/

/**
* @}
*/

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
1 change: 1 addition & 0 deletions tests/lib/cpp/cxx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/class/usb_hid.h>
#include <zephyr/drivers/video-controls.h>
#include <zephyr/drivers/video/formats.h>
#include <zephyr/drivers/video.h>
#include <zephyr/drivers/watchdog.h>

Expand Down

0 comments on commit 12ca486

Please sign in to comment.