FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/wavelet97.c
Date: 2026-11-06 00:28:10
Exec Total Coverage
Lines: 74 74 100.0%
Functions: 10 10 100.0%
Branches: 28 28 100.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
3 * Copyright (c) 2013 Clément Bœsch <u pkh me>
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
22 #include "libavutil/internal.h"
23 #include "libavutil/mathematics.h"
24 #include "wavelet97.h"
25
26 const double ff_wavelet97_coeff[2][5] = {
27 {
28 0.6029490182363579 * M_SQRT2,
29 0.2668641184428723 * M_SQRT2,
30 -0.07822326652898785 * M_SQRT2,
31 -0.01686411844287495 * M_SQRT2,
32 0.02674875741080976 * M_SQRT2,
33 },{
34 1.115087052456994 / M_SQRT2,
35 -0.5912717631142470 / M_SQRT2,
36 -0.05754352622849957 / M_SQRT2,
37 0.09127176311424948 / M_SQRT2,
38 }
39 };
40
41 static const double icoeff[2][5] = {
42 {
43 1.115087052456994 / M_SQRT2,
44 0.5912717631142470 / M_SQRT2,
45 -0.05754352622849957 / M_SQRT2,
46 -0.09127176311424948 / M_SQRT2,
47 },{
48 0.6029490182363579 * M_SQRT2,
49 -0.2668641184428723 * M_SQRT2,
50 -0.07822326652898785 * M_SQRT2,
51 0.01686411844287495 * M_SQRT2,
52 0.02674875741080976 * M_SQRT2,
53 }
54 };
55
56 702400 static inline void decompose(float *dst_l, float *dst_h, const float *src,
57 const double coeff[2][5], int linesize, int w)
58 {
59 int x, i;
60
2/2
✓ Branch 0 taken 17208000 times.
✓ Branch 1 taken 702400 times.
17910400 for (x = 0; x < w; x++) {
61 17208000 double sum_l = src[x * linesize] * coeff[0][0];
62 17208000 double sum_h = src[x * linesize] * coeff[1][0];
63
2/2
✓ Branch 0 taken 68832000 times.
✓ Branch 1 taken 17208000 times.
86040000 for (i = 1; i <= 4; i++) {
64 68832000 const double s = src[avpriv_mirror(x - i, w - 1) * linesize]
65 68832000 + src[avpriv_mirror(x + i, w - 1) * linesize];
66
67 68832000 sum_l += coeff[0][i] * s;
68 68832000 sum_h += coeff[1][i] * s;
69 }
70 17208000 dst_l[x * linesize] = sum_l;
71 17208000 dst_h[x * linesize] = sum_h;
72 }
73 702400 }
74
75 518400 static inline void compose(float *dst, const float *src_l, const float *src_h,
76 int linesize, int w)
77 {
78 int x, i;
79
2/2
✓ Branch 0 taken 10908000 times.
✓ Branch 1 taken 518400 times.
11426400 for (x = 0; x < w; x++) {
80 10908000 double sum_l = src_l[x * linesize] * icoeff[0][0];
81 10908000 double sum_h = src_h[x * linesize] * icoeff[1][0];
82
2/2
✓ Branch 0 taken 43632000 times.
✓ Branch 1 taken 10908000 times.
54540000 for (i = 1; i <= 4; i++) {
83 43632000 const int x0 = avpriv_mirror(x - i, w - 1) * linesize;
84 43632000 const int x1 = avpriv_mirror(x + i, w - 1) * linesize;
85
86 43632000 sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
87 43632000 sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
88 }
89 10908000 dst[x * linesize] = (sum_l + sum_h) * 0.5;
90 }
91 518400 }
92
93 19100 static inline void decompose_decimated(float *dst, const float *src,
94 const double coeff[2][5], int stride, int n)
95 {
96 int x, i;
97
2/2
✓ Branch 0 taken 2396820 times.
✓ Branch 1 taken 19100 times.
2415920 for (x = 0; x < n; x++) {
98 2396820 const double *c = coeff[x & 1];
99 2396820 double sum = src[x * stride] * c[0];
100
2/2
✓ Branch 0 taken 9587280 times.
✓ Branch 1 taken 2396820 times.
11984100 for (i = 1; i <= 4; i++)
101 9587280 sum += c[i] * (src[avpriv_mirror(x - i, n - 1) * stride]
102 9587280 + src[avpriv_mirror(x + i, n - 1) * stride]);
103 2396820 dst[x * stride] = sum;
104 }
105 19100 }
106
107 9550 static inline void compose_decimated(float *dst, const float *src,
108 int stride, int n)
109 {
110 int x, i;
111
2/2
✓ Branch 0 taken 1198410 times.
✓ Branch 1 taken 9550 times.
1207960 for (x = 0; x < n; x++) {
112 1198410 double sum = src[x * stride] * icoeff[x & 1][0];
113
2/2
✓ Branch 0 taken 4793640 times.
✓ Branch 1 taken 1198410 times.
5992050 for (i = 1; i <= 4; i++)
114 4793640 sum += icoeff[(x + i) & 1][i] * (src[avpriv_mirror(x - i, n - 1) * stride]
115 4793640 + src[avpriv_mirror(x + i, n - 1) * stride]);
116 1198410 dst[x * stride] = sum;
117 }
118 9550 }
119
120 3624 void ff_wavelet97_decompose_lines(float *dst_l, float *dst_h, const float *src,
121 const double coeff[2][5],
122 int xlinesize, int ylinesize,
123 int step, int w, int line0, int line1)
124 {
125 int y, x;
126
2/2
✓ Branch 0 taken 94880 times.
✓ Branch 1 taken 3624 times.
98504 for (y = line0; y < line1; y++)
127
2/2
✓ Branch 0 taken 702400 times.
✓ Branch 1 taken 94880 times.
797280 for (x = 0; x < step; x++)
128 702400 decompose(dst_l + ylinesize*y + xlinesize*x,
129 702400 dst_h + ylinesize*y + xlinesize*x,
130 702400 src + ylinesize*y + xlinesize*x,
131 702400 coeff, step * xlinesize, (w - x + step - 1) / step);
132 3624 }
133
134 1869 void ff_wavelet97_compose_lines(float *dst, const float *src_l, const float *src_h,
135 int xlinesize, int ylinesize,
136 int step, int w, int line0, int line1)
137 {
138 int y, x;
139
2/2
✓ Branch 0 taken 58880 times.
✓ Branch 1 taken 1869 times.
60749 for (y = line0; y < line1; y++)
140
2/2
✓ Branch 0 taken 518400 times.
✓ Branch 1 taken 58880 times.
577280 for (x = 0; x < step; x++)
141 518400 compose(dst + ylinesize*y + xlinesize*x,
142 518400 src_l + ylinesize*y + xlinesize*x,
143 518400 src_h + ylinesize*y + xlinesize*x,
144 518400 step * xlinesize, (w - x + step - 1) / step);
145 1869 }
146
147 2340 void ff_wavelet97_decompose_decimated_lines(float *dst, const float *src,
148 const double coeff[2][5],
149 int xstride, int ystride,
150 int len, int line0, int line1)
151 {
152
2/2
✓ Branch 0 taken 19100 times.
✓ Branch 1 taken 2340 times.
21440 for (int y = line0; y < line1; y++)
153 19100 decompose_decimated(dst + ystride*y, src + ystride*y, coeff, xstride, len);
154 2340 }
155
156 1170 void ff_wavelet97_compose_decimated_lines(float *dst, const float *src,
157 int xstride, int ystride,
158 int len, int line0, int line1)
159 {
160
2/2
✓ Branch 0 taken 9550 times.
✓ Branch 1 taken 1170 times.
10720 for (int y = line0; y < line1; y++)
161 9550 compose_decimated(dst + ystride*y, src + ystride*y, xstride, len);
162 1170 }
163
164 38 void ff_wavelet97_decompose(float *dst[4], const float *src, float *temp[2],
165 const double coeff[2][5],
166 int linesize, int step, int w, int h)
167 {
168 38 ff_wavelet97_decompose_lines(temp[0], temp[1], src, coeff, 1, linesize, step, w, 0, h);
169 38 ff_wavelet97_decompose_lines( dst[0], dst[1], temp[0], coeff, linesize, 1, step, h, 0, w);
170 38 ff_wavelet97_decompose_lines( dst[2], dst[3], temp[1], coeff, linesize, 1, step, h, 0, w);
171 38 }
172
173 38 void ff_wavelet97_compose(float *dst, float *const src[4], float *temp[2],
174 int linesize, int step, int w, int h)
175 {
176 38 ff_wavelet97_compose_lines(temp[0], src[0], src[1], linesize, 1, step, h, 0, w);
177 38 ff_wavelet97_compose_lines(temp[1], src[2], src[3], linesize, 1, step, h, 0, w);
178 38 ff_wavelet97_compose_lines(dst, temp[0], temp[1], 1, linesize, step, w, 0, h);
179 38 }
180