1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <assert.h>
20 #include <stdint.h>
21 #include <string.h>
22
23 #include "config.h"
30
33 {
35 unsigned int sum = 0;
36
37 for (
i = 0;
i < 8 * 8;
i++) {
44
45 sum += (
w *
b) * (
w *
b) >> 4;
46 }
47 return sum >> 2;
48 }
49
51 {
53
54 for (
i = 0;
i < 8 * 8;
i++)
58 }
59
61 {
63
64 for (
i = 0;
i < 16;
i++) {
65 for (j = 0; j < 16; j += 8) {
75 }
76 pix += line_size - 16;
77 }
79 }
80
82 {
85
86 for (
i = 0;
i < 16;
i++) {
87 for (j = 0; j < 16; j += 8) {
88 #if HAVE_FAST_64BIT
89 register uint64_t x = *(uint64_t *)
pix;
91 s += sq[(x >> 8) & 0xff];
92 s += sq[(x >> 16) & 0xff];
93 s += sq[(x >> 24) & 0xff];
94 s += sq[(x >> 32) & 0xff];
95 s += sq[(x >> 40) & 0xff];
96 s += sq[(x >> 48) & 0xff];
97 s += sq[(x >> 56) & 0xff];
98 #else
99 register uint32_t x = *(uint32_t *)
pix;
101 s += sq[(x >> 8) & 0xff];
102 s += sq[(x >> 16) & 0xff];
103 s += sq[(x >> 24) & 0xff];
104 x = *(uint32_t *) (
pix + 4);
106 s += sq[(x >> 8) & 0xff];
107 s += sq[(x >> 16) & 0xff];
108 s += sq[(x >> 24) & 0xff];
109 #endif
111 }
112 pix += line_size - 16;
113 }
115 }
116
118 {
120 memset(ptr -
w, ptr[0],
w);
123 }
124 }
125
126 /* draw the edges of width 'w' of an image of size width, height */
127 // FIXME: Check that this is OK for MPEG-4 interlaced.
129 int w,
int h,
int sides)
130 {
131 uint8_t *last_line;
133
134 /* left and right */
139 } else {
142 }
143
144 /* top and bottom + corners */
148 for (
i = 0;
i <
h;
i++)
149 // top
152 for (
i = 0;
i <
h;
i++)
153 // bottom
154 memcpy(last_line + (
i + 1) *
wrap, last_line,
width +
w +
w);
155 }
156
157 /* This wrapper function only serves to convert the stride parameters
158 * from ptrdiff_t to int for av_image_copy_plane(). */
160 const uint8_t *
src, ptrdiff_t src_wrap,
162 {
164 }
165
166 /* 2x2 -> 1x1 */
168 const uint8_t *
src, ptrdiff_t src_wrap,
170 {
172 const uint8_t *s1, *s2;
173 uint8_t *d;
174
177 s2 = s1 + src_wrap;
180 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
181 d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
182 d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
183 d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
184 s1 += 8;
185 s2 += 8;
186 d += 4;
187 }
189 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
190 s1 += 2;
191 s2 += 2;
192 d++;
193 }
196 }
197 }
198
199 /* 4x4 -> 1x1 */
201 const uint8_t *
src, ptrdiff_t src_wrap,
203 {
205 const uint8_t *s1, *s2, *s3, *s4;
206 uint8_t *d;
207
210 s2 = s1 + src_wrap;
211 s3 = s2 + src_wrap;
212 s4 = s3 + src_wrap;
215 d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
216 s2[0] + s2[1] + s2[2] + s2[3] +
217 s3[0] + s3[1] + s3[2] + s3[3] +
218 s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
219 s1 += 4;
220 s2 += 4;
221 s3 += 4;
222 s4 += 4;
223 d++;
224 }
227 }
228 }
229
230 /* 8x8 -> 1x1 */
232 const uint8_t *
src, ptrdiff_t src_wrap,
234 {
236
240 for (
i = 0;
i < 8;
i++) {
244 }
245 *(
dst++) = (
tmp + 32) >> 6;
246 src += 8 - 8 * src_wrap;
247 }
250 }
251 }
252
255 {
258
263
266
268
269 #if ARCH_AARCH64
271 #elif ARCH_ARM
273 #elif ARCH_PPC
275 #elif ARCH_RISCV
277 #elif ARCH_X86
279 #elif ARCH_MIPS
281 #endif
282 }