• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <cstdint>
4 #include <string>
5 
6 namespace kms
7 {
MakeFourCC(const char * fourcc)8 constexpr uint32_t MakeFourCC(const char *fourcc)
9 {
10 	return fourcc[0] | (fourcc[1] << 8) | (fourcc[2] << 16) | (fourcc[3] << 24);
11 }
12 
13 enum class PixelFormat : uint32_t
14 {
15 	Undefined = 0,
16 
17 	NV12 = MakeFourCC("NV12"),
18 	NV21 = MakeFourCC("NV21"),
19 
20 	UYVY = MakeFourCC("UYVY"),
21 	YUYV = MakeFourCC("YUYV"),
22 	YVYU = MakeFourCC("YVYU"),
23 	VYUY = MakeFourCC("VYUY"),
24 
25 	XRGB8888 = MakeFourCC("XR24"),
26 	XBGR8888 = MakeFourCC("XB24"),
27 	ARGB8888 = MakeFourCC("AR24"),
28 	ABGR8888 = MakeFourCC("AB24"),
29 
30 	RGB888 = MakeFourCC("RG24"),
31 	BGR888 = MakeFourCC("BG24"),
32 
33 	RGB565 = MakeFourCC("RG16"),
34 	BGR565 = MakeFourCC("BG16"),
35 };
36 
FourCCToPixelFormat(const std::string & fourcc)37 static inline PixelFormat FourCCToPixelFormat(const std::string& fourcc)
38 {
39 	return (PixelFormat)MakeFourCC(fourcc.c_str());
40 }
41 
PixelFormatToFourCC(PixelFormat f)42 static inline std::string PixelFormatToFourCC(PixelFormat f)
43 {
44 	char buf[5] = { (char)(((int)f >> 0) & 0xff),
45 			(char)(((int)f >> 8) & 0xff),
46 			(char)(((int)f >> 16) & 0xff),
47 			(char)(((int)f >> 24) & 0xff),
48 			0 };
49 	return std::string(buf);
50 }
51 
52 struct PixelFormatPlaneInfo
53 {
54 	uint8_t bitspp;
55 	uint8_t xsub;
56 	uint8_t ysub;
57 };
58 
59 struct PixelFormatInfo
60 {
61 	uint8_t num_planes;
62 	struct PixelFormatPlaneInfo planes[4];
63 };
64 
65 const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format);
66 
67 }
68