39 #define LUT_BITS (depth==16 ? 8 : 4)
40 #define LOAD(x) (((depth==8 ? src[x] : AV_RN16A(src+(x)*2)) << (16-depth)) + (((1<<(16-depth))-1)>>1))
41 #define STORE(x,val) (depth==8 ? dst[x] = (val) >> (16-depth)\
42 : AV_WN16A(dst+(x)*2, (val) >> (16-depth)))
45 static uint32_t
lowpass(
int prev,
int cur, int16_t *coef,
int depth)
47 int d = (prev - cur) >> (8 -
LUT_BITS);
54 int w,
int h,
int sstride,
int dstride,
55 int16_t *temporal,
int depth)
62 for (y = 0; y < h; y++) {
63 for (x = 0; x < w; x++) {
64 frame_ant[x] = tmp =
lowpass(frame_ant[x],
LOAD(x), temporal, depth);
76 uint16_t *line_ant, uint16_t *frame_ant,
77 int w,
int h,
int sstride,
int dstride,
78 int16_t *spatial, int16_t *temporal,
int depth)
90 for (x = 0; x < w; x++) {
91 line_ant[x] = tmp = pixel_ant =
lowpass(pixel_ant,
LOAD(x), spatial, depth);
92 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
96 for (y = 1; y < h; y++) {
105 for (x = 0; x < w-1; x++) {
106 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
107 pixel_ant =
lowpass(pixel_ant,
LOAD(x+1), spatial, depth);
108 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
111 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
112 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
120 uint16_t *line_ant, uint16_t **frame_ant_ptr,
121 int w,
int h,
int sstride,
int dstride,
122 int16_t *spatial, int16_t *temporal,
int depth)
127 uint16_t *frame_ant = *frame_ant_ptr;
130 *frame_ant_ptr = frame_ant =
av_malloc(w*h*
sizeof(uint16_t));
131 for (y = 0; y < h; y++, src += sstride, frame_ant += w)
132 for (x = 0; x < w; x++)
133 frame_ant[x] =
LOAD(x);
135 frame_ant = *frame_ant_ptr;
140 w, h, sstride, dstride, spatial, temporal, depth);
143 w, h, sstride, dstride, temporal, depth);
146 #define denoise(...) \
147 switch (hqdn3d->depth) {\
148 case 8: denoise_depth(__VA_ARGS__, 8); break;\
149 case 9: denoise_depth(__VA_ARGS__, 9); break;\
150 case 10: denoise_depth(__VA_ARGS__, 10); break;\
151 case 16: denoise_depth(__VA_ARGS__, 16); break;\
157 double gamma, simil,
C;
162 gamma = log(0.25) / log(1.0 -
FFMIN(dist25,252.0)/255.0 - 0.00001);
166 simil = 1.0 -
FFABS(f) / 255.0;
167 C = pow(simil, gamma) * 256.0 * f;
175 #define PARAM1_DEFAULT 4.0
176 #define PARAM2_DEFAULT 3.0
177 #define PARAM3_DEFAULT 6.0
182 double lum_spac, lum_tmp, chrom_spac, chrom_tmp;
183 double param1, param2, param3, param4;
188 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
191 switch (sscanf(args,
"%lf:%lf:%lf:%lf",
192 ¶m1, ¶m2, ¶m3, ¶m4)) {
197 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
203 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
209 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
226 lum_spac, chrom_spac, lum_tmp, chrom_tmp);
227 if (lum_spac < 0 || chrom_spac < 0 ||
isnan(chrom_tmp)) {
229 "Invalid negative value for luma or chroma spatial strength, "
230 "or resulting value for chroma temporal strength is nan.\n");
295 for (i = 0; i < 4; i++) {
297 if (!hqdn3d->
coefs[i])
327 for (
c = 0;
c < 3;
c++) {
370 .
inputs = avfilter_vf_hqdn3d_inputs,
372 .
outputs = avfilter_vf_hqdn3d_outputs,