Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/include/render/pixel_format.h (2.1K)
1 #ifndef FX_RENDER_PIXEL_FORMAT_H
2 #define FX_RENDER_PIXEL_FORMAT_H
3
4 #include <wayland-server-protocol.h>
5
6 /**
7 * Information about a pixel format.
8 *
9 * A pixel format is identified via its DRM four character code (see <drm_fourcc.h>).
10 *
11 * Simple formats have a block size of 1×1 pixels and bytes_per_block contains
12 * the number of bytes per pixel (including padding).
13 *
14 * Tiled formats (e.g. sub-sampled YCbCr) are described with a block size
15 * greater than 1×1 pixels. A block is a rectangle of pixels which are stored
16 * next to each other in a byte-aligned memory region.
17 */
18 struct wlr_pixel_format_info {
19 uint32_t drm_format;
20
21 /* Equivalent of the format if it has an alpha channel,
22 * DRM_FORMAT_INVALID (0) if NA
23 */
24 uint32_t opaque_substitute;
25
26 /* Bytes per block (including padding) */
27 uint32_t bytes_per_block;
28 /* Size of a block in pixels (zero for 1×1) */
29 uint32_t block_width, block_height;
30 };
31
32 /**
33 * Get pixel format information from a DRM FourCC.
34 *
35 * NULL is returned if the pixel format is unknown.
36 */
37 const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt);
38 /**
39 * Get the number of pixels per block for a pixel format.
40 */
41 uint32_t pixel_format_info_pixels_per_block(const struct wlr_pixel_format_info *info);
42 /**
43 * Get the minimum stride for a given pixel format and width.
44 */
45 int32_t pixel_format_info_min_stride(const struct wlr_pixel_format_info *info, int32_t width);
46 /**
47 * Check whether a stride is large enough for a given pixel format and width.
48 */
49 bool pixel_format_info_check_stride(const struct wlr_pixel_format_info *info,
50 int32_t stride, int32_t width);
51
52 /**
53 * Convert an enum wl_shm_format to a DRM FourCC.
54 */
55 uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt);
56 /**
57 * Convert a DRM FourCC to an enum wl_shm_format.
58 */
59 enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt);
60
61 /**
62 * Return true if the DRM FourCC fmt has an alpha channel, false otherwise.
63 */
64 bool pixel_format_has_alpha(uint32_t fmt);
65
66 /**
67 * Return true if the DRM FourCC fmt belongs to a YCbCr colorspace family, false otherwise.
68 */
69 bool pixel_format_is_ycbcr(uint32_t fmt);
70
71 #endif