idct: Only build prores IDCT if ProRes decoder is enabled
[libav.git] / libavcodec / simple_idct.c
CommitLineData
37e8dcda 1/*
ff4ec49e
FB
2 * Simple IDCT
3 *
4 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
5 *
2912e87a 6 * This file is part of Libav.
b78e7197 7 *
2912e87a 8 * Libav is free software; you can redistribute it and/or
ff4ec49e
FB
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
b78e7197 11 * version 2.1 of the License, or (at your option) any later version.
ff4ec49e 12 *
2912e87a 13 * Libav is distributed in the hope that it will be useful,
ff4ec49e
FB
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
2912e87a 19 * License along with Libav; if not, write to the Free Software
5509bffa 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ff4ec49e 21 */
115329f1 22
983e3246 23/**
ba87f080 24 * @file
983e3246
MN
25 * simpleidct in C.
26 */
115329f1 27
3e9409b1 28#include "libavutil/intreadwrite.h"
6000abfa 29#include "avcodec.h"
edf7c2b2 30#include "mathops.h"
37e8dcda
A
31#include "simple_idct.h"
32
e7a972e1
MR
33#define BIT_DEPTH 8
34#include "simple_idct_template.c"
35#undef BIT_DEPTH
37e8dcda 36
e7a972e1
MR
37#define BIT_DEPTH 10
38#include "simple_idct_template.c"
39#undef BIT_DEPTH
86748dbc 40
9bf71516
FB
41/* 2x4x8 idct */
42
43#define CN_SHIFT 12
44#define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
652f0197
FB
45#define C1 C_FIX(0.6532814824)
46#define C2 C_FIX(0.2705980501)
9bf71516 47
652f0197
FB
48/* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
49 and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
50#define C_SHIFT (4+1+12)
9bf71516 51
88bd7fdc 52static inline void idct4col_put(uint8_t *dest, int line_size, const int16_t *col)
9bf71516
FB
53{
54 int c0, c1, c2, c3, a0, a1, a2, a3;
9bf71516
FB
55
56 a0 = col[8*0];
57 a1 = col[8*2];
58 a2 = col[8*4];
59 a3 = col[8*6];
652f0197
FB
60 c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
61 c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
9bf71516
FB
62 c1 = a1 * C1 + a3 * C2;
63 c3 = a1 * C2 - a3 * C1;
c23acbae 64 dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT);
9bf71516 65 dest += line_size;
c23acbae 66 dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT);
9bf71516 67 dest += line_size;
c23acbae 68 dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT);
9bf71516 69 dest += line_size;
c23acbae 70 dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT);
9bf71516
FB
71}
72
73#define BF(k) \
74{\
75 int a0, a1;\
76 a0 = ptr[k];\
77 a1 = ptr[8 + k];\
78 ptr[k] = a0 + a1;\
79 ptr[8 + k] = a0 - a1;\
80}
81
82/* only used by DV codec. The input must be interlaced. 128 is added
83 to the pixels before clamping to avoid systematic error
84 (1024*sqrt(2)) offset would be needed otherwise. */
85/* XXX: I think a 1.0/sqrt(2) normalization should be needed to
86 compensate the extra butterfly stage - I don't have the full DV
87 specification */
88bd7fdc 88void ff_simple_idct248_put(uint8_t *dest, int line_size, int16_t *block)
9bf71516
FB
89{
90 int i;
88bd7fdc 91 int16_t *ptr;
115329f1 92
9bf71516
FB
93 /* butterfly */
94 ptr = block;
95 for(i=0;i<4;i++) {
96 BF(0);
97 BF(1);
98 BF(2);
99 BF(3);
100 BF(4);
101 BF(5);
102 BF(6);
103 BF(7);
104 ptr += 2 * 8;
105 }
106
107 /* IDCT8 on each line */
108 for(i=0; i<8; i++) {
f78cd0c2 109 idctRowCondDC_8(block + i*8, 0);
9bf71516
FB
110 }
111
112 /* IDCT4 and store */
113 for(i=0;i<8;i++) {
fda767bb
KS
114 idct4col_put(dest + i, 2 * line_size, block + i);
115 idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i);
9bf71516
FB
116 }
117}
1457ab52
MN
118
119/* 8x4 & 4x8 WMV2 IDCT */
120#undef CN_SHIFT
121#undef C_SHIFT
122#undef C_FIX
123#undef C1
124#undef C2
125#define CN_SHIFT 12
126#define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5))
127#define C1 C_FIX(0.6532814824)
128#define C2 C_FIX(0.2705980501)
129#define C3 C_FIX(0.5)
130#define C_SHIFT (4+1+12)
88bd7fdc 131static inline void idct4col_add(uint8_t *dest, int line_size, const int16_t *col)
1457ab52
MN
132{
133 int c0, c1, c2, c3, a0, a1, a2, a3;
1457ab52
MN
134
135 a0 = col[8*0];
136 a1 = col[8*1];
137 a2 = col[8*2];
138 a3 = col[8*3];
139 c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
140 c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
141 c1 = a1 * C1 + a3 * C2;
142 c3 = a1 * C2 - a3 * C1;
c23acbae 143 dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));
1457ab52 144 dest += line_size;
c23acbae 145 dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));
1457ab52 146 dest += line_size;
c23acbae 147 dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));
1457ab52 148 dest += line_size;
c23acbae 149 dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));
1457ab52
MN
150}
151
152#define RN_SHIFT 15
153#define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5))
154#define R1 R_FIX(0.6532814824)
155#define R2 R_FIX(0.2705980501)
156#define R3 R_FIX(0.5)
157#define R_SHIFT 11
88bd7fdc 158static inline void idct4row(int16_t *row)
1457ab52
MN
159{
160 int c0, c1, c2, c3, a0, a1, a2, a3;
1457ab52
MN
161
162 a0 = row[0];
163 a1 = row[1];
164 a2 = row[2];
165 a3 = row[3];
166 c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
167 c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
168 c1 = a1 * R1 + a3 * R2;
169 c3 = a1 * R2 - a3 * R1;
170 row[0]= (c0 + c1) >> R_SHIFT;
171 row[1]= (c2 + c3) >> R_SHIFT;
172 row[2]= (c2 - c3) >> R_SHIFT;
173 row[3]= (c0 - c1) >> R_SHIFT;
174}
175
88bd7fdc 176void ff_simple_idct84_add(uint8_t *dest, int line_size, int16_t *block)
1457ab52
MN
177{
178 int i;
179
180 /* IDCT8 on each line */
181 for(i=0; i<4; i++) {
f78cd0c2 182 idctRowCondDC_8(block + i*8, 0);
1457ab52
MN
183 }
184
185 /* IDCT4 and store */
186 for(i=0;i<8;i++) {
187 idct4col_add(dest + i, line_size, block + i);
188 }
189}
190
88bd7fdc 191void ff_simple_idct48_add(uint8_t *dest, int line_size, int16_t *block)
1457ab52
MN
192{
193 int i;
194
195 /* IDCT4 on each line */
196 for(i=0; i<8; i++) {
197 idct4row(block + i*8);
198 }
199
200 /* IDCT8 and store */
201 for(i=0; i<4; i++){
e7a972e1 202 idctSparseColAdd_8(dest + i, line_size, block + i);
1457ab52
MN
203 }
204}
205
88bd7fdc 206void ff_simple_idct44_add(uint8_t *dest, int line_size, int16_t *block)
91823a6e
KS
207{
208 int i;
209
210 /* IDCT4 on each line */
211 for(i=0; i<4; i++) {
212 idct4row(block + i*8);
213 }
214
215 /* IDCT4 and store */
216 for(i=0; i<4; i++){
217 idct4col_add(dest + i, line_size, block + i);
218 }
219}
92fb52d9 220
d6e49096 221#if CONFIG_PRORES_DECODER
88bd7fdc 222void ff_prores_idct(int16_t *block, const int16_t *qmat)
92fb52d9
RB
223{
224 int i;
225
226 for (i = 0; i < 64; i++)
227 block[i] *= qmat[i];
228
229 for (i = 0; i < 8; i++)
f78cd0c2 230 idctRowCondDC_10(block + i*8, 2);
92fb52d9
RB
231
232 for (i = 0; i < 8; i++)
233 idctSparseCol_10(block + i);
234}
d6e49096 235#endif /* CONFIG_PRORES_DECODER */