|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 tinyVision.ai Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_PIXEL_CONVERT_H_ |
| 8 | +#define ZEPHYR_INCLUDE_PIXEL_CONVERT_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/image.h> |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Define a new format conversion operation. |
| 19 | + * |
| 20 | + * @param _fn Function converting one input line. |
| 21 | + * @param _fourcc_in The input format for that operation. |
| 22 | + * @param _fourcc_out The Output format for that operation. |
| 23 | + */ |
| 24 | +#define PIXEL_DEFINE_CONVERT_OPERATION(_fn, _fourcc_in, _fourcc_out) \ |
| 25 | + static const STRUCT_SECTION_ITERABLE_ALTERNATE(pixel_convert, pixel_operation, \ |
| 26 | + _fn##_op) = { \ |
| 27 | + .name = #_fn, \ |
| 28 | + .fourcc_in = _fourcc_in, \ |
| 29 | + .fourcc_out = _fourcc_out, \ |
| 30 | + .window_size = 1, \ |
| 31 | + .run = pixel_convert_op, \ |
| 32 | + .arg = _fn, \ |
| 33 | + } |
| 34 | +/** |
| 35 | + * @brief Helper to turn a format conversion function into an operation. |
| 36 | + * |
| 37 | + * The line conversion function is free to perform any processing on the input line. |
| 38 | + * The @c w argument is the width of both the source and destination buffers. |
| 39 | + * |
| 40 | + * The line conversion function is to be provided in @c op->arg |
| 41 | + * |
| 42 | + * @param op Current operation in progress. |
| 43 | + */ |
| 44 | +void pixel_convert_op(struct pixel_operation *op); |
| 45 | + |
| 46 | +/** |
| 47 | + * @brief Get the luminance (luma channel) of an RGB24 pixel. |
| 48 | + * |
| 49 | + * @param rgb24 Pointer to an RGB24 pixel: red, green, blue channels. |
| 50 | + */ |
| 51 | +uint8_t pixel_rgb24_get_luma_bt709(const uint8_t rgb24[3]); |
| 52 | + |
| 53 | +/** |
| 54 | + * @brief Convert a line of pixel data from RGB24 to RGB24 (null conversion). |
| 55 | + * |
| 56 | + * See @ref video_pixel_formats for the definition of the input and output formats. |
| 57 | + * |
| 58 | + * You only need to call this function to work directly on raw buffers. |
| 59 | + * See @ref pixel_image_convert for converting between formats. |
| 60 | + * |
| 61 | + * @param src Buffer of the input line in the format, @c XXX in @c pixel_line_XXX_to_YYY(). |
| 62 | + * @param dst Buffer of the output line in the format, @c YYY in @c pixel_line_XXX_to_YYY(). |
| 63 | + * @param width Width of the lines in number of pixels. |
| 64 | + */ |
| 65 | +void pixel_line_rgb24_to_rgb24(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 66 | +/** |
| 67 | + * @brief Convert a line of pixel data from RGB332 to RGB24. |
| 68 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 69 | + */ |
| 70 | +void pixel_line_rgb332_to_rgb24(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 71 | +/** |
| 72 | + * @brief Convert a line of pixel data from RGB24 to RGB332 little-endian. |
| 73 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 74 | + */ |
| 75 | +void pixel_line_rgb24_to_rgb332(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 76 | +/** |
| 77 | + * @brief Convert a line of pixel data from RGB565 little-endian to RGB24. |
| 78 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 79 | + */ |
| 80 | +void pixel_line_rgb565le_to_rgb24(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 81 | +/** |
| 82 | + * @brief Convert a line of pixel data from RGB565 big-endian to RGB24. |
| 83 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 84 | + */ |
| 85 | +void pixel_line_rgb565be_to_rgb24(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 86 | +/** |
| 87 | + * @brief Convert a line of pixel data from RGB24 to RGB565 little-endian. |
| 88 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 89 | + */ |
| 90 | +void pixel_line_rgb24_to_rgb565le(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 91 | +/** |
| 92 | + * @brief Convert a line of pixel data from RGB24 to RGB565 big-endian. |
| 93 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 94 | + */ |
| 95 | +void pixel_line_rgb24_to_rgb565be(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 96 | +/** |
| 97 | + * @brief Convert a line of pixel data from YUYV to RGB24 (BT.709 coefficients). |
| 98 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 99 | + */ |
| 100 | +void pixel_line_yuyv_to_rgb24_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 101 | +/** |
| 102 | + * @brief Convert a line of pixel data from RGB24 to YUYV (BT.709 coefficients). |
| 103 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 104 | + */ |
| 105 | +void pixel_line_rgb24_to_yuyv_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 106 | +/** |
| 107 | + * @brief Convert a line of pixel data from RGB24 to YUV24 (BT.709 coefficients). |
| 108 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 109 | + */ |
| 110 | +void pixel_line_rgb24_to_yuv24_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 111 | +/** |
| 112 | + * @brief Convert a line of pixel data from YUV24 to RGB24 (BT.709 coefficients). |
| 113 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 114 | + */ |
| 115 | +void pixel_line_yuv24_to_rgb24_bt709(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 116 | +/** |
| 117 | + * @brief Convert a line of pixel data from YUYV to YUV24 |
| 118 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 119 | + */ |
| 120 | +void pixel_line_yuyv_to_yuv24(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 121 | +/** |
| 122 | + * @brief Convert a line of pixel data from YUV24 to YUYV |
| 123 | + * @copydetails pixel_line_rgb24_to_rgb24() |
| 124 | + */ |
| 125 | +void pixel_line_yuv24_to_yuyv(const uint8_t *src, uint8_t *dst, uint16_t width); |
| 126 | + |
| 127 | +#endif /* ZEPHYR_INCLUDE_PIXEL_CONVERT_H_ */ |
0 commit comments