4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of Libav.
8 * Libav 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.
13 * Libav 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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "libavutil/intreadwrite.h"
32 #include "simple_idct.h"
35 #include "simple_idct_template.c"
39 #include "simple_idct_template.c"
45 #define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
46 #define C1 C_FIX(0.6532814824)
47 #define C2 C_FIX(0.2705980501)
49 /* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
50 and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
51 #define C_SHIFT (4+1+12)
53 static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col)
55 int c0, c1, c2, c3, a0, a1, a2, a3;
56 const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
62 c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
63 c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
64 c1 = a1 * C1 + a3 * C2;
65 c3 = a1 * C2 - a3 * C1;
66 dest[0] = cm[(c0 + c1) >> C_SHIFT];
68 dest[0] = cm[(c2 + c3) >> C_SHIFT];
70 dest[0] = cm[(c2 - c3) >> C_SHIFT];
72 dest[0] = cm[(c0 - c1) >> C_SHIFT];
81 ptr[8 + k] = a0 - a1;\
84 /* only used by DV codec. The input must be interlaced. 128 is added
85 to the pixels before clamping to avoid systematic error
86 (1024*sqrt(2)) offset would be needed otherwise. */
87 /* XXX: I think a 1.0/sqrt(2) normalization should be needed to
88 compensate the extra butterfly stage - I don't have the full DV
90 void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
109 /* IDCT8 on each line */
111 idctRowCondDC_8(block + i*8, 0);
114 /* IDCT4 and store */
116 idct4col_put(dest + i, 2 * line_size, block + i);
117 idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i);
121 /* 8x4 & 4x8 WMV2 IDCT */
128 #define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5))
129 #define C1 C_FIX(0.6532814824)
130 #define C2 C_FIX(0.2705980501)
131 #define C3 C_FIX(0.5)
132 #define C_SHIFT (4+1+12)
133 static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
135 int c0, c1, c2, c3, a0, a1, a2, a3;
136 const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
142 c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
143 c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
144 c1 = a1 * C1 + a3 * C2;
145 c3 = a1 * C2 - a3 * C1;
146 dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)];
148 dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)];
150 dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)];
152 dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)];
156 #define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5))
157 #define R1 R_FIX(0.6532814824)
158 #define R2 R_FIX(0.2705980501)
159 #define R3 R_FIX(0.5)
161 static inline void idct4row(DCTELEM *row)
163 int c0, c1, c2, c3, a0, a1, a2, a3;
164 //const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
170 c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
171 c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
172 c1 = a1 * R1 + a3 * R2;
173 c3 = a1 * R2 - a3 * R1;
174 row[0]= (c0 + c1) >> R_SHIFT;
175 row[1]= (c2 + c3) >> R_SHIFT;
176 row[2]= (c2 - c3) >> R_SHIFT;
177 row[3]= (c0 - c1) >> R_SHIFT;
180 void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
184 /* IDCT8 on each line */
186 idctRowCondDC_8(block + i*8, 0);
189 /* IDCT4 and store */
191 idct4col_add(dest + i, line_size, block + i);
195 void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
199 /* IDCT4 on each line */
201 idct4row(block + i*8);
204 /* IDCT8 and store */
206 idctSparseColAdd_8(dest + i, line_size, block + i);
210 void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block)
214 /* IDCT4 on each line */
216 idct4row(block + i*8);
219 /* IDCT4 and store */
221 idct4col_add(dest + i, line_size, block + i);
225 void ff_prores_idct(DCTELEM *block, const int16_t *qmat)
229 for (i = 0; i < 64; i++)
232 for (i = 0; i < 8; i++)
233 idctRowCondDC_10(block + i*8, 2);
235 for (i = 0; i < 8; i++)
236 idctSparseCol_10(block + i);