Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/mm/pixel.h

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 25 янв. 2026 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_MM_PIXEL_H_
23 #define LSP_PLUG_IN_MM_PIXEL_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #include <lsp-plug.in/common/types.h>
28
29 namespace lsp
30 {
31 namespace mm
32 {
33 enum pixel_format_t
34 {
35 PIXFMT_DEFAULT, /* Default pixel format */
36 PIXFMT_G1, /* 1 bit per pixel, gray */
37 PIXFMT_G2, /* 2 bits per pixel, gray */
38 PIXFMT_G4, /* 4 bits per pixel, gray */
39 PIXFMT_G8, /* 8 bits per pixel, gray */
40 PIXFMT_A1, /* 1 bit per pixel, alpha */
41 PIXFMT_A2, /* 2 bits per pixel, alpha */
42 PIXFMT_A4, /* 4 bits per pixel, alpha */
43 PIXFMT_A8, /* 8 bits per pixel, alpha */
44 PIXFMT_RGB888, /* RGB: 8 bits per each component */
45 PIXFMT_BGR888, /* BGR: 8 bits per each component */
46 PIXFMT_RGBA8888, /* RGBA: 8 bits per each component */
47 PIXFMT_BGRA8888, /* BGRA: 8 bits per each component */
48 PIXFMT_PRGBA8888, /* PRGBA: 8 bits per each component */
49 PIXFMT_PBGRA8888, /* PRGBA: 8 bits per each component */
50 };
51
52 /**
53 * Pixel conversion function
54 * @param dst desination buffer to store data
55 * @param src source buffer to read data
56 * @param count number of pixels to convert
57 */
58 typedef void (*pixel_conversion_t)(uint8_t *dst, const uint8_t *src, size_t count);
59
60 /**
61 * Get number of bits used to represent a pixel
62 * @param format pixel format
63 * @return number of bits used to represent a pixel
64 */
65 size_t bits_per_pixel(pixel_format_t format) noexcept;
66
67 /**
68 * Get actual number of bits used to represent a pixel on a device
69 * @param format pixel format
70 * @return number of bits used to represent a pixel
71 */
72 size_t device_bits_per_pixel(pixel_format_t format) noexcept;
73
74 /**
75 * Get pixel format name
76 * @param format pixel format
77 * @return pixel format name
78 */
79 const char *pixel_format_name(pixel_format_t format) noexcept;
80
81 /**
82 * Check that pixels of format dst have the same representation in memory
83 * and do not need conversion from format src
84 * @param dst destination pixel format
85 * @param src source pixel format
86 * @return true if there is no conversion needed
87 */
88 bool is_exact_copy_of_pixel(pixel_format_t dst, pixel_format_t src) noexcept;
89
90 /**
91 * Perform conversion between different pixel formats.
92 *
93 * @param dst desination buffer to store data
94 * @param src source buffer to read data
95 * @param dst_fmt destination pixel format
96 * @param src_fmt source pixel format
97 * @param count number of pixels to convert
98 */
99 void convert_pixels(uint8_t *dst, const uint8_t *src, pixel_format_t dst_fmt, pixel_format_t src_fmt, size_t count) noexcept;
100
101 /**
102 * Get pixel conversion function.
103 *
104 * @param dst_fmt destination pixel format
105 * @param src_fmt source pixel format
106 * @return pixel conversion function or NULL if no conversion is needed (@see is_exact_copy_of_pixel).
107 */
108 pixel_conversion_t pixel_convert_function(pixel_format_t dst_fmt, pixel_format_t src_fmt) noexcept;
109
110 } /* namespace mm */
111 } /* namespace lsp */
112
113 #endif /* LSP_PLUG_IN_MM_PIXEL_H_ */