GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/simple_idct.c Lines: 96 101 95.0 %
Date: 2021-04-14 23:45:22 Branches: 26 30 86.7 %

Line Branch Exec Source
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
28
#include "libavutil/intreadwrite.h"
29
#include "avcodec.h"
30
#include "mathops.h"
31
#include "simple_idct.h"
32
33
#define IN_IDCT_DEPTH 16
34
35
#define BIT_DEPTH 8
36
#include "simple_idct_template.c"
37
#undef BIT_DEPTH
38
39
#define BIT_DEPTH 10
40
#include "simple_idct_template.c"
41
42
#define EXTRA_SHIFT  2
43
#include "simple_idct_template.c"
44
45
#undef EXTRA_SHIFT
46
#undef BIT_DEPTH
47
48
#define BIT_DEPTH 12
49
#include "simple_idct_template.c"
50
#undef BIT_DEPTH
51
#undef IN_IDCT_DEPTH
52
53
#define IN_IDCT_DEPTH 32
54
#define BIT_DEPTH 10
55
#include "simple_idct_template.c"
56
#undef BIT_DEPTH
57
#undef IN_IDCT_DEPTH
58
59
/* 2x4x8 idct */
60
61
#define CN_SHIFT 12
62
#define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
63
#define C1 C_FIX(0.6532814824)
64
#define C2 C_FIX(0.2705980501)
65
66
/* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
67
   and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
68
#define C_SHIFT (4+1+12)
69
70
441216
static inline void idct4col_put(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
71
{
72
    int c0, c1, c2, c3, a0, a1, a2, a3;
73
74
441216
    a0 = col[8*0];
75
441216
    a1 = col[8*2];
76
441216
    a2 = col[8*4];
77
441216
    a3 = col[8*6];
78
441216
    c0 = ((a0 + a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
79
441216
    c2 = ((a0 - a2) * (1 << CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
80
441216
    c1 = a1 * C1 + a3 * C2;
81
441216
    c3 = a1 * C2 - a3 * C1;
82
441216
    dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT);
83
441216
    dest += line_size;
84
441216
    dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT);
85
441216
    dest += line_size;
86
441216
    dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT);
87
441216
    dest += line_size;
88
441216
    dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT);
89
441216
}
90
91
#define BF(k) \
92
{\
93
    int a0, a1;\
94
    a0 = ptr[k];\
95
    a1 = ptr[8 + k];\
96
    ptr[k] = a0 + a1;\
97
    ptr[8 + k] = a0 - a1;\
98
}
99
100
/* only used by DV codec. The input must be interlaced. 128 is added
101
   to the pixels before clamping to avoid systematic error
102
   (1024*sqrt(2)) offset would be needed otherwise. */
103
/* XXX: I think a 1.0/sqrt(2) normalization should be needed to
104
   compensate the extra butterfly stage - I don't have the full DV
105
   specification */
106
27576
void ff_simple_idct248_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
107
{
108
    int i;
109
    int16_t *ptr;
110
111
    /* butterfly */
112
27576
    ptr = block;
113
137880
    for(i=0;i<4;i++) {
114
110304
        BF(0);
115
110304
        BF(1);
116
110304
        BF(2);
117
110304
        BF(3);
118
110304
        BF(4);
119
110304
        BF(5);
120
110304
        BF(6);
121
110304
        BF(7);
122
110304
        ptr += 2 * 8;
123
    }
124
125
    /* IDCT8 on each line */
126
248184
    for(i=0; i<8; i++) {
127
220608
        idctRowCondDC_int16_8bit(block + i*8, 0);
128
    }
129
130
    /* IDCT4 and store */
131
248184
    for(i=0;i<8;i++) {
132
220608
        idct4col_put(dest + i, 2 * line_size, block + i);
133
220608
        idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i);
134
    }
135
27576
}
136
137
/* 8x4 & 4x8 WMV2 IDCT */
138
#undef CN_SHIFT
139
#undef C_SHIFT
140
#undef C_FIX
141
#undef C1
142
#undef C2
143
#define CN_SHIFT 12
144
#define C_FIX(x) ((int)((x) * M_SQRT2 * (1 << CN_SHIFT) + 0.5))
145
#define C1 C_FIX(0.6532814824)
146
#define C2 C_FIX(0.2705980501)
147
#define C3 C_FIX(0.5)
148
#define C_SHIFT (4+1+12)
149
263504
static inline void idct4col_add(uint8_t *dest, ptrdiff_t line_size, const int16_t *col)
150
{
151
    int c0, c1, c2, c3, a0, a1, a2, a3;
152
153
263504
    a0 = col[8*0];
154
263504
    a1 = col[8*1];
155
263504
    a2 = col[8*2];
156
263504
    a3 = col[8*3];
157
263504
    c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
158
263504
    c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
159
263504
    c1 = a1 * C1 + a3 * C2;
160
263504
    c3 = a1 * C2 - a3 * C1;
161
263504
    dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));
162
263504
    dest += line_size;
163
263504
    dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));
164
263504
    dest += line_size;
165
263504
    dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));
166
263504
    dest += line_size;
167
263504
    dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));
168
263504
}
169
170
#define RN_SHIFT 15
171
#define R_FIX(x) ((int)((x) * M_SQRT2 * (1 << RN_SHIFT) + 0.5))
172
#define R1 R_FIX(0.6532814824)
173
#define R2 R_FIX(0.2705980501)
174
#define R3 R_FIX(0.5)
175
#define R_SHIFT 11
176
239648
static inline void idct4row(int16_t *row)
177
{
178
    unsigned c0, c1, c2, c3;
179
    int a0, a1, a2, a3;
180
181
239648
    a0 = row[0];
182
239648
    a1 = row[1];
183
239648
    a2 = row[2];
184
239648
    a3 = row[3];
185
239648
    c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
186
239648
    c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
187
239648
    c1 = a1 * R1 + a3 * R2;
188
239648
    c3 = a1 * R2 - a3 * R1;
189
239648
    row[0]= (c0 + c1) >> R_SHIFT;
190
239648
    row[1]= (c2 + c3) >> R_SHIFT;
191
239648
    row[2]= (c2 - c3) >> R_SHIFT;
192
239648
    row[3]= (c0 - c1) >> R_SHIFT;
193
239648
}
194
195
32938
void ff_simple_idct84_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
196
{
197
    int i;
198
199
    /* IDCT8 on each line */
200
164690
    for(i=0; i<4; i++) {
201
131752
        idctRowCondDC_int16_8bit(block + i*8, 0);
202
    }
203
204
    /* IDCT4 and store */
205
296442
    for(i=0;i<8;i++) {
206
263504
        idct4col_add(dest + i, line_size, block + i);
207
    }
208
32938
}
209
210
29956
void ff_simple_idct48_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
211
{
212
    int i;
213
214
    /* IDCT4 on each line */
215
269604
    for(i=0; i<8; i++) {
216
239648
        idct4row(block + i*8);
217
    }
218
219
    /* IDCT8 and store */
220
149780
    for(i=0; i<4; i++){
221
119824
        idctSparseColAdd_int16_8bit(dest + i, line_size, block + i);
222
    }
223
29956
}
224
225
void ff_simple_idct44_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
226
{
227
    int i;
228
229
    /* IDCT4 on each line */
230
    for(i=0; i<4; i++) {
231
        idct4row(block + i*8);
232
    }
233
234
    /* IDCT4 and store */
235
    for(i=0; i<4; i++){
236
        idct4col_add(dest + i, line_size, block + i);
237
    }
238
}
239
240
2682912
void ff_prores_idct_10(int16_t *block, const int16_t *qmat)
241
{
242
    int i;
243
244
174389280
    for (i = 0; i < 64; i++)
245
171706368
        block[i] *= qmat[i];
246
247
24146208
    for (i = 0; i < 8; i++)
248
21463296
        idctRowCondDC_extrashift_10(block + i*8, 2);
249
250
24146208
    for (i = 0; i < 8; i++) {
251
21463296
        block[i] += 8192;
252
21463296
        idctSparseCol_extrashift_10(block + i);
253
    }
254
2682912
}
255
256
2446164
void ff_prores_idct_12(int16_t *block, const int16_t *qmat)
257
{
258
    int i;
259
260
159000660
    for (i = 0; i < 64; i++)
261
156554496
        block[i] *= qmat[i];
262
263
22015476
    for (i = 0; i < 8; i++)
264
19569312
        idctRowCondDC_int16_12bit(block + i*8, 0);
265
266
22015476
    for (i = 0; i < 8; i++) {
267
19569312
        block[i] += 8192;
268
19569312
        idctSparseCol_int16_12bit(block + i);
269
    }
270
2446164
}