Coverage Report

Created: 2025-08-28 07:12

/src/ffmpeg/libavcodec/faanidct.c
Line
Count
Source
1
/*
2
 * Floating point AAN IDCT
3
 * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
#include "faanidct.h"
22
#include "libavutil/common.h"
23
#include "libavutil/emms.h"
24
25
/* To allow switching to double. */
26
typedef float FLOAT;
27
28
#define B0 1.0000000000000000000000
29
#define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2)
30
196M
#define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2)
31
#define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2)
32
#define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2)
33
#define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2)
34
196M
#define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2)
35
#define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2)
36
37
392M
#define A4 0.70710678118654752438 // cos(pi*4/16)
38
784M
#define A2 0.92387953251128675613 // cos(pi*2/16)
39
40
static const FLOAT prescale[64]={
41
B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8,
42
B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8,
43
B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8,
44
B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8,
45
B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8,
46
B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8,
47
B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8,
48
B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8,
49
};
50
51
static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest,
52
                          ptrdiff_t stride, int x, int y, int type)
53
24.5M
{
54
24.5M
    int i;
55
24.5M
    FLOAT s04, d04, s17, d17, s26, d26, s53, d53;
56
24.5M
    FLOAT os07, os16, os25, os34;
57
24.5M
    FLOAT od07, od16, od25, od34;
58
59
220M
    for(i=0; i<y*8; i+=y){
60
196M
        s17= temp[1*x + i] + temp[7*x + i];
61
196M
        d17= temp[1*x + i] - temp[7*x + i];
62
196M
        s53= temp[5*x + i] + temp[3*x + i];
63
196M
        d53= temp[5*x + i] - temp[3*x + i];
64
65
196M
        od07=  s17 + s53;
66
196M
        od25= (s17 - s53)*(2*A4);
67
68
196M
        od34=  d17*(2*(B6-A2)) - d53*(2*A2);
69
196M
        od16=  d53*(2*(A2-B2)) + d17*(2*A2);
70
71
196M
        od16 -= od07;
72
196M
        od25 -= od16;
73
196M
        od34 += od25;
74
75
196M
        s26 = temp[2*x + i] + temp[6*x + i];
76
196M
        d26 = temp[2*x + i] - temp[6*x + i];
77
196M
        d26*= 2*A4;
78
196M
        d26-= s26;
79
80
196M
        s04= temp[0*x + i] + temp[4*x + i];
81
196M
        d04= temp[0*x + i] - temp[4*x + i];
82
83
196M
        os07= s04 + s26;
84
196M
        os34= s04 - s26;
85
196M
        os16= d04 + d26;
86
196M
        os25= d04 - d26;
87
88
196M
        if(type==0){
89
98.0M
            temp[0*x + i]= os07 + od07;
90
98.0M
            temp[7*x + i]= os07 - od07;
91
98.0M
            temp[1*x + i]= os16 + od16;
92
98.0M
            temp[6*x + i]= os16 - od16;
93
98.0M
            temp[2*x + i]= os25 + od25;
94
98.0M
            temp[5*x + i]= os25 - od25;
95
98.0M
            temp[3*x + i]= os34 - od34;
96
98.0M
            temp[4*x + i]= os34 + od34;
97
98.0M
        }else if(type==1){
98
186k
            data[0*x + i]= lrintf(os07 + od07);
99
186k
            data[7*x + i]= lrintf(os07 - od07);
100
186k
            data[1*x + i]= lrintf(os16 + od16);
101
186k
            data[6*x + i]= lrintf(os16 - od16);
102
186k
            data[2*x + i]= lrintf(os25 + od25);
103
186k
            data[5*x + i]= lrintf(os25 - od25);
104
186k
            data[3*x + i]= lrintf(os34 - od34);
105
186k
            data[4*x + i]= lrintf(os34 + od34);
106
97.8M
        }else if(type==2){
107
7.50M
            dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));
108
7.50M
            dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));
109
7.50M
            dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));
110
7.50M
            dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));
111
7.50M
            dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));
112
7.50M
            dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));
113
7.50M
            dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));
114
7.50M
            dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));
115
90.3M
        }else{
116
90.3M
            dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));
117
90.3M
            dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));
118
90.3M
            dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));
119
90.3M
            dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));
120
90.3M
            dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));
121
90.3M
            dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));
122
90.3M
            dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));
123
90.3M
            dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));
124
90.3M
        }
125
196M
    }
126
24.5M
}
127
128
23.3k
void ff_faanidct(int16_t block[64]){
129
23.3k
    FLOAT temp[64];
130
23.3k
    int i;
131
132
23.3k
    emms_c();
133
134
1.51M
    for(i=0; i<64; i++)
135
1.49M
        temp[i] = block[i] * prescale[i];
136
137
23.3k
    p8idct(block, temp, NULL, 0, 1, 8, 0);
138
23.3k
    p8idct(block, temp, NULL, 0, 8, 1, 1);
139
23.3k
}
140
141
void ff_faanidct_add(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
142
937k
{
143
937k
    FLOAT temp[64];
144
937k
    int i;
145
146
937k
    emms_c();
147
148
60.9M
    for(i=0; i<64; i++)
149
60.0M
        temp[i] = block[i] * prescale[i];
150
151
937k
    p8idct(block, temp, NULL,         0, 1, 8, 0);
152
937k
    p8idct(NULL , temp, dest, line_size, 8, 1, 2);
153
937k
}
154
155
void ff_faanidct_put(uint8_t *dest, ptrdiff_t line_size, int16_t block[64])
156
11.2M
{
157
11.2M
    FLOAT temp[64];
158
11.2M
    int i;
159
160
11.2M
    emms_c();
161
162
734M
    for(i=0; i<64; i++)
163
722M
        temp[i] = block[i] * prescale[i];
164
165
11.2M
    p8idct(block, temp, NULL,         0, 1, 8, 0);
166
11.2M
    p8idct(NULL , temp, dest, line_size, 8, 1, 3);
167
11.2M
}