Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: pixel: towards gstreamer/ffmpeg/opencv #86671

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,21 @@ PHYTEC Platforms:
labels:
- "platform: PHYTEC"

Pixel library:
status: maintained
maintainers:
- josuah
files:
- include/zephyr/pixel/
- lib/pixel/
- tests/lib/pixel/
- samples/lib/pixel/
labels:
- "area: Pixel Library"
tests:
- libraries.pixel
description: Library for pixel manipulation and image processing

POSIX API layer:
status: maintained
maintainers:
Expand Down
139 changes: 139 additions & 0 deletions include/zephyr/pixel/bayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2025 tinyVision.ai Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_PIXEL_BAYER_H_
#define ZEPHYR_INCLUDE_PIXEL_BAYER_H_

#include <stdint.h>
#include <stdlib.h>

#include <zephyr/pixel/stream.h>

/**
* @brief Convert a line from RGGB8 to RGB24 with 3x3 method
*
* @param i0 Buffer of the input row number 0 in bayer format (1 byte per pixel).
* @param i1 Buffer of the input row number 1 in bayer format (1 byte per pixel).
* @param i2 Buffer of the input row number 2 in bayer format (1 byte per pixel).
* @param rgb24 Buffer of the output row in RGB24 format (3 bytes per pixel).
* @param width Width of the lines in number of pixels.
*/
void pixel_rggb8line_to_rgb24line_3x3(const uint8_t *i0, const uint8_t *i1, const uint8_t *i2,
uint8_t *rgb24, uint16_t width);
/**
* @brief Convert a line from GRBG8 to RGB24 with 3x3 method
* @copydetails pixel_rggb8line_to_rgb24line_3x3()
*/
void pixel_grbg8line_to_rgb24line_3x3(const uint8_t *i0, const uint8_t *i1, const uint8_t *i2,
uint8_t *rgb24, uint16_t width);
/**
* @brief Convert a line from BGGR8 to RGB24 with 3x3 method
* @copydetails pixel_rggb8line_to_rgb24line_3x3()
*/
void pixel_bggr8line_to_rgb24line_3x3(const uint8_t *i0, const uint8_t *i1, const uint8_t *i2,
uint8_t *rgb24, uint16_t width);
/**
* @brief Convert a line from GBRG8 to RGB24 with 3x3 method
* @copydetails pixel_rggb8line_to_rgb24line_3x3()
*/
void pixel_gbrg8line_to_rgb24line_3x3(const uint8_t *i0, const uint8_t *i1, const uint8_t *i2,
uint8_t *rgb24, uint16_t width);

/**
* @brief Convert a line from RGGB8 to RGB24 with 2x2 method
*
* @param i0 Buffer of the input row number 0 in bayer format (1 byte per pixel).
* @param i1 Buffer of the input row number 1 in bayer format (1 byte per pixel).
* @param rgb24 Buffer of the output row in RGB24 format (3 bytes per pixel).
* @param width Width of the lines in number of pixels.
*/
void pixel_rggb8line_to_rgb24line_2x2(const uint8_t *i0, const uint8_t *i1, uint8_t *rgb24,
uint16_t width);
/**
* @brief Convert a line from GBRG8 to RGB24 with 2x2 method
* @copydetails pixel_rggb8line_to_rgb24line_2x2()
*/
void pixel_gbrg8line_to_rgb24line_2x2(const uint8_t *i0, const uint8_t *i1, uint8_t *rgb24,
uint16_t width);
/**
* @brief Convert a line from BGGR8 to RGB24 with 2x2 method
* @copydetails pixel_rggb8line_to_rgb24line_2x2()
*/
void pixel_bggr8line_to_rgb24line_2x2(const uint8_t *i0, const uint8_t *i1, uint8_t *rgb24,
uint16_t width);
/**
* @brief Convert a line from GRBG8 to RGB24 with 2x2 method
* @copydetails pixel_rggb8line_to_rgb24line_2x2()
*/
void pixel_grbg8line_to_rgb24line_2x2(const uint8_t *i0, const uint8_t *i1, uint8_t *rgb24,
uint16_t width);

/**
* @brief Define a stream converter from RGGB8 to RGB24 with the 3x3 method
*
* @param name The symbol of the @ref pixel_stream that will be defined.
* @param width The total width of the input frame in number of pixels.
* @param height The total height of the input frame in number of pixels.
*/
#define PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_rggb8stream_to_rgb24stream_3x3, (width), (height), 3)
/**
* @brief Define a stream converter from GRBG8 to RGB24 with the 3x3 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_GRBG8STREAM_TO_RGB24STREAM_3X3(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_grbg8stream_to_rgb24stream_3x3, (width), (height), 3)
/**
* @brief Define a stream converter from BGGR8 to RGB24 with the 3x3 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_BGGR8STREAM_TO_RGB24STREAM_3X3(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_bggr8stream_to_rgb24stream_3x3, (width), (height), 3)
/**
* @brief Define a stream converter from GBRG8 to RGB24 with the 3x3 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_GBRG8STREAM_TO_RGB24STREAM_3X3(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_gbrg8stream_to_rgb24stream_3x3, (width), (height), 3)
/**
* @brief Define a stream converter from RGGB8 to RGB24 with the 2x2 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_RGGB8STREAM_TO_RGB24STREAM_2X2(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_rggb8stream_to_rgb24stream_2x2, (width), (height), 2)
/**
* @brief Define a stream converter from GBRG8 to RGB24 with the 2x2 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_GBRG8STREAM_TO_RGB24STREAM_2X2(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_gbrg8stream_to_rgb24stream_2x2, (width), (height), 2)
/**
* @brief Define a stream converter from BGGR8 to RGB24 with the 2x2 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_BGGR8STREAM_TO_RGB24STREAM_2X2(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_bggr8stream_to_rgb24stream_2x2, (width), (height), 2)
/**
* @brief Define a stream converter from GRBG8 to RGB24 with the 2x2 method
* @copydetails PIXEL_RGGB8STREAM_TO_RGB24STREAM_3X3()
*/
#define PIXEL_GRBG8STREAM_TO_RGB24STREAM_2X2(name, width, height) \
PIXEL_BAYER_DEFINE(name, pixel_grbg8stream_to_rgb24stream_2x2, (width), (height), 2)

/** @cond INTERNAL_HIDDEN */
#define PIXEL_BAYER_DEFINE(name, fn, width, height, window_height) \
PIXEL_STREAM_DEFINE((name), (fn), (width), (height), (width), (window_height) * (width))
void pixel_rggb8stream_to_rgb24stream_3x3(struct pixel_stream *strm);
void pixel_grbg8stream_to_rgb24stream_3x3(struct pixel_stream *strm);
void pixel_bggr8stream_to_rgb24stream_3x3(struct pixel_stream *strm);
void pixel_gbrg8stream_to_rgb24stream_3x3(struct pixel_stream *strm);
void pixel_rggb8stream_to_rgb24stream_2x2(struct pixel_stream *strm);
void pixel_gbrg8stream_to_rgb24stream_2x2(struct pixel_stream *strm);
void pixel_bggr8stream_to_rgb24stream_2x2(struct pixel_stream *strm);
void pixel_grbg8stream_to_rgb24stream_2x2(struct pixel_stream *strm);
/** @endcond */

#endif /* ZEPHYR_INCLUDE_PIXEL_BAYER_H_ */
136 changes: 136 additions & 0 deletions include/zephyr/pixel/formats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2025 tinyVision.ai Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_PIXEL_FORMATS_H_
#define ZEPHYR_INCLUDE_PIXEL_FORMATS_H_

#include <stdlib.h>
#include <stdint.h>

#include <zephyr/sys/util.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/pixel/stream.h>

/**
* @brief Get the luminance (luma channel) of an RGB24 pixel.
*
* @param rgb24 Pointer to an RGB24 pixel: red, green, blue channels.
*/
uint8_t pixel_rgb24_get_luma_bt709(const uint8_t rgb24[3]);

/**
* @brief Convert a line of pixel data from RGB332 to RGB24.
*
* See @ref video_pixel_formats for the definition of the input and output formats.
*
* @param src Buffer of the input line in the format, @c XXX in @c pixel_XXXline_to_YYYline().
* @param dst Buffer of the output line in the format, @c YYY in @c pixel_XXXline_to_YYYline().
* @param width Width of the lines in number of pixels.
*/
void pixel_rgb332line_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB24 to RGB332 little-endian.
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb24line_to_rgb332line(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB565 little-endian to RGB24.
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb565leline_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB565 big-endian to RGB24.
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb565beline_to_rgb24line(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB24 to RGB565 little-endian.
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb24line_to_rgb565leline(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB24 to RGB565 big-endian.
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb24line_to_rgb565beline(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from YUYV to RGB24 (BT.709 coefficients).
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_yuyvline_to_rgb24line_bt709(const uint8_t *src, uint8_t *dst, uint16_t width);
/**
* @brief Convert a line of pixel data from RGB24 to YUYV (BT.709 coefficients).
* @copydetails pixel_rgb332line_to_rgb24line()
*/
void pixel_rgb24line_to_yuyvline_bt709(const uint8_t *src, uint8_t *dst, uint16_t width);

/**
* @brief Convert a stream of pixel data from RGB332 to RGB24.
*
* @param name The symbol of the @ref pixel_stream that will be defined.
* @param width The total width of the input frame in number of pixels.
* @param height The total height of the input frame in number of pixels.
*/
#define PIXEL_RGB332STREAM_TO_RGB24STREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb332stream_to_rgb24stream, (width), (height), 1)
/**
* @brief Convert a stream of pixel data from RGB24 to RGB332
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB24STREAM_TO_RGB332STREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb332stream, (width), (height), 3)
/**
* @brief Convert a stream of pixel data from RGB565 little-endian to RGB24
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB565LESTREAM_TO_RGB24STREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb565lestream_to_rgb24stream, (width), (height), 2)
/**
* @brief Convert a stream of pixel data from RGB24 to RGB565 little-endian
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB24STREAM_TO_RGB565LESTREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb565lestream, (width), (height), 3)
/**
* @brief Convert a stream of pixel data from RGB565 big-endian to RGB24
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB565BESTREAM_TO_RGB24STREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb565bestream_to_rgb24stream, (width), (height), 2)
/**
* @brief Convert a stream of pixel data from RGB24 to RGB565 big-endian
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB24STREAM_TO_RGB565BESTREAM(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_rgb565bestream, (width), (height), 3)
/**
* @brief Convert a stream of pixel data from YUYV to RGB24 (BT.709 coefficients)
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_YUYVSTREAM_TO_RGB24STREAM_BT709(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_yuyvstream_to_rgb24stream_bt709, (width), (height), 2)
/**
* @brief Convert a stream of pixel data from RGB24 to YUYV (BT.709 coefficients)
* @copydetails PIXEL_RGB332STREAM_TO_RGB24STREAM()
*/
#define PIXEL_RGB24STREAM_TO_YUYVSTREAM_BT709(name, width, height) \
PIXEL_FORMAT_DEFINE(name, pixel_rgb24stream_to_yuyvstream_bt709, (width), (height), 3)

/** @cond INTERNAL_HIDDEN */
#define PIXEL_FORMAT_DEFINE(name, fn, width, height, bytes_per_pixel) \
PIXEL_STREAM_DEFINE(name, (fn), (width), (height), \
(width) * (bytes_per_pixel), 1 * (width) * (bytes_per_pixel))
void pixel_rgb24stream_to_rgb332stream(struct pixel_stream *strm);
void pixel_rgb332stream_to_rgb24stream(struct pixel_stream *strm);
void pixel_rgb565lestream_to_rgb24stream(struct pixel_stream *strm);
void pixel_rgb24stream_to_rgb565lestream(struct pixel_stream *strm);
void pixel_rgb565bestream_to_rgb24stream(struct pixel_stream *strm);
void pixel_rgb24stream_to_rgb565bestream(struct pixel_stream *strm);
void pixel_yuyvstream_to_rgb24stream_bt709(struct pixel_stream *strm);
void pixel_rgb24stream_to_yuyvstream_bt709(struct pixel_stream *strm);
/** @endcond */

#endif /* ZEPHYR_INCLUDE_PIXEL_FORMATS_H_ */
Loading