-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathyuv2yuva.cpp
188 lines (162 loc) · 7.24 KB
/
yuv2yuva.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//==============================================================================
// xxYUV : yuv2yuva Source
//
// Copyright (c) 2020-2021 TAiGA
// https://github.com/metarutaiga/xxYUV
//==============================================================================
#if defined(__llvm__)
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
#include "cpu.h"
#include "yuv2yuva.inl"
#include "yuv2yuva.h"
#define align(v, a) ((v) + ((a) - 1) & ~((a) - 1))
//------------------------------------------------------------------------------
void yuv2yuva_yu12(const yuv2yuva_parameter* parameter)
{
int width = parameter->width;
int height = parameter->height;
const void* y = parameter->y;
const void* u = parameter->u;
const void* v = parameter->v;
int alignWidth = parameter->alignWidth ? parameter->alignWidth : 16;
int alignHeight = parameter->alignHeight ? parameter->alignHeight : 1;
int alignSize = parameter->alignSize ? parameter->alignSize : 1;
int strideY = parameter->strideY ? parameter->strideY : align(width, alignWidth);
int strideU = parameter->strideU ? parameter->strideU : align(width, alignWidth) / 2;
int strideV = parameter->strideV ? parameter->strideV : align(width, alignWidth) / 2;
int sizeY = align(strideY * align(height, alignHeight), alignSize);
int sizeU = align(strideU * align(height, alignHeight) / 2, alignSize);
void* output = parameter->output;
bool swizzleOutput = parameter->swizzleOutput;
int strideOutput = parameter->strideOutput ? parameter->strideOutput : 4 * width;
if (strideOutput < 0)
{
output = (char*)output - (strideOutput * (height - 1));
}
u = u ? u : (char*)y + sizeY;
v = v ? v : (char*)y + sizeY + sizeU;
void (*converter)(int width, int height, const void* y, const void* u, const void* v, int strideY, int strideU, int strideV, void* output, int strideOutput);
if (swizzleOutput)
{
static auto select = yuv2yuva_select(false, false, 2, 1, 0, 3);
converter = select;
}
else
{
static auto select = yuv2yuva_select(false, false, 0, 1, 2, 3);
converter = select;
}
converter(width, height, y, u, v, strideY, strideU, strideV, output, strideOutput);
}
//------------------------------------------------------------------------------
void yuv2yuva_yv12(const yuv2yuva_parameter* parameter)
{
int width = parameter->width;
int height = parameter->height;
const void* y = parameter->y;
const void* u = parameter->u;
const void* v = parameter->v;
int alignWidth = parameter->alignWidth ? parameter->alignWidth : 16;
int alignHeight = parameter->alignHeight ? parameter->alignHeight : 1;
int alignSize = parameter->alignSize ? parameter->alignSize : 1;
int strideY = parameter->strideY ? parameter->strideY : align(width, alignWidth);
int strideU = parameter->strideU ? parameter->strideU : align(width, alignWidth) / 2;
int strideV = parameter->strideV ? parameter->strideV : align(width, alignWidth) / 2;
int sizeY = align(strideY * align(height, alignHeight), alignSize);
int sizeU = align(strideU * align(height, alignHeight) / 2, alignSize);
void* output = parameter->output;
bool swizzleOutput = parameter->swizzleOutput;
int strideOutput = parameter->strideOutput ? parameter->strideOutput : 4 * width;
if (strideOutput < 0)
{
output = (char*)output - (strideOutput * (height - 1));
}
u = u ? u : (char*)y + sizeY + sizeU;
v = v ? v : (char*)y + sizeY;
void (*converter)(int width, int height, const void* y, const void* u, const void* v, int strideY, int strideU, int strideV, void* output, int strideOutput);
if (swizzleOutput)
{
static auto select = yuv2yuva_select(false, false, 2, 1, 0, 3);
converter = select;
}
else
{
static auto select = yuv2yuva_select(false, false, 0, 1, 2, 3);
converter = select;
}
converter(width, height, y, u, v, strideY, strideU, strideV, output, strideOutput);
}
//------------------------------------------------------------------------------
void yuv2yuva_nv12(const yuv2yuva_parameter* parameter)
{
int width = parameter->width;
int height = parameter->height;
const void* y = parameter->y;
const void* u = parameter->u;
const void* v = parameter->v;
int alignWidth = parameter->alignWidth ? parameter->alignWidth : 16;
int alignHeight = parameter->alignHeight ? parameter->alignHeight : 1;
int alignSize = parameter->alignSize ? parameter->alignSize : 1;
int strideY = parameter->strideY ? parameter->strideY : align(width, alignWidth);
int sizeY = align(strideY * align(height, alignHeight), alignSize);
int sizeUV = align(strideY * align(height, alignHeight) / 2, alignSize);
void* output = parameter->output;
bool swizzleOutput = parameter->swizzleOutput;
int strideOutput = parameter->strideOutput ? parameter->strideOutput : 4 * width;
if (strideOutput < 0)
{
output = (char*)output - (strideOutput * (height - 1));
}
u = u ? u : (char*)y + sizeY;
v = v ? v : (char*)y + sizeY + 1;
void (*converter)(int width, int height, const void* y, const void* u, const void* v, int strideY, int strideU, int strideV, void* output, int strideOutput);
if (swizzleOutput)
{
static auto select = yuv2yuva_select(true, true, 2, 1, 0, 3);
converter = select;
}
else
{
static auto select = yuv2yuva_select(true, true, 0, 1, 2, 3);
converter = select;
}
converter(width, height, y, u, v, strideY, strideY, strideY, output, strideOutput);
}
//------------------------------------------------------------------------------
void yuv2yuva_nv21(const yuv2yuva_parameter* parameter)
{
int width = parameter->width;
int height = parameter->height;
const void* y = parameter->y;
const void* u = parameter->u;
const void* v = parameter->v;
int alignWidth = parameter->alignWidth ? parameter->alignWidth : 16;
int alignHeight = parameter->alignHeight ? parameter->alignHeight : 1;
int alignSize = parameter->alignSize ? parameter->alignSize : 1;
int strideY = parameter->strideY ? parameter->strideY : align(width, alignWidth);
int sizeY = align(strideY * align(height, alignHeight), alignSize);
int sizeUV = align(strideY * align(height, alignHeight) / 2, alignSize);
void* output = parameter->output;
bool swizzleOutput = parameter->swizzleOutput;
int strideOutput = parameter->strideOutput ? parameter->strideOutput : 4 * width;
if (strideOutput < 0)
{
output = (char*)output - (strideOutput * (height - 1));
}
u = u ? u : (char*)y + sizeY + 1;
v = v ? v : (char*)y + sizeY;
void (*converter)(int width, int height, const void* y, const void* u, const void* v, int strideY, int strideU, int strideV, void* output, int strideOutput);
if (swizzleOutput)
{
static auto select = yuv2yuva_select(true, false, 2, 1, 0, 3);
converter = select;
}
else
{
static auto select = yuv2yuva_select(true, false, 0, 1, 2, 3);
converter = select;
}
converter(width, height, y, u, v, strideY, strideY, strideY, output, strideOutput);
}
//------------------------------------------------------------------------------