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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
/*
* DSP utils
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* DSP utils
*/
#include "pixels.h"
/* draw the edges of width 'w' of an image of size width, height */
// FIXME: Check that this is OK for MPEG-4 interlaced.
static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
int w, int h, int sides)
{
uint8_t *ptr = buf, *last_line;
int i;
/* left and right */
for (i = 0; i < height; i++) {
memset(ptr - w, ptr[0], w);
memset(ptr + width, ptr[width - 1], w);
ptr += wrap;
}
/* top and bottom + corners */
buf -= w;
last_line = buf + (height - 1) * wrap;
if (sides & EDGE_TOP)
for (i = 0; i < h; i++)
// top
memcpy(buf - (i + 1) * wrap, buf, width + w + w);
if (sides & EDGE_BOTTOM)
for (i = 0; i < h; i++)
// bottom
memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
}
static void clear_block_8_c(int16_t *block)
{
memset(block, 0, sizeof(int16_t) * 64);
}
static void clear_blocks_8_c(int16_t *blocks)
{
memset(blocks, 0, sizeof(int16_t) * 6 * 64);
}
#define PIXOP2(OPNAME, OP) \
static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int h) \
{ \
int i; \
\
for (i = 0; i < h; i++) { \
uint32_t a, b; \
a = AV_RN32(&src1[i * src_stride1]); \
b = AV_RN32(&src2[i * src_stride2]); \
OP(*((uint32_t *) &dst[i * dst_stride]), \
no_rnd_avg32(a, b)); \
a = AV_RN32(&src1[i * src_stride1 + 4]); \
b = AV_RN32(&src2[i * src_stride2 + 4]); \
OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
no_rnd_avg32(a, b)); \
} \
} \
\
static inline void OPNAME ## _no_rnd_pixels16_l2_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int h) \
{ \
OPNAME ## _no_rnd_pixels8_l2_8(dst, src1, src2, dst_stride, \
src_stride1, src_stride2, h); \
OPNAME ## _no_rnd_pixels8_l2_8(dst + 8, \
src1 + 8, \
src2 + 8, \
dst_stride, src_stride1, \
src_stride2, h); \
} \
\
static inline void OPNAME ## _pixels8_l4_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
const uint8_t *src3, \
const uint8_t *src4, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int src_stride3, \
int src_stride4, \
int h) \
{ \
/* FIXME HIGH BIT DEPTH */ \
int i; \
\
for (i = 0; i < h; i++) { \
uint32_t a, b, c, d, l0, l1, h0, h1; \
a = AV_RN32(&src1[i * src_stride1]); \
b = AV_RN32(&src2[i * src_stride2]); \
c = AV_RN32(&src3[i * src_stride3]); \
d = AV_RN32(&src4[i * src_stride4]); \
l0 = (a & 0x03030303UL) + \
(b & 0x03030303UL) + \
0x02020202UL; \
h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
((b & 0xFCFCFCFCUL) >> 2); \
l1 = (c & 0x03030303UL) + \
(d & 0x03030303UL); \
h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
((d & 0xFCFCFCFCUL) >> 2); \
OP(*((uint32_t *) &dst[i * dst_stride]), \
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
a = AV_RN32(&src1[i * src_stride1 + 4]); \
b = AV_RN32(&src2[i * src_stride2 + 4]); \
c = AV_RN32(&src3[i * src_stride3 + 4]); \
d = AV_RN32(&src4[i * src_stride4 + 4]); \
l0 = (a & 0x03030303UL) + \
(b & 0x03030303UL) + \
0x02020202UL; \
h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
((b & 0xFCFCFCFCUL) >> 2); \
l1 = (c & 0x03030303UL) + \
(d & 0x03030303UL); \
h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
((d & 0xFCFCFCFCUL) >> 2); \
OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
} \
} \
\
static inline void OPNAME ## _no_rnd_pixels8_l4_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
const uint8_t *src3, \
const uint8_t *src4, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int src_stride3, \
int src_stride4, \
int h) \
{ \
/* FIXME HIGH BIT DEPTH */ \
int i; \
\
for (i = 0; i < h; i++) { \
uint32_t a, b, c, d, l0, l1, h0, h1; \
a = AV_RN32(&src1[i * src_stride1]); \
b = AV_RN32(&src2[i * src_stride2]); \
c = AV_RN32(&src3[i * src_stride3]); \
d = AV_RN32(&src4[i * src_stride4]); \
l0 = (a & 0x03030303UL) + \
(b & 0x03030303UL) + \
0x01010101UL; \
h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
((b & 0xFCFCFCFCUL) >> 2); \
l1 = (c & 0x03030303UL) + \
(d & 0x03030303UL); \
h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
((d & 0xFCFCFCFCUL) >> 2); \
OP(*((uint32_t *) &dst[i * dst_stride]), \
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
a = AV_RN32(&src1[i * src_stride1 + 4]); \
b = AV_RN32(&src2[i * src_stride2 + 4]); \
c = AV_RN32(&src3[i * src_stride3 + 4]); \
d = AV_RN32(&src4[i * src_stride4 + 4]); \
l0 = (a & 0x03030303UL) + \
(b & 0x03030303UL) + \
0x01010101UL; \
h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
((b & 0xFCFCFCFCUL) >> 2); \
l1 = (c & 0x03030303UL) + \
(d & 0x03030303UL); \
h1 = ((c & 0xFCFCFCFCUL) >> 2) + \
((d & 0xFCFCFCFCUL) >> 2); \
OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
} \
} \
\
static inline void OPNAME ## _pixels16_l4_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
const uint8_t *src3, \
const uint8_t *src4, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int src_stride3, \
int src_stride4, \
int h) \
{ \
OPNAME ## _pixels8_l4_8(dst, src1, src2, src3, src4, dst_stride, \
src_stride1, src_stride2, src_stride3, \
src_stride4, h); \
OPNAME ## _pixels8_l4_8(dst + 8, \
src1 + 8, src2 + 8, \
src3 + 8, src4 + 8, \
dst_stride, src_stride1, src_stride2, \
src_stride3, src_stride4, h); \
} \
\
static inline void OPNAME ## _no_rnd_pixels16_l4_8(uint8_t *dst, \
const uint8_t *src1, \
const uint8_t *src2, \
const uint8_t *src3, \
const uint8_t *src4, \
int dst_stride, \
int src_stride1, \
int src_stride2, \
int src_stride3, \
int src_stride4, \
int h) \
{ \
OPNAME ## _no_rnd_pixels8_l4_8(dst, src1, src2, src3, src4, \
dst_stride, src_stride1, \
src_stride2, src_stride3, \
src_stride4, h); \
OPNAME ## _no_rnd_pixels8_l4_8(dst + 8, \
src1 + 8, src2 + 8, \
src3 + 8, src4 + 8, \
dst_stride, src_stride1, \
src_stride2, src_stride3, \
src_stride4, h); \
} \
#define op_avg(a, b) a = rnd_avg32(a, b)
#define op_put(a, b) a = b
#define put_no_rnd_pixels8_8_c put_pixels8_8_c
PIXOP2(avg, op_avg)
PIXOP2(put, op_put)
#undef op_avg
#undef op_put
|