40 for (i = 0; i < h; i++) {
41 s += sq[pix1[0] - pix2[0]];
42 s += sq[pix1[1] - pix2[1]];
43 s += sq[pix1[2] - pix2[2]];
44 s += sq[pix1[3] - pix2[3]];
57 for (i = 0; i < h; i++) {
58 s += sq[pix1[0] - pix2[0]];
59 s += sq[pix1[1] - pix2[1]];
60 s += sq[pix1[2] - pix2[2]];
61 s += sq[pix1[3] - pix2[3]];
62 s += sq[pix1[4] - pix2[4]];
63 s += sq[pix1[5] - pix2[5]];
64 s += sq[pix1[6] - pix2[6]];
65 s += sq[pix1[7] - pix2[7]];
78 for (i = 0; i < h; i++) {
79 s += sq[pix1[0] - pix2[0]];
80 s += sq[pix1[1] - pix2[1]];
81 s += sq[pix1[2] - pix2[2]];
82 s += sq[pix1[3] - pix2[3]];
83 s += sq[pix1[4] - pix2[4]];
84 s += sq[pix1[5] - pix2[5]];
85 s += sq[pix1[6] - pix2[6]];
86 s += sq[pix1[7] - pix2[7]];
87 s += sq[pix1[8] - pix2[8]];
88 s += sq[pix1[9] - pix2[9]];
89 s += sq[pix1[10] - pix2[10]];
90 s += sq[pix1[11] - pix2[11]];
91 s += sq[pix1[12] - pix2[12]];
92 s += sq[pix1[13] - pix2[13]];
93 s += sq[pix1[14] - pix2[14]];
94 s += sq[pix1[15] - pix2[15]];
106 for (i = 0; i < 64; i++)
107 sum +=
FFABS(block[i]);
111 #define avg2(a, b) ((a + b + 1) >> 1)
112 #define avg4(a, b, c, d) ((a + b + c + d + 2) >> 2)
115 int line_size,
int h)
119 for (i = 0; i < h; i++) {
120 s += abs(pix1[0] - pix2[0]);
121 s += abs(pix1[1] - pix2[1]);
122 s += abs(pix1[2] - pix2[2]);
123 s += abs(pix1[3] - pix2[3]);
124 s += abs(pix1[4] - pix2[4]);
125 s += abs(pix1[5] - pix2[5]);
126 s += abs(pix1[6] - pix2[6]);
127 s += abs(pix1[7] - pix2[7]);
128 s += abs(pix1[8] - pix2[8]);
129 s += abs(pix1[9] - pix2[9]);
130 s += abs(pix1[10] - pix2[10]);
131 s += abs(pix1[11] - pix2[11]);
132 s += abs(pix1[12] - pix2[12]);
133 s += abs(pix1[13] - pix2[13]);
134 s += abs(pix1[14] - pix2[14]);
135 s += abs(pix1[15] - pix2[15]);
143 int line_size,
int h)
147 for (i = 0; i < h; i++) {
148 s += abs(pix1[0] -
avg2(pix2[0], pix2[1]));
149 s += abs(pix1[1] -
avg2(pix2[1], pix2[2]));
150 s += abs(pix1[2] -
avg2(pix2[2], pix2[3]));
151 s += abs(pix1[3] -
avg2(pix2[3], pix2[4]));
152 s += abs(pix1[4] -
avg2(pix2[4], pix2[5]));
153 s += abs(pix1[5] -
avg2(pix2[5], pix2[6]));
154 s += abs(pix1[6] -
avg2(pix2[6], pix2[7]));
155 s += abs(pix1[7] -
avg2(pix2[7], pix2[8]));
156 s += abs(pix1[8] -
avg2(pix2[8], pix2[9]));
157 s += abs(pix1[9] -
avg2(pix2[9], pix2[10]));
158 s += abs(pix1[10] -
avg2(pix2[10], pix2[11]));
159 s += abs(pix1[11] -
avg2(pix2[11], pix2[12]));
160 s += abs(pix1[12] -
avg2(pix2[12], pix2[13]));
161 s += abs(pix1[13] -
avg2(pix2[13], pix2[14]));
162 s += abs(pix1[14] -
avg2(pix2[14], pix2[15]));
163 s += abs(pix1[15] -
avg2(pix2[15], pix2[16]));
171 int line_size,
int h)
174 uint8_t *pix3 = pix2 + line_size;
176 for (i = 0; i < h; i++) {
177 s += abs(pix1[0] -
avg2(pix2[0], pix3[0]));
178 s += abs(pix1[1] -
avg2(pix2[1], pix3[1]));
179 s += abs(pix1[2] -
avg2(pix2[2], pix3[2]));
180 s += abs(pix1[3] -
avg2(pix2[3], pix3[3]));
181 s += abs(pix1[4] -
avg2(pix2[4], pix3[4]));
182 s += abs(pix1[5] -
avg2(pix2[5], pix3[5]));
183 s += abs(pix1[6] -
avg2(pix2[6], pix3[6]));
184 s += abs(pix1[7] -
avg2(pix2[7], pix3[7]));
185 s += abs(pix1[8] -
avg2(pix2[8], pix3[8]));
186 s += abs(pix1[9] -
avg2(pix2[9], pix3[9]));
187 s += abs(pix1[10] -
avg2(pix2[10], pix3[10]));
188 s += abs(pix1[11] -
avg2(pix2[11], pix3[11]));
189 s += abs(pix1[12] -
avg2(pix2[12], pix3[12]));
190 s += abs(pix1[13] -
avg2(pix2[13], pix3[13]));
191 s += abs(pix1[14] -
avg2(pix2[14], pix3[14]));
192 s += abs(pix1[15] -
avg2(pix2[15], pix3[15]));
201 int line_size,
int h)
204 uint8_t *pix3 = pix2 + line_size;
206 for (i = 0; i < h; i++) {
207 s += abs(pix1[0] -
avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
208 s += abs(pix1[1] -
avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
209 s += abs(pix1[2] -
avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
210 s += abs(pix1[3] -
avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
211 s += abs(pix1[4] -
avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
212 s += abs(pix1[5] -
avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
213 s += abs(pix1[6] -
avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
214 s += abs(pix1[7] -
avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
215 s += abs(pix1[8] -
avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
216 s += abs(pix1[9] -
avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
217 s += abs(pix1[10] -
avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
218 s += abs(pix1[11] -
avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
219 s += abs(pix1[12] -
avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
220 s += abs(pix1[13] -
avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
221 s += abs(pix1[14] -
avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
222 s += abs(pix1[15] -
avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
231 int line_size,
int h)
235 for (i = 0; i < h; i++) {
236 s += abs(pix1[0] - pix2[0]);
237 s += abs(pix1[1] - pix2[1]);
238 s += abs(pix1[2] - pix2[2]);
239 s += abs(pix1[3] - pix2[3]);
240 s += abs(pix1[4] - pix2[4]);
241 s += abs(pix1[5] - pix2[5]);
242 s += abs(pix1[6] - pix2[6]);
243 s += abs(pix1[7] - pix2[7]);
251 int line_size,
int h)
255 for (i = 0; i < h; i++) {
256 s += abs(pix1[0] -
avg2(pix2[0], pix2[1]));
257 s += abs(pix1[1] -
avg2(pix2[1], pix2[2]));
258 s += abs(pix1[2] -
avg2(pix2[2], pix2[3]));
259 s += abs(pix1[3] -
avg2(pix2[3], pix2[4]));
260 s += abs(pix1[4] -
avg2(pix2[4], pix2[5]));
261 s += abs(pix1[5] -
avg2(pix2[5], pix2[6]));
262 s += abs(pix1[6] -
avg2(pix2[6], pix2[7]));
263 s += abs(pix1[7] -
avg2(pix2[7], pix2[8]));
271 int line_size,
int h)
274 uint8_t *pix3 = pix2 + line_size;
276 for (i = 0; i < h; i++) {
277 s += abs(pix1[0] -
avg2(pix2[0], pix3[0]));
278 s += abs(pix1[1] -
avg2(pix2[1], pix3[1]));
279 s += abs(pix1[2] -
avg2(pix2[2], pix3[2]));
280 s += abs(pix1[3] -
avg2(pix2[3], pix3[3]));
281 s += abs(pix1[4] -
avg2(pix2[4], pix3[4]));
282 s += abs(pix1[5] -
avg2(pix2[5], pix3[5]));
283 s += abs(pix1[6] -
avg2(pix2[6], pix3[6]));
284 s += abs(pix1[7] -
avg2(pix2[7], pix3[7]));
293 int line_size,
int h)
296 uint8_t *pix3 = pix2 + line_size;
298 for (i = 0; i < h; i++) {
299 s += abs(pix1[0] -
avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
300 s += abs(pix1[1] -
avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
301 s += abs(pix1[2] -
avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
302 s += abs(pix1[3] -
avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
303 s += abs(pix1[4] -
avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
304 s += abs(pix1[5] -
avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
305 s += abs(pix1[6] -
avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
306 s += abs(pix1[7] -
avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
316 int score1 = 0, score2 = 0, x,
y;
318 for (y = 0; y < h; y++) {
319 for (x = 0; x < 16; x++)
320 score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
322 for (x = 0; x < 15; x++)
323 score2 +=
FFABS(s1[x] - s1[x + stride] -
324 s1[x + 1] + s1[x + stride + 1]) -
325 FFABS(s2[x] - s2[x + stride] -
326 s2[x + 1] + s2[x + stride + 1]);
335 return score1 +
FFABS(score2) * 8;
340 int score1 = 0, score2 = 0, x,
y;
342 for (y = 0; y < h; y++) {
343 for (x = 0; x < 8; x++)
344 score1 += (s1[x] - s2[x]) * (s1[x] - s2[x]);
346 for (x = 0; x < 7; x++)
347 score2 +=
FFABS(s1[x] - s1[x + stride] -
348 s1[x + 1] + s1[x + stride + 1]) -
349 FFABS(s2[x] - s2[x + stride] -
350 s2[x + 1] + s2[x + stride + 1]);
359 return score1 +
FFABS(score2) * 8;
372 memset(cmp, 0,
sizeof(
void *) * 6);
374 for (i = 0; i < 6; i++) {
375 switch (type & 0xFF) {
425 "internal error in cmp function selection\n");
430 #define BUTTERFLY2(o1, o2, i1, i2) \
434 #define BUTTERFLY1(x, y) \
443 #define BUTTERFLYA(x, y) (FFABS((x) + (y)) + FFABS((x) - (y)))
448 int i,
temp[64], sum = 0;
452 for (i = 0; i < 8; i++) {
455 src[stride * i + 0] - dst[stride * i + 0],
456 src[stride * i + 1] - dst[stride * i + 1]);
458 src[stride * i + 2] - dst[stride * i + 2],
459 src[stride * i + 3] - dst[stride * i + 3]);
461 src[stride * i + 4] - dst[stride * i + 4],
462 src[stride * i + 5] - dst[stride * i + 5]);
464 src[stride * i + 6] - dst[stride * i + 6],
465 src[stride * i + 7] - dst[stride * i + 7]);
478 for (i = 0; i < 8; i++) {
489 sum +=
BUTTERFLYA(temp[8 * 0 + i], temp[8 * 4 + i]) +
490 BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i]) +
491 BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i]) +
500 int i,
temp[64], sum = 0;
504 for (i = 0; i < 8; i++) {
507 src[stride * i + 0], src[stride * i + 1]);
509 src[stride * i + 2], src[stride * i + 3]);
511 src[stride * i + 4], src[stride * i + 5]);
513 src[stride * i + 6], src[stride * i + 7]);
526 for (i = 0; i < 8; i++) {
539 +
BUTTERFLYA(temp[8 * 1 + i], temp[8 * 5 + i])
540 +
BUTTERFLYA(temp[8 * 2 + i], temp[8 * 6 + i])
541 +
BUTTERFLYA(temp[8 * 3 + i], temp[8 * 7 + i]);
544 sum -=
FFABS(temp[8 * 0] + temp[8 * 4]);
564 const int s07 = SRC(0) + SRC(7); \
565 const int s16 = SRC(1) + SRC(6); \
566 const int s25 = SRC(2) + SRC(5); \
567 const int s34 = SRC(3) + SRC(4); \
568 const int a0 = s07 + s34; \
569 const int a1 = s16 + s25; \
570 const int a2 = s07 - s34; \
571 const int a3 = s16 - s25; \
572 const int d07 = SRC(0) - SRC(7); \
573 const int d16 = SRC(1) - SRC(6); \
574 const int d25 = SRC(2) - SRC(5); \
575 const int d34 = SRC(3) - SRC(4); \
576 const int a4 = d16 + d25 + (d07 + (d07 >> 1)); \
577 const int a5 = d07 - d34 - (d25 + (d25 >> 1)); \
578 const int a6 = d07 + d34 - (d16 + (d16 >> 1)); \
579 const int a7 = d16 - d25 + (d34 + (d34 >> 1)); \
581 DST(1, a4 + (a7 >> 2)); \
582 DST(2, a2 + (a3 >> 1)); \
583 DST(3, a5 + (a6 >> 2)); \
585 DST(5, a6 - (a5 >> 2)); \
586 DST(6, (a2 >> 1) - a3); \
587 DST(7, (a4 >> 2) - a7); \
598 #define SRC(x) dct[i][x]
599 #define DST(x, v) dct[i][x] = v
600 for (i = 0; i < 8; i++)
605 #define
SRC(x) dct[x][i]
606 #define DST(x, v) sum += FFABS(v)
607 for (i = 0; i < 8; i++)
616 uint8_t *src2,
int stride,
int h)
626 for (i = 0; i < 64; i++)
633 uint8_t *src2,
int stride,
int h)
636 int16_t *
const bak =
temp + 64;
644 memcpy(bak,
temp, 64 *
sizeof(int16_t));
651 for (i = 0; i < 64; i++)
652 sum += (
temp[i] - bak[i]) * (
temp[i] - bak[i]);
692 if (last >= start_i) {
694 for (i = start_i; i < last; i++) {
695 int j = scantable[i];
700 if ((level & (~127)) == 0)
710 level =
temp[i] + 64;
714 if ((level & (~127)) == 0) {
729 distortion = s->
mecc.
sse[1](NULL, lsrc2, lsrc1, 8, 8);
731 return distortion + ((bits * s->
qscale * s->
qscale * 109 + 64) >> 7);
764 if (last >= start_i) {
766 for (i = start_i; i < last; i++) {
767 int j = scantable[i];
772 if ((level & (~127)) == 0)
782 level =
temp[i] + 64;
786 if ((level & (~127)) == 0)
795 #define VSAD_INTRA(size) \
796 static int vsad_intra ## size ## _c(MpegEncContext *c, \
797 uint8_t *s, uint8_t *dummy, \
800 int score = 0, x, y; \
802 for (y = 1; y < h; y++) { \
803 for (x = 0; x < size; x += 4) { \
804 score += FFABS(s[x] - s[x + stride]) + \
805 FFABS(s[x + 1] - s[x + stride + 1]) + \
806 FFABS(s[x + 2] - s[x + 2 + stride]) + \
807 FFABS(s[x + 3] - s[x + 3 + stride]); \
818 static int vsad ## size ## _c(MpegEncContext *c, \
819 uint8_t *s1, uint8_t *s2, \
822 int score = 0, x, y; \
824 for (y = 1; y < h; y++) { \
825 for (x = 0; x < size; x++) \
826 score += FFABS(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
836 #define SQ(a) ((a) * (a))
837 #define VSSE_INTRA(size) \
838 static int vsse_intra ## size ## _c(MpegEncContext *c, \
839 uint8_t *s, uint8_t *dummy, \
842 int score = 0, x, y; \
844 for (y = 1; y < h; y++) { \
845 for (x = 0; x < size; x += 4) { \
846 score += SQ(s[x] - s[x + stride]) + \
847 SQ(s[x + 1] - s[x + stride + 1]) + \
848 SQ(s[x + 2] - s[x + stride + 2]) + \
849 SQ(s[x + 3] - s[x + stride + 3]); \
860 static int vsse ## size ## _c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, \
863 int score = 0, x, y; \
865 for (y = 1; y < h; y++) { \
866 for (x = 0; x < size; x++) \
867 score += SQ(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
877 #define WRAPPER8_16_SQ(name8, name16) \
878 static int name16(MpegEncContext *s, uint8_t *dst, uint8_t *src, \
883 score += name8(s, dst, src, stride, 8); \
884 score += name8(s, dst + 8, src + 8, stride, 8); \
888 score += name8(s, dst, src, stride, 8); \
889 score += name8(s, dst + 8, src + 8, stride, 8); \
909 for (i = 0; i < 512; i++)
915 static int did_fail = 0;
918 if ((intptr_t)aligned & 15) {
920 #if HAVE_MMX || HAVE_ALTIVEC
922 "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
923 "and may be very slow or crash. This is not a bug in libavcodec,\n"
924 "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
925 "Do not report crashes to FFmpeg developers.\n");
950 #define SET_CMP_FUNC(name) \
951 c->name[0] = name ## 16_c; \
952 c->name[1] = name ## 8x8_c;
970 c->
vsad[0] = vsad16_c;
971 c->
vsad[1] = vsad8_c;
972 c->
vsad[4] = vsad_intra16_c;
973 c->
vsad[5] = vsad_intra8_c;
974 c->
vsse[0] = vsse16_c;
975 c->
vsse[1] = vsse8_c;
976 c->
vsse[4] = vsse_intra16_c;
977 c->
vsse[5] = vsse_intra8_c;
980 #if CONFIG_SNOW_DECODER || CONFIG_SNOW_ENCODER