-
Notifications
You must be signed in to change notification settings - Fork 15
/
rgb2yuv.h
120 lines (116 loc) · 4.11 KB
/
rgb2yuv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//==============================================================================
// xxYUV : rgb2yuv Header
//
// Copyright (c) 2020-2021 TAiGA
// https://github.com/metarutaiga/xxYUV
//==============================================================================
#pragma once
#ifndef xxYUV_EXPORT
#define xxYUV_EXPORT
#endif
//------------------------------------------------------------------------------
typedef struct _rgb2yuv_parameter
{
int width;
int height;
const void* rgb;
int componentRGB;
int strideRGB;
bool swizzleRGB;
void* y;
void* u;
void* v;
int alignWidth;
int alignHeight;
int alignSize;
int strideY;
int strideU;
int strideV;
bool videoRange;
} rgb2yuv_parameter;
//------------------------------------------------------------------------------
xxYUV_EXPORT void rgb2yuv_yu12(const rgb2yuv_parameter* parameter);
xxYUV_EXPORT void rgb2yuv_yv12(const rgb2yuv_parameter* parameter);
xxYUV_EXPORT void rgb2yuv_nv12(const rgb2yuv_parameter* parameter);
xxYUV_EXPORT void rgb2yuv_nv21(const rgb2yuv_parameter* parameter);
//------------------------------------------------------------------------------
#ifndef xxYUV_DEPRECATED
//------------------------------------------------------------------------------
inline void rgb2yuv_yu12(int width, int height, const void* rgb, void* yuv, int rgbWidth = 3, bool rgbSwizzle = false, bool fullRange = true, int strideRGB = 0, int alignWidth = 16, int alignHeight = 1, int alignSize = 1)
{
rgb2yuv_parameter parameter =
{
.width = width,
.height = height,
.rgb = rgb,
.componentRGB = rgbWidth,
.strideRGB = strideRGB,
.swizzleRGB = rgbSwizzle,
.y = yuv,
.alignWidth = alignWidth,
.alignHeight = alignHeight,
.alignSize = alignSize,
.videoRange = !fullRange,
};
rgb2yuv_yu12(¶meter);
}
//------------------------------------------------------------------------------
inline void rgb2yuv_yv12(int width, int height, const void* rgb, void* yuv, int rgbWidth = 3, bool rgbSwizzle = false, bool fullRange = true, int strideRGB = 0, int alignWidth = 16, int alignHeight = 1, int alignSize = 1)
{
rgb2yuv_parameter parameter =
{
.width = width,
.height = height,
.rgb = rgb,
.componentRGB = rgbWidth,
.strideRGB = strideRGB,
.swizzleRGB = rgbSwizzle,
.y = yuv,
.alignWidth = alignWidth,
.alignHeight = alignHeight,
.alignSize = alignSize,
.videoRange = !fullRange,
};
rgb2yuv_yv12(¶meter);
}
//------------------------------------------------------------------------------
inline void rgb2yuv_nv12(int width, int height, const void* rgb, void* yuv, int rgbWidth = 3, bool rgbSwizzle = false, bool fullRange = true, int strideRGB = 0, int alignWidth = 16, int alignHeight = 1, int alignSize = 1)
{
rgb2yuv_parameter parameter =
{
.width = width,
.height = height,
.rgb = rgb,
.componentRGB = rgbWidth,
.strideRGB = strideRGB,
.swizzleRGB = rgbSwizzle,
.y = yuv,
.alignWidth = alignWidth,
.alignHeight = alignHeight,
.alignSize = alignSize,
.videoRange = !fullRange,
};
rgb2yuv_nv12(¶meter);
}
//------------------------------------------------------------------------------
inline void rgb2yuv_nv21(int width, int height, const void* rgb, void* yuv, int rgbWidth = 3, bool rgbSwizzle = false, bool fullRange = true, int strideRGB = 0, int alignWidth = 16, int alignHeight = 1, int alignSize = 1)
{
rgb2yuv_parameter parameter =
{
.width = width,
.height = height,
.rgb = rgb,
.componentRGB = rgbWidth,
.strideRGB = strideRGB,
.swizzleRGB = rgbSwizzle,
.y = yuv,
.alignWidth = alignWidth,
.alignHeight = alignHeight,
.alignSize = alignSize,
.videoRange = !fullRange,
};
rgb2yuv_nv21(¶meter);
}
//------------------------------------------------------------------------------
#endif
//------------------------------------------------------------------------------