• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <cstdint>
4 #include <string>
5 #include <stdexcept>
6 
7 namespace kms
8 {
MakeFourCC(const char * fourcc)9 constexpr uint32_t MakeFourCC(const char* fourcc)
10 {
11 	return fourcc[0] | (fourcc[1] << 8) | (fourcc[2] << 16) | (fourcc[3] << 24);
12 }
13 
14 enum class PixelFormat : uint32_t {
15 	Undefined = 0,
16 
17 	NV12 = MakeFourCC("NV12"),
18 	NV21 = MakeFourCC("NV21"),
19 	NV16 = MakeFourCC("NV16"),
20 	NV61 = MakeFourCC("NV61"),
21 
22 	YUV420 = MakeFourCC("YU12"),
23 	YVU420 = MakeFourCC("YV12"),
24 	YUV422 = MakeFourCC("YU16"),
25 	YVU422 = MakeFourCC("YV16"),
26 	YUV444 = MakeFourCC("YU24"),
27 	YVU444 = MakeFourCC("YV24"),
28 
29 	UYVY = MakeFourCC("UYVY"),
30 	YUYV = MakeFourCC("YUYV"),
31 	YVYU = MakeFourCC("YVYU"),
32 	VYUY = MakeFourCC("VYUY"),
33 
34 	XRGB8888 = MakeFourCC("XR24"),
35 	XBGR8888 = MakeFourCC("XB24"),
36 	RGBX8888 = MakeFourCC("RX24"),
37 	BGRX8888 = MakeFourCC("BX24"),
38 
39 	ARGB8888 = MakeFourCC("AR24"),
40 	ABGR8888 = MakeFourCC("AB24"),
41 	RGBA8888 = MakeFourCC("RA24"),
42 	BGRA8888 = MakeFourCC("BA24"),
43 
44 	RGB888 = MakeFourCC("RG24"),
45 	BGR888 = MakeFourCC("BG24"),
46 
47 	RGB332 = MakeFourCC("RGB8"),
48 
49 	RGB565 = MakeFourCC("RG16"),
50 	BGR565 = MakeFourCC("BG16"),
51 
52 	XRGB4444 = MakeFourCC("XR12"),
53 	XRGB1555 = MakeFourCC("XR15"),
54 
55 	ARGB4444 = MakeFourCC("AR12"),
56 	ARGB1555 = MakeFourCC("AR15"),
57 
58 	XRGB2101010 = MakeFourCC("XR30"),
59 	XBGR2101010 = MakeFourCC("XB30"),
60 	RGBX1010102 = MakeFourCC("RX30"),
61 	BGRX1010102 = MakeFourCC("BX30"),
62 
63 	ARGB2101010 = MakeFourCC("AR30"),
64 	ABGR2101010 = MakeFourCC("AB30"),
65 	RGBA1010102 = MakeFourCC("RA30"),
66 	BGRA1010102 = MakeFourCC("BA30"),
67 };
68 
FourCCToPixelFormat(const std::string & fourcc)69 static inline PixelFormat FourCCToPixelFormat(const std::string& fourcc)
70 {
71 	return (PixelFormat)MakeFourCC(fourcc.c_str());
72 }
73 
PixelFormatToFourCC(PixelFormat f)74 static inline std::string PixelFormatToFourCC(PixelFormat f)
75 {
76 	char buf[5] = { (char)(((uint32_t)f >> 0) & 0xff),
77 			(char)(((uint32_t)f >> 8) & 0xff),
78 			(char)(((uint32_t)f >> 16) & 0xff),
79 			(char)(((uint32_t)f >> 24) & 0xff),
80 			0 };
81 	return std::string(buf);
82 }
83 
84 enum class PixelColorType {
85 	RGB,
86 	YUV,
87 };
88 
89 struct PixelFormatPlaneInfo {
90 	uint8_t bitspp;
91 	uint8_t xsub;
92 	uint8_t ysub;
93 };
94 
95 struct PixelFormatInfo {
96 	PixelColorType type;
97 	uint8_t num_planes;
98 	struct PixelFormatPlaneInfo planes[4];
99 };
100 
101 const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format);
102 
103 } // namespace kms
104