-
Notifications
You must be signed in to change notification settings - Fork 4
/
v210.cpp
186 lines (151 loc) · 6.45 KB
/
v210.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
#include "p2p.h"
namespace P2P_NAMESPACE {
namespace {
template <class Endian>
void unpack_v210(const void *src, void * const dst[4], unsigned left, unsigned right)
{
const unsigned lsb_10b = 0x3FF;
const uint32_t *src_p = static_cast<const uint32_t *>(src);
uint16_t *dst_p[3] = { static_cast<uint16_t *>(dst[0]), static_cast<uint16_t *>(dst[1]), static_cast<uint16_t *>(dst[2]) };
// v210 packs 6 pixels in 4 DWORDs.
left = left - (left % 6);
// Adjust pointers.
src_p += left * 4 / 6;
dst_p[C_Y] += left;
dst_p[C_U] += left / 2;
dst_p[C_V] += left / 2;
for (unsigned i = left; i < right - right % 6; i += 6) {
uint32_t w0 = detail::convert_endian<Endian>(*src_p++);
uint32_t w1 = detail::convert_endian<Endian>(*src_p++);
uint32_t w2 = detail::convert_endian<Endian>(*src_p++);
uint32_t w3 = detail::convert_endian<Endian>(*src_p++);
*dst_p[C_U]++ = static_cast<uint16_t>((w0 >> 0) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w0 >> 10) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w0 >> 20) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w1 >> 0) & lsb_10b);
*dst_p[C_U]++ = static_cast<uint16_t>((w1 >> 10) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w1 >> 20) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w2 >> 0) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w2 >> 10) & lsb_10b);
*dst_p[C_U]++ = static_cast<uint16_t>((w2 >> 20) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w3 >> 0) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w3 >> 10) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w3 >> 20) & lsb_10b);
}
if (right % 6) {
// No check needed as v210 is 128-byte aligned.
uint32_t w0 = detail::convert_endian<Endian>(*src_p++);
uint32_t w1 = detail::convert_endian<Endian>(*src_p++);
uint32_t w2 = detail::convert_endian<Endian>(*src_p++);
uint32_t w3 = detail::convert_endian<Endian>(*src_p++);
{
*dst_p[C_U]++ = static_cast<uint16_t>((w0 >> 0) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w0 >> 10) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w0 >> 20) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w1 >> 0) & lsb_10b);
}
if (right % 6 > 2) {
*dst_p[C_U]++ = static_cast<uint16_t>((w1 >> 10) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w1 >> 20) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w2 >> 0) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w2 >> 10) & lsb_10b);
}
if (right % 6 > 4) {
*dst_p[C_U]++ = static_cast<uint16_t>((w2 >> 20) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w3 >> 0) & lsb_10b);
*dst_p[C_V]++ = static_cast<uint16_t>((w3 >> 10) & lsb_10b);
*dst_p[C_Y]++ = static_cast<uint16_t>((w3 >> 20) & lsb_10b);
}
}
}
template <class Endian>
void pack_v210(const void * const src[4], void *dst, unsigned left, unsigned right)
{
const unsigned lsb_10b = 0x3FF;
const uint16_t *src_p[3] = { static_cast<const uint16_t *>(src[0]), static_cast<const uint16_t *>(src[1]), static_cast<const uint16_t *>(src[2]) };
uint32_t *dst_p = static_cast<uint32_t *>(dst);
// v210 packs 6 pixels in 4 DWORDs.
left = left - (left % 6);
// Adjust pointers.
src_p[C_Y] += left;
src_p[C_U] += left / 2;
src_p[C_V] += left / 2;
dst_p += left * 4 / 6;
for (unsigned i = left; i < right - right % 6; i += 6) {
uint32_t w0 = 0;
uint32_t w1 = 0;
uint32_t w2 = 0;
uint32_t w3 = 0;
w0 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 0;
w0 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 10;
w0 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 20;
w1 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 0;
w1 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 10;
w1 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 20;
w2 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 0;
w2 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 10;
w2 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 20;
w3 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 0;
w3 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 10;
w3 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 20;
*dst_p++ = detail::convert_endian<Endian>(w0);
*dst_p++ = detail::convert_endian<Endian>(w1);
*dst_p++ = detail::convert_endian<Endian>(w2);
*dst_p++ = detail::convert_endian<Endian>(w3);
}
if (right % 6) {
uint32_t w0 = 0;
uint32_t w1 = 0;
uint32_t w2 = 0;
uint32_t w3 = 0;
{
w0 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 0;
w0 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 10;
w0 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 20;
w1 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 0;
}
if (right % 6 > 2) {
w1 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 10;
w1 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 20;
w2 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 0;
w2 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 10;
}
if (right % 6 > 4) {
w2 |= static_cast<uint32_t>(*src_p[C_U]++ & lsb_10b) << 20;
w3 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 0;
w3 |= static_cast<uint32_t>(*src_p[C_V]++ & lsb_10b) << 10;
w3 |= static_cast<uint32_t>(*src_p[C_Y]++ & lsb_10b) << 20;
}
// No check needed as v210 is 128-byte aligned.
*dst_p++ = detail::convert_endian<Endian>(w0);
*dst_p++ = detail::convert_endian<Endian>(w1);
*dst_p++ = detail::convert_endian<Endian>(w2);
*dst_p++ = detail::convert_endian<Endian>(w3);
}
}
} // namespace
void packed_to_planar<packed_v210_be>::unpack(const void *src, void * const dst[4], unsigned left, unsigned right)
{
unpack_v210<big_endian_t>(src, dst, left, right);
}
void packed_to_planar<packed_v210_le>::unpack(const void *src, void * const dst[4], unsigned left, unsigned right)
{
unpack_v210<little_endian_t>(src, dst, left, right);
}
void planar_to_packed<packed_v210_be, false>::pack(const void * const src[4], void *dst, unsigned left, unsigned right)
{
pack_v210<big_endian_t>(src, dst, left, right);
}
void planar_to_packed<packed_v210_be, true>::pack(const void * const src[4], void *dst, unsigned left, unsigned right)
{
pack_v210<big_endian_t>(src, dst, left, right);
}
void planar_to_packed<packed_v210_le, false>::pack(const void * const src[4], void *dst, unsigned left, unsigned right)
{
pack_v210<little_endian_t>(src, dst, left, right);
}
void planar_to_packed<packed_v210_le, true>::pack(const void * const src[4], void *dst, unsigned left, unsigned right)
{
pack_v210<little_endian_t>(src, dst, left, right);
}
} // namespace p2p