FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wmv2dsp.c
Go to the documentation of this file.
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 "libavutil/attributes.h"
20 #include "libavutil/common.h"
21 #include "avcodec.h"
22 #include "dsputil.h"
23 #include "wmv2dsp.h"
24 
25 #define W0 2048
26 #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
27 #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
28 #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
29 #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
30 #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
31 #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
32 #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
33 
34 static void wmv2_idct_row(short * b)
35 {
36  int s1, s2;
37  int a0, a1, a2, a3, a4, a5, a6, a7;
38 
39  /* step 1 */
40  a1 = W1 * b[1] + W7 * b[7];
41  a7 = W7 * b[1] - W1 * b[7];
42  a5 = W5 * b[5] + W3 * b[3];
43  a3 = W3 * b[5] - W5 * b[3];
44  a2 = W2 * b[2] + W6 * b[6];
45  a6 = W6 * b[2] - W2 * b[6];
46  a0 = W0 * b[0] + W0 * b[4];
47  a4 = W0 * b[0] - W0 * b[4];
48 
49  /* step 2 */
50  s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8; // 1, 3, 5, 7
51  s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
52 
53  /* step 3 */
54  b[0] = (a0 + a2 + a1 + a5 + (1 << 7)) >> 8;
55  b[1] = (a4 + a6 + s1 + (1 << 7)) >> 8;
56  b[2] = (a4 - a6 + s2 + (1 << 7)) >> 8;
57  b[3] = (a0 - a2 + a7 + a3 + (1 << 7)) >> 8;
58  b[4] = (a0 - a2 - a7 - a3 + (1 << 7)) >> 8;
59  b[5] = (a4 - a6 - s2 + (1 << 7)) >> 8;
60  b[6] = (a4 + a6 - s1 + (1 << 7)) >> 8;
61  b[7] = (a0 + a2 - a1 - a5 + (1 << 7)) >> 8;
62 }
63 
64 static void wmv2_idct_col(short * b)
65 {
66  int s1, s2;
67  int a0, a1, a2, a3, a4, a5, a6, a7;
68 
69  /* step 1, with extended precision */
70  a1 = (W1 * b[8 * 1] + W7 * b[8 * 7] + 4) >> 3;
71  a7 = (W7 * b[8 * 1] - W1 * b[8 * 7] + 4) >> 3;
72  a5 = (W5 * b[8 * 5] + W3 * b[8 * 3] + 4) >> 3;
73  a3 = (W3 * b[8 * 5] - W5 * b[8 * 3] + 4) >> 3;
74  a2 = (W2 * b[8 * 2] + W6 * b[8 * 6] + 4) >> 3;
75  a6 = (W6 * b[8 * 2] - W2 * b[8 * 6] + 4) >> 3;
76  a0 = (W0 * b[8 * 0] + W0 * b[8 * 4] ) >> 3;
77  a4 = (W0 * b[8 * 0] - W0 * b[8 * 4] ) >> 3;
78 
79  /* step 2 */
80  s1 = (181 * (a1 - a5 + a7 - a3) + 128) >> 8;
81  s2 = (181 * (a1 - a5 - a7 + a3) + 128) >> 8;
82 
83  /* step 3 */
84  b[8 * 0] = (a0 + a2 + a1 + a5 + (1 << 13)) >> 14;
85  b[8 * 1] = (a4 + a6 + s1 + (1 << 13)) >> 14;
86  b[8 * 2] = (a4 - a6 + s2 + (1 << 13)) >> 14;
87  b[8 * 3] = (a0 - a2 + a7 + a3 + (1 << 13)) >> 14;
88 
89  b[8 * 4] = (a0 - a2 - a7 - a3 + (1 << 13)) >> 14;
90  b[8 * 5] = (a4 - a6 - s2 + (1 << 13)) >> 14;
91  b[8 * 6] = (a4 + a6 - s1 + (1 << 13)) >> 14;
92  b[8 * 7] = (a0 + a2 - a1 - a5 + (1 << 13)) >> 14;
93 }
94 
95 static void wmv2_idct_add_c(uint8_t *dest, int line_size, int16_t *block)
96 {
97  int i;
98 
99  for (i = 0; i < 64; i += 8)
100  wmv2_idct_row(block + i);
101  for (i = 0; i < 8; i++)
102  wmv2_idct_col(block + i);
103 
104  for (i = 0; i < 8; i++) {
105  dest[0] = av_clip_uint8(dest[0] + block[0]);
106  dest[1] = av_clip_uint8(dest[1] + block[1]);
107  dest[2] = av_clip_uint8(dest[2] + block[2]);
108  dest[3] = av_clip_uint8(dest[3] + block[3]);
109  dest[4] = av_clip_uint8(dest[4] + block[4]);
110  dest[5] = av_clip_uint8(dest[5] + block[5]);
111  dest[6] = av_clip_uint8(dest[6] + block[6]);
112  dest[7] = av_clip_uint8(dest[7] + block[7]);
113  dest += line_size;
114  block += 8;
115  }
116 }
117 
118 static void wmv2_idct_put_c(uint8_t *dest, int line_size, int16_t *block)
119 {
120  int i;
121 
122  for (i = 0; i < 64; i += 8)
123  wmv2_idct_row(block + i);
124  for (i = 0; i < 8; i++)
125  wmv2_idct_col(block + i);
126 
127  for (i = 0; i < 8; i++) {
128  dest[0] = av_clip_uint8(block[0]);
129  dest[1] = av_clip_uint8(block[1]);
130  dest[2] = av_clip_uint8(block[2]);
131  dest[3] = av_clip_uint8(block[3]);
132  dest[4] = av_clip_uint8(block[4]);
133  dest[5] = av_clip_uint8(block[5]);
134  dest[6] = av_clip_uint8(block[6]);
135  dest[7] = av_clip_uint8(block[7]);
136  dest += line_size;
137  block += 8;
138  }
139 }
140 
142 {
146 }