1 /*
2 * Simple IDCT
3 *
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * simpleidct in C.
26 */
27
31
32 #define IN_IDCT_DEPTH 16
33
34 #define BIT_DEPTH 8
36 #undef BIT_DEPTH
37
38 #define BIT_DEPTH 10
40 #undef BIT_DEPTH
41
42 #define BIT_DEPTH 12
44 #undef BIT_DEPTH
45 #undef IN_IDCT_DEPTH
46
47 #define IN_IDCT_DEPTH 32
50 #undef BIT_DEPTH
51 #undef IN_IDCT_DEPTH
52
53 /* 2x4x8 idct */
54
55 #define CN_SHIFT 12
56 #define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
57 #define C1 C_FIX(0.6532814824)
58 #define C2 C_FIX(0.2705980501)
59
60 /* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
61 and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
62 #define C_SHIFT (4+1+12)
63
64 static inline void idct4col_put(uint8_t *dest, ptrdiff_t line_size,
const int16_t *col)
65 {
67
77 dest += line_size;
79 dest += line_size;
81 dest += line_size;
83 }
84
86 {\
87 int a0, a1;\
88 a0 = ptr[k];\
89 a1 = ptr[8 + k];\
90 ptr[k] = a0 + a1;\
91 ptr[8 + k] = a0 - a1;\
92 }
93
94 /* only used by DV codec. The input must be interlaced. 128 is added
95 to the pixels before clamping to avoid systematic error
96 (1024*sqrt(2)) offset would be needed otherwise. */
97 /* XXX: I think a 1.0/sqrt(2) normalization should be needed to
98 compensate the extra butterfly stage - I don't have the full DV
99 specification */
101 {
103 int16_t *ptr;
104
105 /* butterfly */
116 ptr += 2 * 8;
117 }
118
119 /* IDCT8 on each line */
121 idctRowCondDC_int16_8bit(
block +
i*8, 0);
122 }
123
124 /* IDCT4 and store */
128 }
129 }
130
131 /* 8x4 & 4x8 WMV2 IDCT */
132 #undef CN_SHIFT
133 #undef C_SHIFT
134 #undef C_FIX
135 #undef C1
136 #undef C2
138 #define C_FIX(x) ((int)((x) * M_SQRT2 * (1 << CN_SHIFT) + 0.5))
139 #define C1 C_FIX(0.6532814824)
140 #define C2 C_FIX(0.2705980501)
141 #define C3 C_FIX(0.5)
142 #define C_SHIFT (4+1+12)
143 static inline void idct4col_add(uint8_t *dest, ptrdiff_t line_size,
const int16_t *col)
144 {
146
156 dest += line_size;
158 dest += line_size;
160 dest += line_size;
162 }
163
165 #define R_FIX(x) ((int)((x) * M_SQRT2 * (1 << RN_SHIFT) + 0.5))
166 #define R1 R_FIX(0.6532814824)
167 #define R2 R_FIX(0.2705980501)
168 #define R3 R_FIX(0.5)
171 {
172 unsigned c0,
c1,
c2, c3;
174
187 }
188
190 {
192
193 /* IDCT8 on each line */
195 idctRowCondDC_int16_8bit(
block +
i*8, 0);
196 }
197
198 /* IDCT4 and store */
201 }
202 }
203
205 {
207
208 /* IDCT4 on each line */
211 }
212
213 /* IDCT8 and store */
215 idctSparseColAdd_int16_8bit(dest +
i, line_size,
block +
i);
216 }
217 }
218
220 {
222
223 /* IDCT4 on each line */
226 }
227
228 /* IDCT4 and store */
231 }
232 }