|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 tinyVision.ai Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_PIXEL_FORMATS_H_ |
| 8 | +#define ZEPHYR_INCLUDE_PIXEL_FORMATS_H_ |
| 9 | + |
| 10 | +#include <stdlib.h> |
| 11 | +#include <stdint.h> |
| 12 | + |
| 13 | +#include <zephyr/sys/util.h> |
| 14 | +#include <zephyr/sys/byteorder.h> |
| 15 | +#include <zephyr/pixel/stream.h> |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Get the luminance (luma channel) of an RGB24 pixel. |
| 19 | + * |
| 20 | + * @param rgb24 Pointer to an RGB24 pixel: red, green, blue channels. |
| 21 | + */ |
| 22 | +uint8_t pixel_rgb24_get_luma_bt709(const uint8_t rgb24[3]); |
| 23 | + |
| 24 | +/** |
| 25 | + * @brief Convert a line of pixel data from RGB332 to RGB24. |
| 26 | + * |
| 27 | + * See @ref video_pixel_formats for the definition of the input and output formats. |
| 28 | + * |
| 29 | + * @param src Buffer of the input line in the format, @c XXX in @c pixel_XXXline_to_YYYline(). |
| 30 | + * @param dst Buffer of the output line in the format, @c YYY in @c pixel_XXXline_to_YYYline(). |
| 31 | + * @param width Width of the lines in number of pixels. |
| 32 | + */ |
| 33 | +void pixel_rgb332line_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 34 | +/** |
| 35 | + * @brief Convert a line of pixel data from RGB24 to RGB332 little-endian. |
| 36 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 37 | + */ |
| 38 | +void pixel_rgb24line_to_rgb332line(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 39 | +/** |
| 40 | + * @brief Convert a line of pixel data from RGB565 little-endian to RGB24. |
| 41 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 42 | + */ |
| 43 | +void pixel_rgb565leline_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 44 | +/** |
| 45 | + * @brief Convert a line of pixel data from RGB565 big-endian to RGB24. |
| 46 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 47 | + */ |
| 48 | +void pixel_rgb565beline_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 49 | +/** |
| 50 | + * @brief Convert a line of pixel data from RGB24 to RGB565 little-endian. |
| 51 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 52 | + */ |
| 53 | +void pixel_rgb24line_to_rgb565leline(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 54 | +/** |
| 55 | + * @brief Convert a line of pixel data from RGB24 to RGB565 big-endian. |
| 56 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 57 | + */ |
| 58 | +void pixel_rgb24line_to_rgb565beline(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 59 | +/** |
| 60 | + * @brief Convert a line of pixel data from YUYV to RGB24 (BT.709 coefficients). |
| 61 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 62 | + */ |
| 63 | +void pixel_yuyvline_to_rgb24line_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 64 | +/** |
| 65 | + * @brief Convert a line of pixel data from RGB24 to YUYV (BT.709 coefficients). |
| 66 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 67 | + */ |
| 68 | +void pixel_rgb24line_to_yuyvline_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 69 | +/** |
| 70 | + * @brief Convert a line of pixel data from RGB24 to YUV24 (BT.709 coefficients). |
| 71 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 72 | + */ |
| 73 | +void pixel_rgb24line_to_yuv24line_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 74 | +/** |
| 75 | + * @brief Convert a line of pixel data from YUV24 to RGB24 (BT.709 coefficients). |
| 76 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 77 | + */ |
| 78 | +void pixel_yuv24line_to_rgb24line_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 79 | +/** |
| 80 | + * @brief Convert a line of pixel data from YUYV to YUV24 |
| 81 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 82 | + */ |
| 83 | +void pixel_yuyvline_to_yuv24line(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 84 | +/** |
| 85 | + * @brief Convert a line of pixel data from YUV24 to YUYV |
| 86 | + * @copydetails pixel_rgb332line_to_rgb24line() |
| 87 | + */ |
| 88 | +void pixel_yuv24line_to_yuyvline(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 89 | + |
| 90 | +/** |
| 91 | + * @brief Convert a stream of pixel data from RGB332 to RGB24. |
| 92 | + * |
| 93 | + * @param name The symbol of the @ref pixel_stream that will be defined. |
| 94 | + * @param width The total width of the input frame in number of pixels. |
| 95 | + * @param height The total height of the input frame in number of pixels. |
| 96 | + */ |
| 97 | +#define PIXEL_RGB332STREAM_TO_RGB24STREAM(name, width, height) \ |
| 98 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb332stream_to_rgb24stream, (width), (height), 1) |
| 99 | +/** |
| 100 | + * @brief Convert a stream of pixel data from RGB24 to RGB332 |
| 101 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 102 | + */ |
| 103 | +#define PIXEL_RGB24STREAM_TO_RGB332STREAM(name, width, height) \ |
| 104 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb332stream, (width), (height), 3) |
| 105 | +/** |
| 106 | + * @brief Convert a stream of pixel data from RGB565 little-endian to RGB24 |
| 107 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 108 | + */ |
| 109 | +#define PIXEL_RGB565LESTREAM_TO_RGB24STREAM(name, width, height) \ |
| 110 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb565lestream_to_rgb24stream, (width), (height), 2) |
| 111 | +/** |
| 112 | + * @brief Convert a stream of pixel data from RGB24 to RGB565 little-endian |
| 113 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 114 | + */ |
| 115 | +#define PIXEL_RGB24STREAM_TO_RGB565LESTREAM(name, width, height) \ |
| 116 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb565lestream, (width), (height), 3) |
| 117 | +/** |
| 118 | + * @brief Convert a stream of pixel data from RGB565 big-endian to RGB24 |
| 119 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 120 | + */ |
| 121 | +#define PIXEL_RGB565BESTREAM_TO_RGB24STREAM(name, width, height) \ |
| 122 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb565bestream_to_rgb24stream, (width), (height), 2) |
| 123 | +/** |
| 124 | + * @brief Convert a stream of pixel data from RGB24 to RGB565 big-endian |
| 125 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 126 | + */ |
| 127 | +#define PIXEL_RGB24STREAM_TO_RGB565BESTREAM(name, width, height) \ |
| 128 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb565bestream, (width), (height), 3) |
| 129 | +/** |
| 130 | + * @brief Convert a stream of pixel data from YUYV to RGB24 (BT.709 coefficients) |
| 131 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 132 | + */ |
| 133 | +#define PIXEL_YUYVSTREAM_TO_RGB24STREAM_BT709(name, width, height) \ |
| 134 | + PIXEL_FORMAT_DEFINE(name, pixel_yuyvstream_to_rgb24stream_bt709, (width), (height), 2) |
| 135 | +/** |
| 136 | + * @brief Convert a stream of pixel data from RGB24 to YUYV (BT.709 coefficients) |
| 137 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 138 | + */ |
| 139 | +#define PIXEL_RGB24STREAM_TO_YUYVSTREAM_BT709(name, width, height) \ |
| 140 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_yuyvstream_bt709, (width), (height), 3) |
| 141 | +/** |
| 142 | + * @brief Convert a stream of pixel data from YUV24 to RGB24 (BT.709 coefficients) |
| 143 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 144 | + */ |
| 145 | +#define PIXEL_YUV24STREAM_TO_RGB24STREAM_BT709(name, width, height) \ |
| 146 | + PIXEL_FORMAT_DEFINE(name, pixel_yuv24stream_to_rgb24stream_bt709, (width), (height), 3) |
| 147 | +/** |
| 148 | + * @brief Convert a stream of pixel data from RGB24 to YUV24 (BT.709 coefficients) |
| 149 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 150 | + */ |
| 151 | +#define PIXEL_RGB24STREAM_TO_YUV24STREAM_BT709(name, width, height) \ |
| 152 | + PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_yuv24stream_bt709, (width), (height), 3) |
| 153 | +/** |
| 154 | + * @brief Convert a stream of pixel data from YUYV to YUV24 |
| 155 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 156 | + */ |
| 157 | +#define PIXEL_YUYVSTREAM_TO_YUV24STREAM(name, width, height) \ |
| 158 | + PIXEL_FORMAT_DEFINE(name, pixel_yuyvstream_to_yuv24stream, (width), (height), 2) |
| 159 | +/** |
| 160 | + * @brief Convert a stream of pixel data from YUV24 to YUYV |
| 161 | + * @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM() |
| 162 | + */ |
| 163 | +#define PIXEL_YUV24STREAM_TO_YUYVSTREAM(name, width, height) \ |
| 164 | + PIXEL_FORMAT_DEFINE(name, pixel_yuv24stream_to_yuyvstream, (width), (height), 3) |
| 165 | + |
| 166 | +/** @cond INTERNAL_HIDDEN */ |
| 167 | +#define PIXEL_FORMAT_DEFINE(name, fn, width, height, bytes_per_pixel) \ |
| 168 | + PIXEL_STREAM_DEFINE(name, (fn), (width), (height), \ |
| 169 | + (width) * (bytes_per_pixel), 1 * (width) * (bytes_per_pixel)) |
| 170 | +void pixel_rgb24stream_to_rgb332stream(struct pixel_stream *strm); |
| 171 | +void pixel_rgb332stream_to_rgb24stream(struct pixel_stream *strm); |
| 172 | +void pixel_rgb565lestream_to_rgb24stream(struct pixel_stream *strm); |
| 173 | +void pixel_rgb24stream_to_rgb565lestream(struct pixel_stream *strm); |
| 174 | +void pixel_rgb565bestream_to_rgb24stream(struct pixel_stream *strm); |
| 175 | +void pixel_rgb24stream_to_rgb565bestream(struct pixel_stream *strm); |
| 176 | +void pixel_yuyvstream_to_rgb24stream_bt709(struct pixel_stream *strm); |
| 177 | +void pixel_rgb24stream_to_yuyvstream_bt709(struct pixel_stream *strm); |
| 178 | +void pixel_yuv24stream_to_rgb24stream_bt709(struct pixel_stream *strm); |
| 179 | +void pixel_rgb24stream_to_yuv24stream_bt709(struct pixel_stream *strm); |
| 180 | +void pixel_yuyvstream_to_yuv24stream(struct pixel_stream *strm); |
| 181 | +void pixel_yuv24stream_to_yuyvstream(struct pixel_stream *strm); |
| 182 | +/** @endcond */ |
| 183 | + |
| 184 | +#endif /* ZEPHYR_INCLUDE_PIXEL_FORMATS_H_ */ |
0 commit comments