Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * DSP utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include <stddef.h> | ||
24 | |||
25 | #include "libavutil/attributes.h" | ||
26 | #include "libavutil/internal.h" | ||
27 | #include "libavutil/mem_internal.h" | ||
28 | #include "avcodec.h" | ||
29 | #include "copy_block.h" | ||
30 | #include "mathops.h" | ||
31 | #include "simple_idct.h" | ||
32 | #include "me_cmp.h" | ||
33 | #include "mpegvideoenc.h" | ||
34 | #include "config.h" | ||
35 | #include "config_components.h" | ||
36 | |||
37 | 32 | static int sse4_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
38 | ptrdiff_t stride, int h) | ||
39 | { | ||
40 | 32 | int s = 0, i; | |
41 | 32 | const uint32_t *sq = ff_square_tab + 256; | |
42 | |||
43 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 32 times.
|
352 | for (i = 0; i < h; i++) { |
44 | 320 | s += sq[pix1[0] - pix2[0]]; | |
45 | 320 | s += sq[pix1[1] - pix2[1]]; | |
46 | 320 | s += sq[pix1[2] - pix2[2]]; | |
47 | 320 | s += sq[pix1[3] - pix2[3]]; | |
48 | 320 | pix1 += stride; | |
49 | 320 | pix2 += stride; | |
50 | } | ||
51 | 32 | return s; | |
52 | } | ||
53 | |||
54 | 5329472 | static int sse8_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
55 | ptrdiff_t stride, int h) | ||
56 | { | ||
57 | 5329472 | int s = 0, i; | |
58 | 5329472 | const uint32_t *sq = ff_square_tab + 256; | |
59 | |||
60 |
2/2✓ Branch 0 taken 48777234 times.
✓ Branch 1 taken 5329472 times.
|
54106706 | for (i = 0; i < h; i++) { |
61 | 48777234 | s += sq[pix1[0] - pix2[0]]; | |
62 | 48777234 | s += sq[pix1[1] - pix2[1]]; | |
63 | 48777234 | s += sq[pix1[2] - pix2[2]]; | |
64 | 48777234 | s += sq[pix1[3] - pix2[3]]; | |
65 | 48777234 | s += sq[pix1[4] - pix2[4]]; | |
66 | 48777234 | s += sq[pix1[5] - pix2[5]]; | |
67 | 48777234 | s += sq[pix1[6] - pix2[6]]; | |
68 | 48777234 | s += sq[pix1[7] - pix2[7]]; | |
69 | 48777234 | pix1 += stride; | |
70 | 48777234 | pix2 += stride; | |
71 | } | ||
72 | 5329472 | return s; | |
73 | } | ||
74 | |||
75 | 7197448 | static int sse16_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
76 | ptrdiff_t stride, int h) | ||
77 | { | ||
78 | 7197448 | int s = 0, i; | |
79 | 7197448 | const uint32_t *sq = ff_square_tab + 256; | |
80 | |||
81 |
2/2✓ Branch 0 taken 115158852 times.
✓ Branch 1 taken 7197448 times.
|
122356300 | for (i = 0; i < h; i++) { |
82 | 115158852 | s += sq[pix1[0] - pix2[0]]; | |
83 | 115158852 | s += sq[pix1[1] - pix2[1]]; | |
84 | 115158852 | s += sq[pix1[2] - pix2[2]]; | |
85 | 115158852 | s += sq[pix1[3] - pix2[3]]; | |
86 | 115158852 | s += sq[pix1[4] - pix2[4]]; | |
87 | 115158852 | s += sq[pix1[5] - pix2[5]]; | |
88 | 115158852 | s += sq[pix1[6] - pix2[6]]; | |
89 | 115158852 | s += sq[pix1[7] - pix2[7]]; | |
90 | 115158852 | s += sq[pix1[8] - pix2[8]]; | |
91 | 115158852 | s += sq[pix1[9] - pix2[9]]; | |
92 | 115158852 | s += sq[pix1[10] - pix2[10]]; | |
93 | 115158852 | s += sq[pix1[11] - pix2[11]]; | |
94 | 115158852 | s += sq[pix1[12] - pix2[12]]; | |
95 | 115158852 | s += sq[pix1[13] - pix2[13]]; | |
96 | 115158852 | s += sq[pix1[14] - pix2[14]]; | |
97 | 115158852 | s += sq[pix1[15] - pix2[15]]; | |
98 | |||
99 | 115158852 | pix1 += stride; | |
100 | 115158852 | pix2 += stride; | |
101 | } | ||
102 | 7197448 | return s; | |
103 | } | ||
104 | |||
105 | ✗ | static int sum_abs_dctelem_c(const int16_t *block) | |
106 | { | ||
107 | ✗ | int sum = 0, i; | |
108 | |||
109 | ✗ | for (i = 0; i < 64; i++) | |
110 | ✗ | sum += FFABS(block[i]); | |
111 | ✗ | return sum; | |
112 | } | ||
113 | |||
114 | #define avg2(a, b) (((a) + (b) + 1) >> 1) | ||
115 | #define avg4(a, b, c, d) (((a) + (b) + (c) + (d) + 2) >> 2) | ||
116 | |||
117 | 44304537 | static inline int pix_abs16_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
118 | ptrdiff_t stride, int h) | ||
119 | { | ||
120 | 44304537 | int s = 0, i; | |
121 | |||
122 |
2/2✓ Branch 0 taken 628503512 times.
✓ Branch 1 taken 44304537 times.
|
672808049 | for (i = 0; i < h; i++) { |
123 | 628503512 | s += abs(pix1[0] - pix2[0]); | |
124 | 628503512 | s += abs(pix1[1] - pix2[1]); | |
125 | 628503512 | s += abs(pix1[2] - pix2[2]); | |
126 | 628503512 | s += abs(pix1[3] - pix2[3]); | |
127 | 628503512 | s += abs(pix1[4] - pix2[4]); | |
128 | 628503512 | s += abs(pix1[5] - pix2[5]); | |
129 | 628503512 | s += abs(pix1[6] - pix2[6]); | |
130 | 628503512 | s += abs(pix1[7] - pix2[7]); | |
131 | 628503512 | s += abs(pix1[8] - pix2[8]); | |
132 | 628503512 | s += abs(pix1[9] - pix2[9]); | |
133 | 628503512 | s += abs(pix1[10] - pix2[10]); | |
134 | 628503512 | s += abs(pix1[11] - pix2[11]); | |
135 | 628503512 | s += abs(pix1[12] - pix2[12]); | |
136 | 628503512 | s += abs(pix1[13] - pix2[13]); | |
137 | 628503512 | s += abs(pix1[14] - pix2[14]); | |
138 | 628503512 | s += abs(pix1[15] - pix2[15]); | |
139 | 628503512 | pix1 += stride; | |
140 | 628503512 | pix2 += stride; | |
141 | } | ||
142 | 44304537 | return s; | |
143 | } | ||
144 | |||
145 | 32 | static inline int pix_median_abs16_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
146 | ptrdiff_t stride, int h) | ||
147 | { | ||
148 | 32 | int s = 0, i, j; | |
149 | |||
150 | #define V(x) (pix1[x] - pix2[x]) | ||
151 | |||
152 | 32 | s += abs(V(0)); | |
153 | 32 | s += abs(V(1) - V(0)); | |
154 | 32 | s += abs(V(2) - V(1)); | |
155 | 32 | s += abs(V(3) - V(2)); | |
156 | 32 | s += abs(V(4) - V(3)); | |
157 | 32 | s += abs(V(5) - V(4)); | |
158 | 32 | s += abs(V(6) - V(5)); | |
159 | 32 | s += abs(V(7) - V(6)); | |
160 | 32 | s += abs(V(8) - V(7)); | |
161 | 32 | s += abs(V(9) - V(8)); | |
162 | 32 | s += abs(V(10) - V(9)); | |
163 | 32 | s += abs(V(11) - V(10)); | |
164 | 32 | s += abs(V(12) - V(11)); | |
165 | 32 | s += abs(V(13) - V(12)); | |
166 | 32 | s += abs(V(14) - V(13)); | |
167 | 32 | s += abs(V(15) - V(14)); | |
168 | |||
169 | 32 | pix1 += stride; | |
170 | 32 | pix2 += stride; | |
171 | |||
172 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 32 times.
|
352 | for (i = 1; i < h; i++) { |
173 | 320 | s += abs(V(0) - V(-stride)); | |
174 |
2/2✓ Branch 0 taken 4800 times.
✓ Branch 1 taken 320 times.
|
5120 | for (j = 1; j < 16; j++) |
175 | 4800 | s += abs(V(j) - mid_pred(V(j-stride), V(j-1), V(j-stride) + V(j-1) - V(j-stride-1))); | |
176 | 320 | pix1 += stride; | |
177 | 320 | pix2 += stride; | |
178 | |||
179 | } | ||
180 | #undef V | ||
181 | 32 | return s; | |
182 | } | ||
183 | |||
184 | 3304472 | static int pix_abs16_x2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
185 | ptrdiff_t stride, int h) | ||
186 | { | ||
187 | 3304472 | int s = 0, i; | |
188 | |||
189 |
2/2✓ Branch 0 taken 43561700 times.
✓ Branch 1 taken 3304472 times.
|
46866172 | for (i = 0; i < h; i++) { |
190 | 43561700 | s += abs(pix1[0] - avg2(pix2[0], pix2[1])); | |
191 | 43561700 | s += abs(pix1[1] - avg2(pix2[1], pix2[2])); | |
192 | 43561700 | s += abs(pix1[2] - avg2(pix2[2], pix2[3])); | |
193 | 43561700 | s += abs(pix1[3] - avg2(pix2[3], pix2[4])); | |
194 | 43561700 | s += abs(pix1[4] - avg2(pix2[4], pix2[5])); | |
195 | 43561700 | s += abs(pix1[5] - avg2(pix2[5], pix2[6])); | |
196 | 43561700 | s += abs(pix1[6] - avg2(pix2[6], pix2[7])); | |
197 | 43561700 | s += abs(pix1[7] - avg2(pix2[7], pix2[8])); | |
198 | 43561700 | s += abs(pix1[8] - avg2(pix2[8], pix2[9])); | |
199 | 43561700 | s += abs(pix1[9] - avg2(pix2[9], pix2[10])); | |
200 | 43561700 | s += abs(pix1[10] - avg2(pix2[10], pix2[11])); | |
201 | 43561700 | s += abs(pix1[11] - avg2(pix2[11], pix2[12])); | |
202 | 43561700 | s += abs(pix1[12] - avg2(pix2[12], pix2[13])); | |
203 | 43561700 | s += abs(pix1[13] - avg2(pix2[13], pix2[14])); | |
204 | 43561700 | s += abs(pix1[14] - avg2(pix2[14], pix2[15])); | |
205 | 43561700 | s += abs(pix1[15] - avg2(pix2[15], pix2[16])); | |
206 | 43561700 | pix1 += stride; | |
207 | 43561700 | pix2 += stride; | |
208 | } | ||
209 | 3304472 | return s; | |
210 | } | ||
211 | |||
212 | 3304472 | static int pix_abs16_y2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
213 | ptrdiff_t stride, int h) | ||
214 | { | ||
215 | 3304472 | int s = 0, i; | |
216 | 3304472 | const uint8_t *pix3 = pix2 + stride; | |
217 | |||
218 |
2/2✓ Branch 0 taken 43561660 times.
✓ Branch 1 taken 3304472 times.
|
46866132 | for (i = 0; i < h; i++) { |
219 | 43561660 | s += abs(pix1[0] - avg2(pix2[0], pix3[0])); | |
220 | 43561660 | s += abs(pix1[1] - avg2(pix2[1], pix3[1])); | |
221 | 43561660 | s += abs(pix1[2] - avg2(pix2[2], pix3[2])); | |
222 | 43561660 | s += abs(pix1[3] - avg2(pix2[3], pix3[3])); | |
223 | 43561660 | s += abs(pix1[4] - avg2(pix2[4], pix3[4])); | |
224 | 43561660 | s += abs(pix1[5] - avg2(pix2[5], pix3[5])); | |
225 | 43561660 | s += abs(pix1[6] - avg2(pix2[6], pix3[6])); | |
226 | 43561660 | s += abs(pix1[7] - avg2(pix2[7], pix3[7])); | |
227 | 43561660 | s += abs(pix1[8] - avg2(pix2[8], pix3[8])); | |
228 | 43561660 | s += abs(pix1[9] - avg2(pix2[9], pix3[9])); | |
229 | 43561660 | s += abs(pix1[10] - avg2(pix2[10], pix3[10])); | |
230 | 43561660 | s += abs(pix1[11] - avg2(pix2[11], pix3[11])); | |
231 | 43561660 | s += abs(pix1[12] - avg2(pix2[12], pix3[12])); | |
232 | 43561660 | s += abs(pix1[13] - avg2(pix2[13], pix3[13])); | |
233 | 43561660 | s += abs(pix1[14] - avg2(pix2[14], pix3[14])); | |
234 | 43561660 | s += abs(pix1[15] - avg2(pix2[15], pix3[15])); | |
235 | 43561660 | pix1 += stride; | |
236 | 43561660 | pix2 += stride; | |
237 | 43561660 | pix3 += stride; | |
238 | } | ||
239 | 3304472 | return s; | |
240 | } | ||
241 | |||
242 | 6608896 | static int pix_abs16_xy2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
243 | ptrdiff_t stride, int h) | ||
244 | { | ||
245 | 6608896 | int s = 0, i; | |
246 | 6608896 | const uint8_t *pix3 = pix2 + stride; | |
247 | |||
248 |
2/2✓ Branch 0 taken 87122936 times.
✓ Branch 1 taken 6608896 times.
|
93731832 | for (i = 0; i < h; i++) { |
249 | 87122936 | s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1])); | |
250 | 87122936 | s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2])); | |
251 | 87122936 | s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3])); | |
252 | 87122936 | s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4])); | |
253 | 87122936 | s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5])); | |
254 | 87122936 | s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6])); | |
255 | 87122936 | s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7])); | |
256 | 87122936 | s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8])); | |
257 | 87122936 | s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9])); | |
258 | 87122936 | s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10])); | |
259 | 87122936 | s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11])); | |
260 | 87122936 | s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12])); | |
261 | 87122936 | s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13])); | |
262 | 87122936 | s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14])); | |
263 | 87122936 | s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15])); | |
264 | 87122936 | s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16])); | |
265 | 87122936 | pix1 += stride; | |
266 | 87122936 | pix2 += stride; | |
267 | 87122936 | pix3 += stride; | |
268 | } | ||
269 | 6608896 | return s; | |
270 | } | ||
271 | |||
272 | 33810668 | static inline int pix_abs8_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
273 | ptrdiff_t stride, int h) | ||
274 | { | ||
275 | 33810668 | int s = 0, i; | |
276 | |||
277 |
2/2✓ Branch 0 taken 270485498 times.
✓ Branch 1 taken 33810668 times.
|
304296166 | for (i = 0; i < h; i++) { |
278 | 270485498 | s += abs(pix1[0] - pix2[0]); | |
279 | 270485498 | s += abs(pix1[1] - pix2[1]); | |
280 | 270485498 | s += abs(pix1[2] - pix2[2]); | |
281 | 270485498 | s += abs(pix1[3] - pix2[3]); | |
282 | 270485498 | s += abs(pix1[4] - pix2[4]); | |
283 | 270485498 | s += abs(pix1[5] - pix2[5]); | |
284 | 270485498 | s += abs(pix1[6] - pix2[6]); | |
285 | 270485498 | s += abs(pix1[7] - pix2[7]); | |
286 | 270485498 | pix1 += stride; | |
287 | 270485498 | pix2 += stride; | |
288 | } | ||
289 | 33810668 | return s; | |
290 | } | ||
291 | |||
292 | 32 | static inline int pix_median_abs8_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
293 | ptrdiff_t stride, int h) | ||
294 | { | ||
295 | 32 | int s = 0, i, j; | |
296 | |||
297 | #define V(x) (pix1[x] - pix2[x]) | ||
298 | |||
299 | 32 | s += abs(V(0)); | |
300 | 32 | s += abs(V(1) - V(0)); | |
301 | 32 | s += abs(V(2) - V(1)); | |
302 | 32 | s += abs(V(3) - V(2)); | |
303 | 32 | s += abs(V(4) - V(3)); | |
304 | 32 | s += abs(V(5) - V(4)); | |
305 | 32 | s += abs(V(6) - V(5)); | |
306 | 32 | s += abs(V(7) - V(6)); | |
307 | |||
308 | 32 | pix1 += stride; | |
309 | 32 | pix2 += stride; | |
310 | |||
311 |
2/2✓ Branch 0 taken 264 times.
✓ Branch 1 taken 32 times.
|
296 | for (i = 1; i < h; i++) { |
312 | 264 | s += abs(V(0) - V(-stride)); | |
313 |
2/2✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 264 times.
|
2112 | for (j = 1; j < 8; j++) |
314 | 1848 | s += abs(V(j) - mid_pred(V(j-stride), V(j-1), V(j-stride) + V(j-1) - V(j-stride-1))); | |
315 | 264 | pix1 += stride; | |
316 | 264 | pix2 += stride; | |
317 | |||
318 | } | ||
319 | #undef V | ||
320 | 32 | return s; | |
321 | } | ||
322 | |||
323 | 837597 | static int pix_abs8_x2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
324 | ptrdiff_t stride, int h) | ||
325 | { | ||
326 | 837597 | int s = 0, i; | |
327 | |||
328 |
2/2✓ Branch 0 taken 6700868 times.
✓ Branch 1 taken 837597 times.
|
7538465 | for (i = 0; i < h; i++) { |
329 | 6700868 | s += abs(pix1[0] - avg2(pix2[0], pix2[1])); | |
330 | 6700868 | s += abs(pix1[1] - avg2(pix2[1], pix2[2])); | |
331 | 6700868 | s += abs(pix1[2] - avg2(pix2[2], pix2[3])); | |
332 | 6700868 | s += abs(pix1[3] - avg2(pix2[3], pix2[4])); | |
333 | 6700868 | s += abs(pix1[4] - avg2(pix2[4], pix2[5])); | |
334 | 6700868 | s += abs(pix1[5] - avg2(pix2[5], pix2[6])); | |
335 | 6700868 | s += abs(pix1[6] - avg2(pix2[6], pix2[7])); | |
336 | 6700868 | s += abs(pix1[7] - avg2(pix2[7], pix2[8])); | |
337 | 6700868 | pix1 += stride; | |
338 | 6700868 | pix2 += stride; | |
339 | } | ||
340 | 837597 | return s; | |
341 | } | ||
342 | |||
343 | 837597 | static int pix_abs8_y2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
344 | ptrdiff_t stride, int h) | ||
345 | { | ||
346 | 837597 | int s = 0, i; | |
347 | 837597 | const uint8_t *pix3 = pix2 + stride; | |
348 | |||
349 |
2/2✓ Branch 0 taken 6700868 times.
✓ Branch 1 taken 837597 times.
|
7538465 | for (i = 0; i < h; i++) { |
350 | 6700868 | s += abs(pix1[0] - avg2(pix2[0], pix3[0])); | |
351 | 6700868 | s += abs(pix1[1] - avg2(pix2[1], pix3[1])); | |
352 | 6700868 | s += abs(pix1[2] - avg2(pix2[2], pix3[2])); | |
353 | 6700868 | s += abs(pix1[3] - avg2(pix2[3], pix3[3])); | |
354 | 6700868 | s += abs(pix1[4] - avg2(pix2[4], pix3[4])); | |
355 | 6700868 | s += abs(pix1[5] - avg2(pix2[5], pix3[5])); | |
356 | 6700868 | s += abs(pix1[6] - avg2(pix2[6], pix3[6])); | |
357 | 6700868 | s += abs(pix1[7] - avg2(pix2[7], pix3[7])); | |
358 | 6700868 | pix1 += stride; | |
359 | 6700868 | pix2 += stride; | |
360 | 6700868 | pix3 += stride; | |
361 | } | ||
362 | 837597 | return s; | |
363 | } | ||
364 | |||
365 | 1675146 | static int pix_abs8_xy2_c(MPVEncContext *unused, const uint8_t *pix1, const uint8_t *pix2, | |
366 | ptrdiff_t stride, int h) | ||
367 | { | ||
368 | 1675146 | int s = 0, i; | |
369 | 1675146 | const uint8_t *pix3 = pix2 + stride; | |
370 | |||
371 |
2/2✓ Branch 0 taken 13401214 times.
✓ Branch 1 taken 1675146 times.
|
15076360 | for (i = 0; i < h; i++) { |
372 | 13401214 | s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1])); | |
373 | 13401214 | s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2])); | |
374 | 13401214 | s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3])); | |
375 | 13401214 | s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4])); | |
376 | 13401214 | s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5])); | |
377 | 13401214 | s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6])); | |
378 | 13401214 | s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7])); | |
379 | 13401214 | s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8])); | |
380 | 13401214 | pix1 += stride; | |
381 | 13401214 | pix2 += stride; | |
382 | 13401214 | pix3 += stride; | |
383 | } | ||
384 | 1675146 | return s; | |
385 | } | ||
386 | |||
387 | 748189 | static int nsse16_c(MPVEncContext *const c, const uint8_t *s1, const uint8_t *s2, | |
388 | ptrdiff_t stride, int h) | ||
389 | { | ||
390 | 748189 | int score1 = 0, score2 = 0, x, y; | |
391 | |||
392 |
2/2✓ Branch 0 taken 11970696 times.
✓ Branch 1 taken 748189 times.
|
12718885 | for (y = 0; y < h; y++) { |
393 |
2/2✓ Branch 0 taken 191531136 times.
✓ Branch 1 taken 11970696 times.
|
203501832 | for (x = 0; x < 16; x++) |
394 | 191531136 | score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]); | |
395 |
2/2✓ Branch 0 taken 11222507 times.
✓ Branch 1 taken 748189 times.
|
11970696 | if (y + 1 < h) { |
396 |
2/2✓ Branch 0 taken 168337605 times.
✓ Branch 1 taken 11222507 times.
|
179560112 | for (x = 0; x < 15; x++) |
397 | 168337605 | score2 += FFABS(s1[x] - s1[x + stride] - | |
398 | 168337605 | s1[x + 1] + s1[x + stride + 1]) - | |
399 | 168337605 | FFABS(s2[x] - s2[x + stride] - | |
400 | s2[x + 1] + s2[x + stride + 1]); | ||
401 | } | ||
402 | 11970696 | s1 += stride; | |
403 | 11970696 | s2 += stride; | |
404 | } | ||
405 | |||
406 |
2/2✓ Branch 0 taken 748141 times.
✓ Branch 1 taken 48 times.
|
748189 | if (c) |
407 | 748141 | return score1 + FFABS(score2) * c->c.avctx->nsse_weight; | |
408 | else | ||
409 | 48 | return score1 + FFABS(score2) * 8; | |
410 | } | ||
411 | |||
412 | 48 | static int nsse8_c(MPVEncContext *const c, const uint8_t *s1, const uint8_t *s2, | |
413 | ptrdiff_t stride, int h) | ||
414 | { | ||
415 | 48 | int score1 = 0, score2 = 0, x, y; | |
416 | |||
417 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 48 times.
|
496 | for (y = 0; y < h; y++) { |
418 |
2/2✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 448 times.
|
4032 | for (x = 0; x < 8; x++) |
419 | 3584 | score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]); | |
420 |
2/2✓ Branch 0 taken 400 times.
✓ Branch 1 taken 48 times.
|
448 | if (y + 1 < h) { |
421 |
2/2✓ Branch 0 taken 2800 times.
✓ Branch 1 taken 400 times.
|
3200 | for (x = 0; x < 7; x++) |
422 | 2800 | score2 += FFABS(s1[x] - s1[x + stride] - | |
423 | 2800 | s1[x + 1] + s1[x + stride + 1]) - | |
424 | 2800 | FFABS(s2[x] - s2[x + stride] - | |
425 | s2[x + 1] + s2[x + stride + 1]); | ||
426 | } | ||
427 | 448 | s1 += stride; | |
428 | 448 | s2 += stride; | |
429 | } | ||
430 | |||
431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (c) |
432 | ✗ | return score1 + FFABS(score2) * c->c.avctx->nsse_weight; | |
433 | else | ||
434 | 48 | return score1 + FFABS(score2) * 8; | |
435 | } | ||
436 | |||
437 | ✗ | static int zero_cmp(MPVEncContext *s, const uint8_t *a, const uint8_t *b, | |
438 | ptrdiff_t stride, int h) | ||
439 | { | ||
440 | ✗ | return 0; | |
441 | } | ||
442 | |||
443 | 1097 | av_cold int ff_set_cmp(const MECmpContext *c, me_cmp_func *cmp, int type, int mpvenc) | |
444 | { | ||
445 | #define ENTRY(CMP_FLAG, ARRAY, MPVENC_ONLY) \ | ||
446 | [FF_CMP_ ## CMP_FLAG] = { \ | ||
447 | .offset = offsetof(MECmpContext, ARRAY), \ | ||
448 | .mpv_only = MPVENC_ONLY, \ | ||
449 | .available = 1, \ | ||
450 | } | ||
451 | static const struct { | ||
452 | char available; | ||
453 | char mpv_only; | ||
454 | uint16_t offset; | ||
455 | } cmp_func_list[] = { | ||
456 | ENTRY(SAD, sad, 0), | ||
457 | ENTRY(SSE, sse, 0), | ||
458 | ENTRY(SATD, hadamard8_diff, 0), | ||
459 | ENTRY(DCT, dct_sad, 1), | ||
460 | ENTRY(PSNR, quant_psnr, 1), | ||
461 | ENTRY(BIT, bit, 1), | ||
462 | ENTRY(RD, rd, 1), | ||
463 | ENTRY(VSAD, vsad, 0), | ||
464 | ENTRY(VSSE, vsse, 0), | ||
465 | ENTRY(NSSE, nsse, 0), | ||
466 | #if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER | ||
467 | ENTRY(W53, w53, 0), | ||
468 | ENTRY(W97, w97, 0), | ||
469 | #endif | ||
470 | ENTRY(DCTMAX, dct_max, 1), | ||
471 | #if CONFIG_GPL | ||
472 | ENTRY(DCT264, dct264_sad, 1), | ||
473 | #endif | ||
474 | ENTRY(MEDIAN_SAD, median_sad, 0), | ||
475 | }; | ||
476 | const me_cmp_func *me_cmp_func_array; | ||
477 | |||
478 | 1097 | type &= 0xFF; | |
479 | |||
480 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1097 times.
|
1097 | if (type == FF_CMP_ZERO) { |
481 | ✗ | for (int i = 0; i < 6; i++) | |
482 | ✗ | cmp[i] = zero_cmp; | |
483 | ✗ | return 0; | |
484 | } | ||
485 |
1/2✓ Branch 0 taken 1097 times.
✗ Branch 1 not taken.
|
1097 | if (type >= FF_ARRAY_ELEMS(cmp_func_list) || |
486 |
3/4✓ Branch 0 taken 1097 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 1037 times.
|
1097 | !cmp_func_list[type].available || |
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | !mpvenc && cmp_func_list[type].mpv_only) { |
488 | ✗ | av_log(NULL, AV_LOG_ERROR, | |
489 | "invalid cmp function selection\n"); | ||
490 | ✗ | return AVERROR(EINVAL); | |
491 | } | ||
492 | 1097 | me_cmp_func_array = (const me_cmp_func*)(((const char*)c) + cmp_func_list[type].offset); | |
493 |
2/2✓ Branch 0 taken 6582 times.
✓ Branch 1 taken 1097 times.
|
7679 | for (int i = 0; i < 6; i++) |
494 | 6582 | cmp[i] = me_cmp_func_array[i]; | |
495 | |||
496 | 1097 | return 0; | |
497 | } | ||
498 | |||
499 | #define BUTTERFLY2(o1, o2, i1, i2) \ | ||
500 | o1 = (i1) + (i2); \ | ||
501 | o2 = (i1) - (i2); | ||
502 | |||
503 | #define BUTTERFLY1(x, y) \ | ||
504 | { \ | ||
505 | int a, b; \ | ||
506 | a = x; \ | ||
507 | b = y; \ | ||
508 | x = a + b; \ | ||
509 | y = a - b; \ | ||
510 | } | ||
511 | |||
512 | #define BUTTERFLYA(x, y) (FFABS((x) + (y)) + FFABS((x) - (y))) | ||
513 | |||
514 | 15264262 | static int hadamard8_diff8x8_c(MPVEncContext *unused, const uint8_t *dst, | |
515 | const uint8_t *src, ptrdiff_t stride, int h) | ||
516 | { | ||
517 | 15264262 | int i, temp[64], sum = 0; | |
518 | |||
519 |
2/2✓ Branch 0 taken 122114096 times.
✓ Branch 1 taken 15264262 times.
|
137378358 | for (i = 0; i < 8; i++) { |
520 | // FIXME: try pointer walks | ||
521 | 122114096 | BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1], | |
522 | src[stride * i + 0] - dst[stride * i + 0], | ||
523 | src[stride * i + 1] - dst[stride * i + 1]); | ||
524 | 122114096 | BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3], | |
525 | src[stride * i + 2] - dst[stride * i + 2], | ||
526 | src[stride * i + 3] - dst[stride * i + 3]); | ||
527 | 122114096 | BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5], | |
528 | src[stride * i + 4] - dst[stride * i + 4], | ||
529 | src[stride * i + 5] - dst[stride * i + 5]); | ||
530 | 122114096 | BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7], | |
531 | src[stride * i + 6] - dst[stride * i + 6], | ||
532 | src[stride * i + 7] - dst[stride * i + 7]); | ||
533 | |||
534 | 122114096 | BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]); | |
535 | 122114096 | BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]); | |
536 | 122114096 | BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]); | |
537 | 122114096 | BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]); | |
538 | |||
539 | 122114096 | BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]); | |
540 | 122114096 | BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]); | |
541 | 122114096 | BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]); | |
542 | 122114096 | BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]); | |
543 | } | ||
544 | |||
545 |
2/2✓ Branch 0 taken 122114096 times.
✓ Branch 1 taken 15264262 times.
|
137378358 | for (i = 0; i < 8; i++) { |
546 | 122114096 | BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]); | |
547 | 122114096 | BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]); | |
548 | 122114096 | BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]); | |
549 | 122114096 | BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]); | |
550 | |||
551 | 122114096 | BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]); | |
552 | 122114096 | BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]); | |
553 | 122114096 | BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]); | |
554 | 122114096 | BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]); | |
555 | |||
556 | 122114096 | sum += BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) + | |
557 | 122114096 | BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) + | |
558 | 122114096 | BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) + | |
559 | 122114096 | BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]); | |
560 | } | ||
561 | 15264262 | return sum; | |
562 | } | ||
563 | |||
564 | 104 | static int hadamard8_intra8x8_c(MPVEncContext *unused, const uint8_t *src, | |
565 | const uint8_t *dummy, ptrdiff_t stride, int h) | ||
566 | { | ||
567 | 104 | int i, temp[64], sum = 0; | |
568 | |||
569 |
2/2✓ Branch 0 taken 832 times.
✓ Branch 1 taken 104 times.
|
936 | for (i = 0; i < 8; i++) { |
570 | // FIXME: try pointer walks | ||
571 | 832 | BUTTERFLY2(temp[8 * i + 0], temp[8 * i + 1], | |
572 | src[stride * i + 0], src[stride * i + 1]); | ||
573 | 832 | BUTTERFLY2(temp[8 * i + 2], temp[8 * i + 3], | |
574 | src[stride * i + 2], src[stride * i + 3]); | ||
575 | 832 | BUTTERFLY2(temp[8 * i + 4], temp[8 * i + 5], | |
576 | src[stride * i + 4], src[stride * i + 5]); | ||
577 | 832 | BUTTERFLY2(temp[8 * i + 6], temp[8 * i + 7], | |
578 | src[stride * i + 6], src[stride * i + 7]); | ||
579 | |||
580 | 832 | BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 2]); | |
581 | 832 | BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 3]); | |
582 | 832 | BUTTERFLY1(temp[8 * i + 4], temp[8 * i + 6]); | |
583 | 832 | BUTTERFLY1(temp[8 * i + 5], temp[8 * i + 7]); | |
584 | |||
585 | 832 | BUTTERFLY1(temp[8 * i + 0], temp[8 * i + 4]); | |
586 | 832 | BUTTERFLY1(temp[8 * i + 1], temp[8 * i + 5]); | |
587 | 832 | BUTTERFLY1(temp[8 * i + 2], temp[8 * i + 6]); | |
588 | 832 | BUTTERFLY1(temp[8 * i + 3], temp[8 * i + 7]); | |
589 | } | ||
590 | |||
591 |
2/2✓ Branch 0 taken 832 times.
✓ Branch 1 taken 104 times.
|
936 | for (i = 0; i < 8; i++) { |
592 | 832 | BUTTERFLY1(temp[8 * 0 + i], temp[8 * 1 + i]); | |
593 | 832 | BUTTERFLY1(temp[8 * 2 + i], temp[8 * 3 + i]); | |
594 | 832 | BUTTERFLY1(temp[8 * 4 + i], temp[8 * 5 + i]); | |
595 | 832 | BUTTERFLY1(temp[8 * 6 + i], temp[8 * 7 + i]); | |
596 | |||
597 | 832 | BUTTERFLY1(temp[8 * 0 + i], temp[8 * 2 + i]); | |
598 | 832 | BUTTERFLY1(temp[8 * 1 + i], temp[8 * 3 + i]); | |
599 | 832 | BUTTERFLY1(temp[8 * 4 + i], temp[8 * 6 + i]); | |
600 | 832 | BUTTERFLY1(temp[8 * 5 + i], temp[8 * 7 + i]); | |
601 | |||
602 | 832 | sum += | |
603 | 832 | BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) | |
604 | 832 | + BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) | |
605 | 832 | + BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) | |
606 | 832 | + BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]); | |
607 | } | ||
608 | |||
609 | 104 | sum -= FFABS(temp[8 * 0] + temp[8 * 4]); // -mean | |
610 | |||
611 | 104 | return sum; | |
612 | } | ||
613 | |||
614 | ✗ | static int dct_sad8x8_c(MPVEncContext *const s, const uint8_t *src1, | |
615 | const uint8_t *src2, ptrdiff_t stride, int h) | ||
616 | { | ||
617 | ✗ | LOCAL_ALIGNED_16(int16_t, temp, [64]); | |
618 | |||
619 | ✗ | s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride); | |
620 | ✗ | s->fdsp.fdct(temp); | |
621 | ✗ | return s->sum_abs_dctelem(temp); | |
622 | } | ||
623 | |||
624 | #if CONFIG_GPL | ||
625 | #define DCT8_1D \ | ||
626 | { \ | ||
627 | const int s07 = SRC(0) + SRC(7); \ | ||
628 | const int s16 = SRC(1) + SRC(6); \ | ||
629 | const int s25 = SRC(2) + SRC(5); \ | ||
630 | const int s34 = SRC(3) + SRC(4); \ | ||
631 | const int a0 = s07 + s34; \ | ||
632 | const int a1 = s16 + s25; \ | ||
633 | const int a2 = s07 - s34; \ | ||
634 | const int a3 = s16 - s25; \ | ||
635 | const int d07 = SRC(0) - SRC(7); \ | ||
636 | const int d16 = SRC(1) - SRC(6); \ | ||
637 | const int d25 = SRC(2) - SRC(5); \ | ||
638 | const int d34 = SRC(3) - SRC(4); \ | ||
639 | const int a4 = d16 + d25 + (d07 + (d07 >> 1)); \ | ||
640 | const int a5 = d07 - d34 - (d25 + (d25 >> 1)); \ | ||
641 | const int a6 = d07 + d34 - (d16 + (d16 >> 1)); \ | ||
642 | const int a7 = d16 - d25 + (d34 + (d34 >> 1)); \ | ||
643 | DST(0, a0 + a1); \ | ||
644 | DST(1, a4 + (a7 >> 2)); \ | ||
645 | DST(2, a2 + (a3 >> 1)); \ | ||
646 | DST(3, a5 + (a6 >> 2)); \ | ||
647 | DST(4, a0 - a1); \ | ||
648 | DST(5, a6 - (a5 >> 2)); \ | ||
649 | DST(6, (a2 >> 1) - a3); \ | ||
650 | DST(7, (a4 >> 2) - a7); \ | ||
651 | } | ||
652 | |||
653 | ✗ | static int dct264_sad8x8_c(MPVEncContext *const s, const uint8_t *src1, | |
654 | const uint8_t *src2, ptrdiff_t stride, int h) | ||
655 | { | ||
656 | int16_t dct[8][8]; | ||
657 | ✗ | int i, sum = 0; | |
658 | |||
659 | ✗ | s->pdsp.diff_pixels_unaligned(dct[0], src1, src2, stride); | |
660 | |||
661 | #define SRC(x) dct[i][x] | ||
662 | #define DST(x, v) dct[i][x] = v | ||
663 | ✗ | for (i = 0; i < 8; i++) | |
664 | ✗ | DCT8_1D | |
665 | #undef SRC | ||
666 | #undef DST | ||
667 | |||
668 | #define SRC(x) dct[x][i] | ||
669 | #define DST(x, v) sum += FFABS(v) | ||
670 | ✗ | for (i = 0; i < 8; i++) | |
671 | ✗ | DCT8_1D | |
672 | #undef SRC | ||
673 | #undef DST | ||
674 | ✗ | return sum; | |
675 | } | ||
676 | #endif | ||
677 | |||
678 | ✗ | static int dct_max8x8_c(MPVEncContext *const s, const uint8_t *src1, | |
679 | const uint8_t *src2, ptrdiff_t stride, int h) | ||
680 | { | ||
681 | ✗ | LOCAL_ALIGNED_16(int16_t, temp, [64]); | |
682 | ✗ | int sum = 0, i; | |
683 | |||
684 | ✗ | s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride); | |
685 | ✗ | s->fdsp.fdct(temp); | |
686 | |||
687 | ✗ | for (i = 0; i < 64; i++) | |
688 | ✗ | sum = FFMAX(sum, FFABS(temp[i])); | |
689 | |||
690 | ✗ | return sum; | |
691 | } | ||
692 | |||
693 | ✗ | static int quant_psnr8x8_c(MPVEncContext *const s, const uint8_t *src1, | |
694 | const uint8_t *src2, ptrdiff_t stride, int h) | ||
695 | { | ||
696 | ✗ | LOCAL_ALIGNED_16(int16_t, temp, [64 * 2]); | |
697 | ✗ | int16_t *const bak = temp + 64; | |
698 | ✗ | int sum = 0, i; | |
699 | |||
700 | ✗ | s->c.mb_intra = 0; | |
701 | |||
702 | ✗ | s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride); | |
703 | |||
704 | ✗ | memcpy(bak, temp, 64 * sizeof(int16_t)); | |
705 | |||
706 | ✗ | s->c.block_last_index[0 /* FIXME */] = | |
707 | ✗ | s->dct_quantize(s, temp, 0 /* FIXME */, s->c.qscale, &i); | |
708 | ✗ | s->c.dct_unquantize_inter(&s->c, temp, 0, s->c.qscale); | |
709 | ✗ | ff_simple_idct_int16_8bit(temp); // FIXME | |
710 | |||
711 | ✗ | for (i = 0; i < 64; i++) | |
712 | ✗ | sum += (temp[i] - bak[i]) * (temp[i] - bak[i]); | |
713 | |||
714 | ✗ | return sum; | |
715 | } | ||
716 | |||
717 | ✗ | static int rd8x8_c(MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, | |
718 | ptrdiff_t stride, int h) | ||
719 | { | ||
720 | ✗ | const uint8_t *scantable = s->c.intra_scantable.permutated; | |
721 | ✗ | LOCAL_ALIGNED_16(int16_t, temp, [64]); | |
722 | ✗ | LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]); | |
723 | ✗ | LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]); | |
724 | int i, last, run, bits, level, distortion, start_i; | ||
725 | ✗ | const int esc_length = s->ac_esc_length; | |
726 | const uint8_t *length, *last_length; | ||
727 | |||
728 | ✗ | copy_block8(lsrc1, src1, 8, stride, 8); | |
729 | ✗ | copy_block8(lsrc2, src2, 8, stride, 8); | |
730 | |||
731 | ✗ | s->pdsp.diff_pixels(temp, lsrc1, lsrc2, 8); | |
732 | |||
733 | ✗ | s->c.block_last_index[0 /* FIXME */] = | |
734 | last = | ||
735 | ✗ | s->dct_quantize(s, temp, 0 /* FIXME */, s->c.qscale, &i); | |
736 | |||
737 | ✗ | bits = 0; | |
738 | |||
739 | ✗ | if (s->c.mb_intra) { | |
740 | ✗ | start_i = 1; | |
741 | ✗ | length = s->intra_ac_vlc_length; | |
742 | ✗ | last_length = s->intra_ac_vlc_last_length; | |
743 | ✗ | bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma | |
744 | } else { | ||
745 | ✗ | start_i = 0; | |
746 | ✗ | length = s->inter_ac_vlc_length; | |
747 | ✗ | last_length = s->inter_ac_vlc_last_length; | |
748 | } | ||
749 | |||
750 | ✗ | if (last >= start_i) { | |
751 | ✗ | run = 0; | |
752 | ✗ | for (i = start_i; i < last; i++) { | |
753 | ✗ | int j = scantable[i]; | |
754 | ✗ | level = temp[j]; | |
755 | |||
756 | ✗ | if (level) { | |
757 | ✗ | level += 64; | |
758 | ✗ | if ((level & (~127)) == 0) | |
759 | ✗ | bits += length[UNI_AC_ENC_INDEX(run, level)]; | |
760 | else | ||
761 | ✗ | bits += esc_length; | |
762 | ✗ | run = 0; | |
763 | } else | ||
764 | ✗ | run++; | |
765 | } | ||
766 | ✗ | i = scantable[last]; | |
767 | |||
768 | ✗ | level = temp[i] + 64; | |
769 | |||
770 | av_assert2(level - 64); | ||
771 | |||
772 | ✗ | if ((level & (~127)) == 0) { | |
773 | ✗ | bits += last_length[UNI_AC_ENC_INDEX(run, level)]; | |
774 | } else | ||
775 | ✗ | bits += esc_length; | |
776 | } | ||
777 | |||
778 | ✗ | if (last >= 0) { | |
779 | ✗ | if (s->c.mb_intra) | |
780 | ✗ | s->c.dct_unquantize_intra(&s->c, temp, 0, s->c.qscale); | |
781 | else | ||
782 | ✗ | s->c.dct_unquantize_inter(&s->c, temp, 0, s->c.qscale); | |
783 | } | ||
784 | |||
785 | ✗ | s->c.idsp.idct_add(lsrc2, 8, temp); | |
786 | |||
787 | ✗ | distortion = s->sse_cmp[1](NULL, lsrc2, lsrc1, 8, 8); | |
788 | |||
789 | ✗ | return distortion + ((bits * s->c.qscale * s->c.qscale * 109 + 64) >> 7); | |
790 | } | ||
791 | |||
792 | ✗ | static int bit8x8_c(MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, | |
793 | ptrdiff_t stride, int h) | ||
794 | { | ||
795 | ✗ | const uint8_t *scantable = s->c.intra_scantable.permutated; | |
796 | ✗ | LOCAL_ALIGNED_16(int16_t, temp, [64]); | |
797 | int i, last, run, bits, level, start_i; | ||
798 | ✗ | const int esc_length = s->ac_esc_length; | |
799 | const uint8_t *length, *last_length; | ||
800 | |||
801 | ✗ | s->pdsp.diff_pixels_unaligned(temp, src1, src2, stride); | |
802 | |||
803 | ✗ | s->c.block_last_index[0 /* FIXME */] = | |
804 | last = | ||
805 | ✗ | s->dct_quantize(s, temp, 0 /* FIXME */, s->c.qscale, &i); | |
806 | |||
807 | ✗ | bits = 0; | |
808 | |||
809 | ✗ | if (s->c.mb_intra) { | |
810 | ✗ | start_i = 1; | |
811 | ✗ | length = s->intra_ac_vlc_length; | |
812 | ✗ | last_length = s->intra_ac_vlc_last_length; | |
813 | ✗ | bits += s->luma_dc_vlc_length[temp[0] + 256]; // FIXME: chroma | |
814 | } else { | ||
815 | ✗ | start_i = 0; | |
816 | ✗ | length = s->inter_ac_vlc_length; | |
817 | ✗ | last_length = s->inter_ac_vlc_last_length; | |
818 | } | ||
819 | |||
820 | ✗ | if (last >= start_i) { | |
821 | ✗ | run = 0; | |
822 | ✗ | for (i = start_i; i < last; i++) { | |
823 | ✗ | int j = scantable[i]; | |
824 | ✗ | level = temp[j]; | |
825 | |||
826 | ✗ | if (level) { | |
827 | ✗ | level += 64; | |
828 | ✗ | if ((level & (~127)) == 0) | |
829 | ✗ | bits += length[UNI_AC_ENC_INDEX(run, level)]; | |
830 | else | ||
831 | ✗ | bits += esc_length; | |
832 | ✗ | run = 0; | |
833 | } else | ||
834 | ✗ | run++; | |
835 | } | ||
836 | ✗ | i = scantable[last]; | |
837 | |||
838 | ✗ | level = temp[i] + 64; | |
839 | |||
840 | av_assert2(level - 64); | ||
841 | |||
842 | ✗ | if ((level & (~127)) == 0) | |
843 | ✗ | bits += last_length[UNI_AC_ENC_INDEX(run, level)]; | |
844 | else | ||
845 | ✗ | bits += esc_length; | |
846 | } | ||
847 | |||
848 | ✗ | return bits; | |
849 | } | ||
850 | |||
851 | #define VSAD_INTRA(size) \ | ||
852 | static int vsad_intra ## size ## _c(MPVEncContext *unused, \ | ||
853 | const uint8_t *s, const uint8_t *dummy, \ | ||
854 | ptrdiff_t stride, int h) \ | ||
855 | { \ | ||
856 | int score = 0, x, y; \ | ||
857 | \ | ||
858 | for (y = 1; y < h; y++) { \ | ||
859 | for (x = 0; x < size; x += 4) { \ | ||
860 | score += FFABS(s[x] - s[x + stride]) + \ | ||
861 | FFABS(s[x + 1] - s[x + stride + 1]) + \ | ||
862 | FFABS(s[x + 2] - s[x + 2 + stride]) + \ | ||
863 | FFABS(s[x + 3] - s[x + 3 + stride]); \ | ||
864 | } \ | ||
865 | s += stride; \ | ||
866 | } \ | ||
867 | \ | ||
868 | return score; \ | ||
869 | } | ||
870 |
4/4✓ Branch 0 taken 840 times.
✓ Branch 1 taken 420 times.
✓ Branch 2 taken 420 times.
✓ Branch 3 taken 48 times.
|
1308 | VSAD_INTRA(8) |
871 |
4/4✓ Branch 0 taken 34475120 times.
✓ Branch 1 taken 8618780 times.
✓ Branch 2 taken 8618780 times.
✓ Branch 3 taken 1231246 times.
|
44325146 | VSAD_INTRA(16) |
872 | |||
873 | #define VSAD(size) \ | ||
874 | static int vsad ## size ## _c(MPVEncContext *unused, \ | ||
875 | const uint8_t *s1, const uint8_t *s2, \ | ||
876 | ptrdiff_t stride, int h) \ | ||
877 | { \ | ||
878 | int score = 0, x, y; \ | ||
879 | \ | ||
880 | for (y = 1; y < h; y++) { \ | ||
881 | for (x = 0; x < size; x++) \ | ||
882 | score += FFABS(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \ | ||
883 | s1 += stride; \ | ||
884 | s2 += stride; \ | ||
885 | } \ | ||
886 | \ | ||
887 | return score; \ | ||
888 | } | ||
889 |
4/4✓ Branch 0 taken 2176 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 272 times.
✓ Branch 3 taken 32 times.
|
2480 | VSAD(8) |
890 |
4/4✓ Branch 0 taken 213085536 times.
✓ Branch 1 taken 13317846 times.
✓ Branch 2 taken 13317846 times.
✓ Branch 3 taken 1902546 times.
|
228305928 | VSAD(16) |
891 | |||
892 | #define SQ(a) ((a) * (a)) | ||
893 | #define VSSE_INTRA(size) \ | ||
894 | static int vsse_intra ## size ## _c(MPVEncContext *unused, \ | ||
895 | const uint8_t *s, const uint8_t *dummy, \ | ||
896 | ptrdiff_t stride, int h) \ | ||
897 | { \ | ||
898 | int score = 0, x, y; \ | ||
899 | \ | ||
900 | for (y = 1; y < h; y++) { \ | ||
901 | for (x = 0; x < size; x += 4) { \ | ||
902 | score += SQ(s[x] - s[x + stride]) + \ | ||
903 | SQ(s[x + 1] - s[x + stride + 1]) + \ | ||
904 | SQ(s[x + 2] - s[x + stride + 2]) + \ | ||
905 | SQ(s[x + 3] - s[x + stride + 3]); \ | ||
906 | } \ | ||
907 | s += stride; \ | ||
908 | } \ | ||
909 | \ | ||
910 | return score; \ | ||
911 | } | ||
912 |
4/4✓ Branch 0 taken 592 times.
✓ Branch 1 taken 296 times.
✓ Branch 2 taken 296 times.
✓ Branch 3 taken 32 times.
|
920 | VSSE_INTRA(8) |
913 |
4/4✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 32 times.
|
1472 | VSSE_INTRA(16) |
914 | |||
915 | #define VSSE(size) \ | ||
916 | static int vsse ## size ## _c(MPVEncContext *unused, const uint8_t *s1, \ | ||
917 | const uint8_t *s2, ptrdiff_t stride, int h) \ | ||
918 | { \ | ||
919 | int score = 0, x, y; \ | ||
920 | \ | ||
921 | for (y = 1; y < h; y++) { \ | ||
922 | for (x = 0; x < size; x++) \ | ||
923 | score += SQ(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \ | ||
924 | s1 += stride; \ | ||
925 | s2 += stride; \ | ||
926 | } \ | ||
927 | \ | ||
928 | return score; \ | ||
929 | } | ||
930 |
4/4✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 32 times.
|
2336 | VSSE(8) |
931 |
4/4✓ Branch 0 taken 4544 times.
✓ Branch 1 taken 284 times.
✓ Branch 2 taken 284 times.
✓ Branch 3 taken 32 times.
|
4860 | VSSE(16) |
932 | |||
933 | #define WRAPPER8_16_SQ(name8, name16) \ | ||
934 | static int name16(MPVEncContext *const s, const uint8_t *dst, \ | ||
935 | const uint8_t *src, ptrdiff_t stride, int h) \ | ||
936 | { \ | ||
937 | int score = 0; \ | ||
938 | \ | ||
939 | score += name8(s, dst, src, stride, 8); \ | ||
940 | score += name8(s, dst + 8, src + 8, stride, 8); \ | ||
941 | if (h == 16) { \ | ||
942 | dst += 8 * stride; \ | ||
943 | src += 8 * stride; \ | ||
944 | score += name8(s, dst, src, stride, 8); \ | ||
945 | score += name8(s, dst + 8, src + 8, stride, 8); \ | ||
946 | } \ | ||
947 | return score; \ | ||
948 | } | ||
949 | |||
950 |
2/2✓ Branch 2 taken 3502682 times.
✓ Branch 3 taken 45 times.
|
3502727 | WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c) |
951 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 3 taken 28 times.
|
32 | WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c) |
952 | ✗ | WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c) | |
953 | #if CONFIG_GPL | ||
954 | ✗ | WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c) | |
955 | #endif | ||
956 | ✗ | WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c) | |
957 | ✗ | WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c) | |
958 | ✗ | WRAPPER8_16_SQ(rd8x8_c, rd16_c) | |
959 | ✗ | WRAPPER8_16_SQ(bit8x8_c, bit16_c) | |
960 | |||
961 | 1063 | av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx) | |
962 | { | ||
963 | 1063 | memset(c, 0, sizeof(*c)); | |
964 | |||
965 | 1063 | c->sum_abs_dctelem = sum_abs_dctelem_c; | |
966 | |||
967 | /* TODO [0] 16 [1] 8 */ | ||
968 | 1063 | c->pix_abs[0][0] = pix_abs16_c; | |
969 | 1063 | c->pix_abs[0][1] = pix_abs16_x2_c; | |
970 | 1063 | c->pix_abs[0][2] = pix_abs16_y2_c; | |
971 | 1063 | c->pix_abs[0][3] = pix_abs16_xy2_c; | |
972 | 1063 | c->pix_abs[1][0] = pix_abs8_c; | |
973 | 1063 | c->pix_abs[1][1] = pix_abs8_x2_c; | |
974 | 1063 | c->pix_abs[1][2] = pix_abs8_y2_c; | |
975 | 1063 | c->pix_abs[1][3] = pix_abs8_xy2_c; | |
976 | |||
977 | #define SET_CMP_FUNC(name) \ | ||
978 | c->name[0] = name ## 16_c; \ | ||
979 | c->name[1] = name ## 8x8_c; | ||
980 | |||
981 | 1063 | SET_CMP_FUNC(hadamard8_diff) | |
982 | 1063 | c->hadamard8_diff[4] = hadamard8_intra16_c; | |
983 | 1063 | c->hadamard8_diff[5] = hadamard8_intra8x8_c; | |
984 | 1063 | SET_CMP_FUNC(dct_sad) | |
985 | 1063 | SET_CMP_FUNC(dct_max) | |
986 | #if CONFIG_GPL | ||
987 | 1063 | SET_CMP_FUNC(dct264_sad) | |
988 | #endif | ||
989 | 1063 | c->sad[0] = pix_abs16_c; | |
990 | 1063 | c->sad[1] = pix_abs8_c; | |
991 | 1063 | c->sse[0] = sse16_c; | |
992 | 1063 | c->sse[1] = sse8_c; | |
993 | 1063 | c->sse[2] = sse4_c; | |
994 | 1063 | SET_CMP_FUNC(quant_psnr) | |
995 | 1063 | SET_CMP_FUNC(rd) | |
996 | 1063 | SET_CMP_FUNC(bit) | |
997 | 1063 | c->vsad[0] = vsad16_c; | |
998 | 1063 | c->vsad[1] = vsad8_c; | |
999 | 1063 | c->vsad[4] = vsad_intra16_c; | |
1000 | 1063 | c->vsad[5] = vsad_intra8_c; | |
1001 | 1063 | c->vsse[0] = vsse16_c; | |
1002 | 1063 | c->vsse[1] = vsse8_c; | |
1003 | 1063 | c->vsse[4] = vsse_intra16_c; | |
1004 | 1063 | c->vsse[5] = vsse_intra8_c; | |
1005 | 1063 | c->nsse[0] = nsse16_c; | |
1006 | 1063 | c->nsse[1] = nsse8_c; | |
1007 | #if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER | ||
1008 | 1063 | ff_dsputil_init_dwt(c); | |
1009 | #endif | ||
1010 | |||
1011 | 1063 | c->median_sad[0] = pix_median_abs16_c; | |
1012 | 1063 | c->median_sad[1] = pix_median_abs8_c; | |
1013 | |||
1014 | #if ARCH_AARCH64 | ||
1015 | ff_me_cmp_init_aarch64(c, avctx); | ||
1016 | #elif ARCH_ARM | ||
1017 | ff_me_cmp_init_arm(c, avctx); | ||
1018 | #elif ARCH_PPC | ||
1019 | ff_me_cmp_init_ppc(c, avctx); | ||
1020 | #elif ARCH_RISCV | ||
1021 | ff_me_cmp_init_riscv(c, avctx); | ||
1022 | #elif ARCH_X86 | ||
1023 | 1063 | ff_me_cmp_init_x86(c, avctx); | |
1024 | #elif ARCH_MIPS | ||
1025 | ff_me_cmp_init_mips(c, avctx); | ||
1026 | #endif | ||
1027 | |||
1028 | 1063 | } | |
1029 |