40 uint16_t *frame_prev[3];
44 void (*denoise_row[17])(
uint8_t *src,
uint8_t *
dst, uint16_t *line_ant, uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial, int16_t *temporal);
52 #define LUT_BITS (depth==16 ? 8 : 4)
53 #define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
54 + (((1 << (16 - depth)) - 1) >> 1))
55 #define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
56 AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
59 static uint32_t
lowpass(
int prev,
int cur, int16_t *coef,
int depth)
61 int d = (prev - cur) >> (8 -
LUT_BITS);
68 int w,
int h,
int sstride,
int dstride,
69 int16_t *temporal,
int depth)
76 for (y = 0; y < h; y++) {
77 for (x = 0; x < w; x++) {
78 frame_ant[x] = tmp =
lowpass(frame_ant[x],
LOAD(x), temporal, depth);
90 uint16_t *line_ant, uint16_t *frame_ant,
91 int w,
int h,
int sstride,
int dstride,
92 int16_t *spatial, int16_t *temporal,
int depth)
104 for (x = 0; x < w; x++) {
105 line_ant[x] = tmp = pixel_ant =
lowpass(pixel_ant,
LOAD(x), spatial, depth);
106 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
110 for (y = 1; y < h; y++) {
119 for (x = 0; x < w-1; x++) {
120 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
121 pixel_ant =
lowpass(pixel_ant,
LOAD(x+1), spatial, depth);
122 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
125 line_ant[x] = tmp =
lowpass(line_ant[x], pixel_ant, spatial, depth);
126 frame_ant[x] = tmp =
lowpass(frame_ant[x], tmp, temporal, depth);
134 uint16_t *line_ant, uint16_t **frame_ant_ptr,
135 int w,
int h,
int sstride,
int dstride,
136 int16_t *spatial, int16_t *temporal,
int depth)
141 uint16_t *frame_ant = *frame_ant_ptr;
144 *frame_ant_ptr = frame_ant =
av_malloc(w*h*
sizeof(uint16_t));
145 for (y = 0; y < h; y++, src += sstride, frame_ant += w)
146 for (x = 0; x < w; x++)
147 frame_ant[x] =
LOAD(x);
149 frame_ant = *frame_ant_ptr;
154 w, h, sstride, dstride, spatial, temporal, depth);
157 w, h, sstride, dstride, temporal, depth);
160 #define denoise(...) \
161 switch (hqdn3d->depth) {\
162 case 8: denoise_depth(__VA_ARGS__, 8); break;\
163 case 9: denoise_depth(__VA_ARGS__, 9); break;\
164 case 10: denoise_depth(__VA_ARGS__, 10); break;\
165 case 16: denoise_depth(__VA_ARGS__, 16); break;\
171 double gamma, simil,
C;
176 gamma = log(0.25) / log(1.0 -
FFMIN(dist25,252.0)/255.0 - 0.00001);
180 simil = 1.0 -
FFABS(f) / 255.0;
181 C = pow(simil, gamma) * 256.0 * f;
189 #define PARAM1_DEFAULT 4.0
190 #define PARAM2_DEFAULT 3.0
191 #define PARAM3_DEFAULT 6.0
196 double lum_spac, lum_tmp, chrom_spac, chrom_tmp;
197 double param1, param2, param3, param4;
202 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
205 switch (sscanf(args,
"%lf:%lf:%lf:%lf",
206 ¶m1, ¶m2, ¶m3, ¶m4)) {
211 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
217 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
223 chrom_tmp = lum_tmp * chrom_spac / lum_spac;
240 lum_spac, chrom_spac, lum_tmp, chrom_tmp);
241 if (lum_spac < 0 || chrom_spac < 0 ||
isnan(chrom_tmp)) {
243 "Invalid negative value for luma or chroma spatial strength, "
244 "or resulting value for chroma temporal strength is nan.\n");
309 for (i = 0; i < 4; i++) {
311 if (!hqdn3d->
coefs[i])
346 for (c = 0; c < 3; c++) {
389 .
inputs = avfilter_vf_hqdn3d_inputs,
391 .
outputs = avfilter_vf_hqdn3d_outputs,