FFmpeg
Loading...
Searching...
No Matches
wavelet97.c
Go to the documentation of this file.
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"
24#include "wavelet97.h"
25
26const 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
41static 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
56static 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 for (x = 0; x < w; x++) {
61 double sum_l = src[x * linesize] * coeff[0][0];
62 double sum_h = src[x * linesize] * coeff[1][0];
63 for (i = 1; i <= 4; i++) {
64 const double s = src[avpriv_mirror(x - i, w - 1) * linesize]
65 + src[avpriv_mirror(x + i, w - 1) * linesize];
66
67 sum_l += coeff[0][i] * s;
68 sum_h += coeff[1][i] * s;
69 }
70 dst_l[x * linesize] = sum_l;
71 dst_h[x * linesize] = sum_h;
72 }
73}
74
75static inline void compose(float *dst, const float *src_l, const float *src_h,
76 int linesize, int w)
77{
78 int x, i;
79 for (x = 0; x < w; x++) {
80 double sum_l = src_l[x * linesize] * icoeff[0][0];
81 double sum_h = src_h[x * linesize] * icoeff[1][0];
82 for (i = 1; i <= 4; i++) {
83 const int x0 = avpriv_mirror(x - i, w - 1) * linesize;
84 const int x1 = avpriv_mirror(x + i, w - 1) * linesize;
85
86 sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
87 sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
88 }
89 dst[x * linesize] = (sum_l + sum_h) * 0.5;
90 }
91}
92
93static 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 for (x = 0; x < n; x++) {
98 const double *c = coeff[x & 1];
99 double sum = src[x * stride] * c[0];
100 for (i = 1; i <= 4; i++)
101 sum += c[i] * (src[avpriv_mirror(x - i, n - 1) * stride]
102 + src[avpriv_mirror(x + i, n - 1) * stride]);
103 dst[x * stride] = sum;
104 }
105}
106
107static inline void compose_decimated(float *dst, const float *src,
108 int stride, int n)
109{
110 int x, i;
111 for (x = 0; x < n; x++) {
112 double sum = src[x * stride] * icoeff[x & 1][0];
113 for (i = 1; i <= 4; i++)
114 sum += icoeff[(x + i) & 1][i] * (src[avpriv_mirror(x - i, n - 1) * stride]
115 + src[avpriv_mirror(x + i, n - 1) * stride]);
116 dst[x * stride] = sum;
117 }
118}
119
120void 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 for (y = line0; y < line1; y++)
127 for (x = 0; x < step; x++)
128 decompose(dst_l + ylinesize*y + xlinesize*x,
129 dst_h + ylinesize*y + xlinesize*x,
130 src + ylinesize*y + xlinesize*x,
131 coeff, step * xlinesize, (w - x + step - 1) / step);
132}
133
134void 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 for (y = line0; y < line1; y++)
140 for (x = 0; x < step; x++)
141 compose(dst + ylinesize*y + xlinesize*x,
142 src_l + ylinesize*y + xlinesize*x,
143 src_h + ylinesize*y + xlinesize*x,
144 step * xlinesize, (w - x + step - 1) / step);
145}
146
148 const double coeff[2][5],
149 int xstride, int ystride,
150 int len, int line0, int line1)
151{
152 for (int y = line0; y < line1; y++)
153 decompose_decimated(dst + ystride*y, src + ystride*y, coeff, xstride, len);
154}
155
157 int xstride, int ystride,
158 int len, int line0, int line1)
159{
160 for (int y = line0; y < line1; y++)
161 compose_decimated(dst + ystride*y, src + ystride*y, xstride, len);
162}
163
164void 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 ff_wavelet97_decompose_lines(temp[0], temp[1], src, coeff, 1, linesize, step, w, 0, h);
169 ff_wavelet97_decompose_lines( dst[0], dst[1], temp[0], coeff, linesize, 1, step, h, 0, w);
170 ff_wavelet97_decompose_lines( dst[2], dst[3], temp[1], coeff, linesize, 1, step, h, 0, w);
171}
172
173void ff_wavelet97_compose(float *dst, float *const src[4], float *temp[2],
174 int linesize, int step, int w, int h)
175{
176 ff_wavelet97_compose_lines(temp[0], src[0], src[1], linesize, 1, step, h, 0, w);
177 ff_wavelet97_compose_lines(temp[1], src[2], src[3], linesize, 1, step, h, 0, w);
178 ff_wavelet97_compose_lines(dst, temp[0], temp[1], 1, linesize, step, w, 0, h);
179}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
common internal API header
static av_always_inline av_const int avpriv_mirror(int x, int w)
Definition internal.h:143
uint8_t w
Definition llvidencdsp.c:39
#define M_SQRT2
#define stride
#define src
Definition vp8dsp.c:248
else temp
Definition vf_mcdeint.c:275
int len
static double c[64]
static void compose_decimated(float *dst, const float *src, int stride, int n)
Definition wavelet97.c:107
void ff_wavelet97_decompose_decimated_lines(float *dst, const float *src, const double coeff[2][5], int xstride, int ystride, int len, int line0, int line1)
Decimated analysis of lines line0..line1-1 along one direction.
Definition wavelet97.c:147
void ff_wavelet97_decompose_lines(float *dst_l, float *dst_h, const float *src, const double coeff[2][5], int xlinesize, int ylinesize, int step, int w, int line0, int line1)
Undecimated analysis of lines line0..line1-1 along one direction.
Definition wavelet97.c:120
void ff_wavelet97_compose_lines(float *dst, const float *src_l, const float *src_h, int xlinesize, int ylinesize, int step, int w, int line0, int line1)
Inverse of ff_wavelet97_decompose_lines() with ff_wavelet97_coeff.
Definition wavelet97.c:134
const double ff_wavelet97_coeff[2][5]
Undecimated 9/7 wavelet transform.
Definition wavelet97.c:26
static void decompose(float *dst_l, float *dst_h, const float *src, const double coeff[2][5], int linesize, int w)
Definition wavelet97.c:56
static void decompose_decimated(float *dst, const float *src, const double coeff[2][5], int stride, int n)
Definition wavelet97.c:93
static void compose(float *dst, const float *src_l, const float *src_h, int linesize, int w)
Definition wavelet97.c:75
static const double icoeff[2][5]
Definition wavelet97.c:41
void ff_wavelet97_decompose(float *dst[4], const float *src, float *temp[2], const double coeff[2][5], int linesize, int step, int w, int h)
One level of undecimated 2D analysis, filters are mirrored at the plane borders.
Definition wavelet97.c:164
void ff_wavelet97_compose_decimated_lines(float *dst, const float *src, int xstride, int ystride, int len, int line0, int line1)
Inverse of ff_wavelet97_decompose_decimated_lines() with ff_wavelet97_coeff.
Definition wavelet97.c:156
void ff_wavelet97_compose(float *dst, float *const src[4], float *temp[2], int linesize, int step, int w, int h)
One level of 2D synthesis, the inverse of ff_wavelet97_decompose() with ff_wavelet97_coeff.
Definition wavelet97.c:173