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
27
29 int max_allocated_lines, int line_width,
31 {
33
34 buf->base_buffer = base_buffer;
35 buf->line_count = line_count;
36 buf->line_width = line_width;
37 buf->data_count = max_allocated_lines;
38 buf->line =
av_calloc(line_count,
sizeof(*buf->line));
39 if (!buf->line)
42 if (!buf->data_stack) {
45 }
46
47 for (
i = 0;
i < max_allocated_lines;
i++) {
49 if (!buf->data_stack[
i]) {
55 }
56 }
57
58 buf->data_stack_top = max_allocated_lines - 1;
59 return 0;
60 }
61
63 {
65
67 // av_assert1(!buf->line[line]);
69 return buf->line[
line];
70
71 buffer = buf->data_stack[buf->data_stack_top];
72 buf->data_stack_top--;
74
76 }
77
79 {
81
84
86 buf->data_stack_top++;
87 buf->data_stack[buf->data_stack_top] =
buffer;
89 }
90
92 {
94
95 if (!buf->line)
96 return;
97
98 for (
i = 0;
i < buf->line_count;
i++)
101 }
102
104 {
107
108 if (buf->data_stack)
109 for (
i = buf->data_count - 1;
i >= 0;
i--)
113 }
114
116 int dst_step, int src_step, int ref_step,
119 {
124
125 #define LIFT(src, ref, inv) ((src) + ((inv) ? -(ref) : +(ref)))
126 if (mirror_left) {
128 dst += dst_step;
130 }
131
132 for (
i = 0;
i <
w;
i++)
133 dst[
i * dst_step] =
LIFT(
src[
i * src_step],
134 ((mul * (
ref[
i * ref_step] +
135 ref[(
i + 1) * ref_step]) +
138
139 if (mirror_right)
140 dst[
w * dst_step] =
LIFT(
src[
w * src_step],
141 ((mul * 2 *
ref[
w * ref_step] + add) >>
shift),
143 }
144
146 int dst_step, int src_step, int ref_step,
149 {
154
156 #define LIFTS(src, ref, inv) \
157 ((inv) ? (src) + (((ref) + 4 * (src)) >> shift) \
158 : -((-16 * (src) + (ref) + add / \
159 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23)))
160 if (mirror_left) {
162 dst += dst_step;
164 }
165
166 for (
i = 0;
i <
w;
i++)
168 mul * (
ref[
i * ref_step] +
169 ref[(
i + 1) * ref_step]) + add,
171
172 if (mirror_right)
174 mul * 2 *
ref[
w * ref_step] + add,
176 }
177
179 {
180 const int width2 =
width >> 1;
181 int x;
182 const int w2 = (
width + 1) >> 1;
183
184 for (x = 0; x < width2; x++) {
186 temp[x + w2] =
b[2 * x + 1];
187 }
190 lift(
b + w2,
temp + w2,
temp, 1, 1, 1,
width, -1, 0, 1, 1, 0);
191 lift(
b,
temp,
b + w2, 1, 1, 1,
width, 1, 2, 2, 0, 0);
192 }
193
196 {
198
201 }
202
205 {
207
210 }
211
214 {
215 int y;
218
219 for (y = -2; y <
height; y += 2) {
222
223 if (y + 1 < (
unsigned)
height)
225 if (y + 2 < (
unsigned)
height)
227
228 if (y + 1 < (
unsigned)
height)
230 if (y + 0 < (
unsigned)
height)
232
235 }
236 }
237
239 {
240 const int w2 = (
width + 1) >> 1;
241
242 lift(
temp + w2,
b + 1,
b, 1, 2, 2,
width,
W_AM,
W_AO,
W_AS, 1, 1);
243 liftS(
temp,
b,
temp + w2, 1, 2, 1,
width,
W_BM,
W_BO,
W_BS, 0, 0);
244 lift(
b + w2,
temp + w2,
temp, 1, 1, 1,
width,
W_CM,
W_CO,
W_CS, 1, 0);
245 lift(
b,
temp,
b + w2, 1, 1, 1,
width,
W_DM,
W_DO,
W_DS, 0, 0);
246 }
247
250 {
252
255 }
256
259 {
261
264 }
265
268 {
270
273 (5 * 16) - (1 << 23);
274 }
275
278 {
280
283 }
284
287 {
288 int y;
293
294 for (y = -4; y <
height; y += 2) {
297
298 if (y + 3 < (
unsigned)
height)
300 if (y + 4 < (
unsigned)
height)
302
303 if (y + 3 < (
unsigned)
height)
305 if (y + 2 < (
unsigned)
height)
307 if (y + 1 < (
unsigned)
height)
309 if (y + 0 < (
unsigned)
height)
311
316 }
317 }
318
320 int stride,
int type,
int decomposition_count)
321 {
323
330 break;
335 break;
336 }
337 }
338 }
339
341 {
342 const int width2 =
width >> 1;
343 const int w2 = (
width + 1) >> 1;
344 int x;
345
346 for (x = 0; x < width2; x++) {
348 temp[2 * x + 1] =
b[x + w2];
349 }
352
354 for (x = 2; x <
width - 1; x += 2) {
356 b[x - 1] =
temp[x - 1] + ((
b[x - 2] +
b[x] + 1) >> 1);
357 }
359 b[x] =
temp[x] - ((
temp[x - 1] + 1) >> 1);
360 b[x - 1] =
temp[x - 1] + ((
b[x - 2] +
b[x] + 1) >> 1);
361 } else
362 b[x - 1] =
temp[x - 1] +
b[x - 2];
363 }
364
367 {
369
372 }
373
376 {
378
381 }
382
384 int height,
int stride_line)
385 {
390 }
391
394 {
398 }
399
403 int stride_line)
404 {
406
411 stride_line);
414 stride_line);
415
417 int x;
418
419 for (x = 0; x <
width; x++) {
420 b2[x] -= (
b1[x] +
b3[x] + 2) >> 2;
421 b1[x] += (
b0[x] +
b2[x]) >> 1;
422 }
423 } else {
424 if (y + 1 < (
unsigned)
height)
426 if (y + 0 < (
unsigned)
height)
428 }
429
430 if (y - 1 < (
unsigned)
height)
432 if (y + 0 < (
unsigned)
height)
434
438 }
439
443 {
449
450 if (y + 1 < (
unsigned)
height)
452 if (y + 0 < (
unsigned)
height)
454
455 if (y - 1 < (
unsigned)
height)
457 if (y + 0 < (
unsigned)
height)
459
463 }
464
466 {
467 const int w2 = (
width + 1) >> 1;
468 int x;
469
470 temp[0] =
b[0] - ((3 *
b[w2] + 2) >> 2);
471 for (x = 1; x < (
width >> 1); x++) {
472 temp[2 * x] =
b[x] - ((3 * (
b[x + w2 - 1] +
b[x + w2]) + 4) >> 3);
473 temp[2 * x - 1] =
b[x + w2 - 1] -
temp[2 * x - 2] -
temp[2 * x];
474 }
476 temp[2 * x] =
b[x] - ((3 *
b[x + w2 - 1] + 2) >> 2);
477 temp[2 * x - 1] =
b[x + w2 - 1] -
temp[2 * x - 2] -
temp[2 * x];
478 } else
479 temp[2 * x - 1] =
b[x + w2 - 1] - 2 *
temp[2 * x - 2];
480
482 for (x = 2; x <
width - 1; x += 2) {
484 b[x - 1] =
temp[x - 1] + ((3 * (
b[x - 2] +
b[x])) >> 1);
485 }
488 b[x - 1] =
temp[x - 1] + ((3 * (
b[x - 2] +
b[x])) >> 1);
489 } else
490 b[x - 1] =
temp[x - 1] + 3 *
b[x - 2];
491 }
492
495 {
497
500 }
501
504 {
506
509 }
510
513 {
515
518 }
519
522 {
524
527 }
528
532 {
534
540 }
541 }
542
544 int height,
int stride_line)
545 {
551 }
552
555 {
561 }
562
566 int stride_line)
567 {
569
576 stride_line);
579 stride_line);
580
581 if (y > 0 && y + 4 <
height) {
583 } else {
584 if (y + 3 < (
unsigned)
height)
586 if (y + 2 < (
unsigned)
height)
588 if (y + 1 < (
unsigned)
height)
590 if (y + 0 < (
unsigned)
height)
592 }
593
594 if (y - 1 < (
unsigned)
height)
596 if (y + 0 < (
unsigned)
height)
598
604 }
605
609 {
617
618 if (y + 3 < (
unsigned)
height)
620 if (y + 2 < (
unsigned)
height)
622 if (y + 1 < (
unsigned)
height)
624 if (y + 0 < (
unsigned)
height)
626
627 if (y - 1 < (
unsigned)
height)
629 if (y + 0 < (
unsigned)
height)
631
637 }
638
641 int decomposition_count)
642 {
648 stride_line <<
level);
649 break;
652 stride_line <<
level);
653 break;
654 }
655 }
656 }
657
661 int type,
int decomposition_count,
int y)
662 {
663 const int support =
type == 1 ? 3 : 5;
666 return;
667
675 stride_line <<
level);
676 break;
681 stride_line <<
level);
682 break;
683 }
684 }
685 }
686
689 int decomposition_count)
690 {
697 break;
701 break;
702 }
703 }
704 }
705
709 int decomposition_count, int y)
710 {
711 const int support =
type == 1 ? 3 : 5;
714 return;
715
722 break;
726 break;
727 }
728 }
729 }
730
732 int stride,
int type,
int decomposition_count)
733 {
735 int y;
737 decomposition_count);
738 for (y = 0; y <
height; y += 4)
740 decomposition_count, y);
741 }
742
743 static inline int w_c(
struct MpegEncContext *v,
const uint8_t *pix1,
const uint8_t *pix2, ptrdiff_t line_size,
745 {
747 const int dec_count =
w == 8 ? 3 : 4;
748 int tmp[32 * 32], tmp2[32];
750 static const int scale[2][2][4][4] = {
751 {
752 { // 9/7 8x8 dec=3
753 { 268, 239, 239, 213 },
754 { 0, 224, 224, 152 },
755 { 0, 135, 135, 110 },
756 },
757 { // 9/7 16x16 or 32x32 dec=4
758 { 344, 310, 310, 280 },
759 { 0, 320, 320, 228 },
760 { 0, 175, 175, 136 },
761 { 0, 129, 129, 102 },
762 }
763 },
764 {
765 { // 5/3 8x8 dec=3
766 { 275, 245, 245, 218 },
767 { 0, 230, 230, 156 },
768 { 0, 138, 138, 113 },
769 },
770 { // 5/3 16x16 or 32x32 dec=4
771 { 352, 317, 317, 286 },
772 { 0, 328, 328, 233 },
773 { 0, 180, 180, 140 },
774 { 0, 132, 132, 105 },
775 }
776 }
777 };
778
779 for (
i = 0;
i <
h;
i++) {
780 for (j = 0; j <
w; j += 4) {
781 tmp[32 *
i + j + 0] = (pix1[j + 0] - pix2[j + 0]) * (1 << 4);
782 tmp[32 *
i + j + 1] = (pix1[j + 1] - pix2[j + 1]) * (1 << 4);
783 tmp[32 *
i + j + 2] = (pix1[j + 2] - pix2[j + 2]) * (1 << 4);
784 tmp[32 *
i + j + 3] = (pix1[j + 3] - pix2[j + 3]) * (1 << 4);
785 }
786 pix1 += line_size;
787 pix2 += line_size;
788 }
789
791
795 for (ori =
level ? 1 : 0; ori < 4; ori++) {
797 int sx = (ori & 1) ?
size : 0;
799 int sy = (ori & 2) ?
stride >> 1 : 0;
800
802 for (j = 0; j <
size; j++) {
806 }
807 }
810 }
811
813 {
814 return w_c(v, pix1, pix2, line_size, 8,
h, 1);
815 }
816
818 {
819 return w_c(v, pix1, pix2, line_size, 8,
h, 0);
820 }
821
823 {
824 return w_c(v, pix1, pix2, line_size, 16,
h, 1);
825 }
826
828 {
829 return w_c(v, pix1, pix2, line_size, 16,
h, 0);
830 }
831
833 {
834 return w_c(v, pix1, pix2, line_size, 32,
h, 1);
835 }
836
838 {
839 return w_c(v, pix1, pix2, line_size, 32,
h, 0);
840 }
841
843 {
848 }
849
851 {
855
856 #if ARCH_X86 && HAVE_MMX
858 #endif
859 }
860
861