1 /*
2 * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (C) 2008 David Conrad
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
28
30 int max_allocated_lines, int line_width,
32 {
34
35 buf->base_buffer = base_buffer;
36 buf->line_count = line_count;
37 buf->line_width = line_width;
38 buf->data_count = max_allocated_lines;
39 buf->line =
av_calloc(line_count,
sizeof(*buf->line));
40 if (!buf->line)
43 if (!buf->data_stack) {
46 }
47
48 for (
i = 0;
i < max_allocated_lines;
i++) {
50 if (!buf->data_stack[
i]) {
56 }
57 }
58
59 buf->data_stack_top = max_allocated_lines - 1;
60 return 0;
61 }
62
64 {
66
68 // av_assert1(!buf->line[line]);
70 return buf->line[
line];
71
72 buffer = buf->data_stack[buf->data_stack_top];
73 buf->data_stack_top--;
75
77 }
78
80 {
82
85
87 buf->data_stack_top++;
88 buf->data_stack[buf->data_stack_top] =
buffer;
90 }
91
93 {
95
96 if (!buf->line)
97 return;
98
99 for (
i = 0;
i < buf->line_count;
i++)
102 }
103
105 {
108
109 if (buf->data_stack)
110 for (
i = buf->data_count - 1;
i >= 0;
i--)
114 }
115
117 int dst_step, int src_step, int ref_step,
120 {
125
126 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
127 if (mirror_left) {
131 }
132
133 for (
i = 0;
i <
w;
i++)
135 ((mul * (
ref[
i * ref_step] +
136 ref[(
i + 1) * ref_step]) +
139
140 if (mirror_right)
142 ((mul * 2 *
ref[
w * ref_step] + add) >>
shift),
144 }
145
147 int dst_step, int src_step, int ref_step,
150 {
155
157 #define LIFTS(src, ref, inv) \
158 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
159 : -((-16 * (src) + (ref) + add / \
160 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
161 if (mirror_left) {
165 }
166
167 for (
i = 0;
i <
w;
i++)
169 mul * (
ref[
i * ref_step] +
170 ref[(
i + 1) * ref_step]) + add,
172
173 if (mirror_right)
175 mul * 2 *
ref[
w * ref_step] + add,
177 }
178
180 {
181 const int width2 =
width >> 1;
182 int x;
183 const int w2 = (
width + 1) >> 1;
184
185 for (x = 0; x < width2; x++) {
187 temp[x + w2] =
b[2 * x + 1];
188 }
191 lift(
b + w2,
temp + w2,
temp, 1, 1, 1,
width, -1, 0, 1, 1, 0);
192 lift(
b,
temp,
b + w2, 1, 1, 1,
width, 1, 2, 2, 0, 0);
193 }
194
197 {
199
202 }
203
206 {
208
211 }
212
215 {
216 int y;
219
220 for (y = -2; y <
height; y += 2) {
223
224 if (y + 1 < (
unsigned)
height)
226 if (y + 2 < (
unsigned)
height)
228
229 if (y + 1 < (
unsigned)
height)
231 if (y + 0 < (
unsigned)
height)
233
236 }
237 }
238
240 {
241 const int w2 = (
width + 1) >> 1;
242
243 lift(
temp + w2,
b + 1,
b, 1, 2, 2,
width,
W_AM,
W_AO,
W_AS, 1, 1);
244 liftS(
temp,
b,
temp + w2, 1, 2, 1,
width,
W_BM,
W_BO,
W_BS, 0, 0);
245 lift(
b + w2,
temp + w2,
temp, 1, 1, 1,
width,
W_CM,
W_CO,
W_CS, 1, 0);
246 lift(
b,
temp,
b + w2, 1, 1, 1,
width,
W_DM,
W_DO,
W_DS, 0, 0);
247 }
248
251 {
253
256 }
257
260 {
262
265 }
266
269 {
271
274 (5 * 16) - (1 << 23);
275 }
276
279 {
281
284 }
285
288 {
289 int y;
294
295 for (y = -4; y <
height; y += 2) {
298
299 if (y + 3 < (
unsigned)
height)
301 if (y + 4 < (
unsigned)
height)
303
304 if (y + 3 < (
unsigned)
height)
306 if (y + 2 < (
unsigned)
height)
308 if (y + 1 < (
unsigned)
height)
310 if (y + 0 < (
unsigned)
height)
312
317 }
318 }
319
321 int stride,
int type,
int decomposition_count)
322 {
324
331 break;
336 break;
337 }
338 }
339 }
340
342 {
343 const int width2 =
width >> 1;
344 const int w2 = (
width + 1) >> 1;
345 int x;
346
347 for (x = 0; x < width2; x++) {
349 temp[2 * x + 1] =
b[x + w2];
350 }
353
355 for (x = 2; x <
width - 1; x += 2) {
357 b[x - 1] =
temp[x - 1] + ((
b[x - 2] +
b[x] + 1) >> 1);
358 }
360 b[x] =
temp[x] - ((
temp[x - 1] + 1) >> 1);
361 b[x - 1] =
temp[x - 1] + ((
b[x - 2] +
b[x] + 1) >> 1);
362 } else
363 b[x - 1] =
temp[x - 1] +
b[x - 2];
364 }
365
368 {
370
373 }
374
377 {
379
382 }
383
385 int height,
int stride_line)
386 {
391 }
392
395 {
399 }
400
404 int stride_line)
405 {
407
412 stride_line);
415 stride_line);
416
418 int x;
419
420 for (x = 0; x <
width; x++) {
421 b2[x] -= (
b1[x] +
b3[x] + 2) >> 2;
422 b1[x] += (
b0[x] +
b2[x]) >> 1;
423 }
424 } else {
425 if (y + 1 < (
unsigned)
height)
427 if (y + 0 < (
unsigned)
height)
429 }
430
431 if (y - 1 < (
unsigned)
height)
433 if (y + 0 < (
unsigned)
height)
435
439 }
440
444 {
450
451 if (y + 1 < (
unsigned)
height)
453 if (y + 0 < (
unsigned)
height)
455
456 if (y - 1 < (
unsigned)
height)
458 if (y + 0 < (
unsigned)
height)
460
464 }
465
467 {
468 const int w2 = (
width + 1) >> 1;
469 int x;
470
471 temp[0] =
b[0] - ((3 *
b[w2] + 2) >> 2);
472 for (x = 1; x < (
width >> 1); x++) {
473 temp[2 * x] =
b[x] - ((3 * (
b[x + w2 - 1] +
b[x + w2]) + 4) >> 3);
474 temp[2 * x - 1] =
b[x + w2 - 1] -
temp[2 * x - 2] -
temp[2 * x];
475 }
477 temp[2 * x] =
b[x] - ((3 *
b[x + w2 - 1] + 2) >> 2);
478 temp[2 * x - 1] =
b[x + w2 - 1] -
temp[2 * x - 2] -
temp[2 * x];
479 } else
480 temp[2 * x - 1] =
b[x + w2 - 1] - 2 *
temp[2 * x - 2];
481
483 for (x = 2; x <
width - 1; x += 2) {
485 b[x - 1] =
temp[x - 1] + ((3 * (
b[x - 2] +
b[x])) >> 1);
486 }
489 b[x - 1] =
temp[x - 1] + ((3 * (
b[x - 2] +
b[x])) >> 1);
490 } else
491 b[x - 1] =
temp[x - 1] + 3 *
b[x - 2];
492 }
493
496 {
498
501 }
502
505 {
507
510 }
511
514 {
516
519 }
520
523 {
525
528 }
529
533 {
535
541 }
542 }
543
545 int height,
int stride_line)
546 {
552 }
553
556 {
562 }
563
567 int stride_line)
568 {
570
577 stride_line);
580 stride_line);
581
582 if (y > 0 && y + 4 <
height) {
584 } else {
585 if (y + 3 < (
unsigned)
height)
587 if (y + 2 < (
unsigned)
height)
589 if (y + 1 < (
unsigned)
height)
591 if (y + 0 < (
unsigned)
height)
593 }
594
595 if (y - 1 < (
unsigned)
height)
597 if (y + 0 < (
unsigned)
height)
599
605 }
606
610 {
618
619 if (y + 3 < (
unsigned)
height)
621 if (y + 2 < (
unsigned)
height)
623 if (y + 1 < (
unsigned)
height)
625 if (y + 0 < (
unsigned)
height)
627
628 if (y - 1 < (
unsigned)
height)
630 if (y + 0 < (
unsigned)
height)
632
638 }
639
642 int decomposition_count)
643 {
649 stride_line <<
level);
650 break;
653 stride_line <<
level);
654 break;
655 }
656 }
657 }
658
662 int type,
int decomposition_count,
int y)
663 {
664 const int support =
type == 1 ? 3 : 5;
667 return;
668
676 stride_line <<
level);
677 break;
682 stride_line <<
level);
683 break;
684 }
685 }
686 }
687
690 int decomposition_count)
691 {
698 break;
702 break;
703 }
704 }
705 }
706
710 int decomposition_count, int y)
711 {
712 const int support =
type == 1 ? 3 : 5;
715 return;
716
723 break;
727 break;
728 }
729 }
730 }
731
733 int stride,
int type,
int decomposition_count)
734 {
736 int y;
738 decomposition_count);
739 for (y = 0; y <
height; y += 4)
741 decomposition_count, y);
742 }
743
744 static inline int w_c(
MPVEncContext *v,
const uint8_t *pix1,
const uint8_t *pix2, ptrdiff_t line_size,
746 {
748 const int dec_count =
w == 8 ? 3 : 4;
749 int tmp[32 * 32], tmp2[32];
751 static const int scale[2][2][4][4] = {
752 {
753 { // 9/7 8x8 dec=3
754 { 268, 239, 239, 213 },
755 { 0, 224, 224, 152 },
756 { 0, 135, 135, 110 },
757 },
758 { // 9/7 16x16 or 32x32 dec=4
759 { 344, 310, 310, 280 },
760 { 0, 320, 320, 228 },
761 { 0, 175, 175, 136 },
762 { 0, 129, 129, 102 },
763 }
764 },
765 {
766 { // 5/3 8x8 dec=3
767 { 275, 245, 245, 218 },
768 { 0, 230, 230, 156 },
769 { 0, 138, 138, 113 },
770 },
771 { // 5/3 16x16 or 32x32 dec=4
772 { 352, 317, 317, 286 },
773 { 0, 328, 328, 233 },
774 { 0, 180, 180, 140 },
775 { 0, 132, 132, 105 },
776 }
777 }
778 };
779
780 for (
i = 0;
i <
h;
i++) {
781 for (j = 0; j <
w; j += 4) {
782 tmp[32 *
i + j + 0] = (pix1[j + 0] - pix2[j + 0]) * (1 << 4);
783 tmp[32 *
i + j + 1] = (pix1[j + 1] - pix2[j + 1]) * (1 << 4);
784 tmp[32 *
i + j + 2] = (pix1[j + 2] - pix2[j + 2]) * (1 << 4);
785 tmp[32 *
i + j + 3] = (pix1[j + 3] - pix2[j + 3]) * (1 << 4);
786 }
787 pix1 += line_size;
788 pix2 += line_size;
789 }
790
792
796 for (ori =
level ? 1 : 0; ori < 4; ori++) {
798 int sx = (ori & 1) ?
size : 0;
800 int sy = (ori & 2) ?
stride >> 1 : 0;
801
803 for (j = 0; j <
size; j++) {
807 }
808 }
811 }
812
814 {
815 return w_c(v, pix1, pix2, line_size, 8,
h, 1);
816 }
817
819 {
820 return w_c(v, pix1, pix2, line_size, 8,
h, 0);
821 }
822
824 {
825 return w_c(v, pix1, pix2, line_size, 16,
h, 1);
826 }
827
829 {
830 return w_c(v, pix1, pix2, line_size, 16,
h, 0);
831 }
832
834 {
835 return w_c(v, pix1, pix2, line_size, 32,
h, 1);
836 }
837
839 {
840 return w_c(v, pix1, pix2, line_size, 32,
h, 0);
841 }
842
844 {
849 }
850
852 {
856
857 #if ARCH_X86 && HAVE_MMX
859 #endif
860 }