... | ... |
@@ -1216,7 +1216,6 @@ image noise producing smooth images and making still images really |
1216 | 1216 |
still. It should enhance compressibility. |
1217 | 1217 |
|
1218 | 1218 |
It accepts the following optional parameters: |
1219 |
-@var{luma_spatial}:@var{chroma_spatial}:@var{luma_tmp}:@var{chroma_tmp} |
|
1220 | 1219 |
|
1221 | 1220 |
@table @option |
1222 | 1221 |
@item luma_spatial |
... | ... |
@@ -26,10 +26,14 @@ |
26 | 26 |
* libmpcodecs/vf_hqdn3d.c. |
27 | 27 |
*/ |
28 | 28 |
|
29 |
+#include <float.h> |
|
30 |
+ |
|
29 | 31 |
#include "config.h" |
30 | 32 |
#include "libavutil/common.h" |
31 | 33 |
#include "libavutil/pixdesc.h" |
32 | 34 |
#include "libavutil/intreadwrite.h" |
35 |
+#include "libavutil/opt.h" |
|
36 |
+ |
|
33 | 37 |
#include "avfilter.h" |
34 | 38 |
#include "formats.h" |
35 | 39 |
#include "internal.h" |
... | ... |
@@ -180,57 +184,19 @@ static int16_t *precalc_coefs(double dist25, int depth) |
180 | 180 |
static int init(AVFilterContext *ctx, const char *args) |
181 | 181 |
{ |
182 | 182 |
HQDN3DContext *hqdn3d = ctx->priv; |
183 |
- double lum_spac, lum_tmp, chrom_spac, chrom_tmp; |
|
184 |
- double param1, param2, param3, param4; |
|
185 |
- |
|
186 |
- lum_spac = PARAM1_DEFAULT; |
|
187 |
- chrom_spac = PARAM2_DEFAULT; |
|
188 |
- lum_tmp = PARAM3_DEFAULT; |
|
189 |
- chrom_tmp = lum_tmp * chrom_spac / lum_spac; |
|
190 |
- |
|
191 |
- if (args) { |
|
192 |
- switch (sscanf(args, "%lf:%lf:%lf:%lf", |
|
193 |
- ¶m1, ¶m2, ¶m3, ¶m4)) { |
|
194 |
- case 1: |
|
195 |
- lum_spac = param1; |
|
196 |
- chrom_spac = PARAM2_DEFAULT * param1 / PARAM1_DEFAULT; |
|
197 |
- lum_tmp = PARAM3_DEFAULT * param1 / PARAM1_DEFAULT; |
|
198 |
- chrom_tmp = lum_tmp * chrom_spac / lum_spac; |
|
199 |
- break; |
|
200 |
- case 2: |
|
201 |
- lum_spac = param1; |
|
202 |
- chrom_spac = param2; |
|
203 |
- lum_tmp = PARAM3_DEFAULT * param1 / PARAM1_DEFAULT; |
|
204 |
- chrom_tmp = lum_tmp * chrom_spac / lum_spac; |
|
205 |
- break; |
|
206 |
- case 3: |
|
207 |
- lum_spac = param1; |
|
208 |
- chrom_spac = param2; |
|
209 |
- lum_tmp = param3; |
|
210 |
- chrom_tmp = lum_tmp * chrom_spac / lum_spac; |
|
211 |
- break; |
|
212 |
- case 4: |
|
213 |
- lum_spac = param1; |
|
214 |
- chrom_spac = param2; |
|
215 |
- lum_tmp = param3; |
|
216 |
- chrom_tmp = param4; |
|
217 |
- break; |
|
218 |
- } |
|
219 |
- } |
|
220 | 183 |
|
221 |
- hqdn3d->strength[0] = lum_spac; |
|
222 |
- hqdn3d->strength[1] = lum_tmp; |
|
223 |
- hqdn3d->strength[2] = chrom_spac; |
|
224 |
- hqdn3d->strength[3] = chrom_tmp; |
|
184 |
+ if (!hqdn3d->strength[LUMA_SPATIAL]) |
|
185 |
+ hqdn3d->strength[LUMA_SPATIAL] = PARAM1_DEFAULT; |
|
186 |
+ if (!hqdn3d->strength[CHROMA_SPATIAL]) |
|
187 |
+ hqdn3d->strength[CHROMA_SPATIAL] = PARAM2_DEFAULT * hqdn3d->strength[LUMA_SPATIAL] / PARAM1_DEFAULT; |
|
188 |
+ if (!hqdn3d->strength[LUMA_TMP]) |
|
189 |
+ hqdn3d->strength[LUMA_TMP] = PARAM3_DEFAULT * hqdn3d->strength[LUMA_SPATIAL] / PARAM1_DEFAULT; |
|
190 |
+ if (!hqdn3d->strength[CHROMA_TMP]) |
|
191 |
+ hqdn3d->strength[CHROMA_TMP] = hqdn3d->strength[LUMA_TMP] * hqdn3d->strength[CHROMA_SPATIAL] / hqdn3d->strength[LUMA_SPATIAL]; |
|
225 | 192 |
|
226 | 193 |
av_log(ctx, AV_LOG_VERBOSE, "ls:%f cs:%f lt:%f ct:%f\n", |
227 |
- lum_spac, chrom_spac, lum_tmp, chrom_tmp); |
|
228 |
- if (lum_spac < 0 || chrom_spac < 0 || isnan(chrom_tmp)) { |
|
229 |
- av_log(ctx, AV_LOG_ERROR, |
|
230 |
- "Invalid negative value for luma or chroma spatial strength, " |
|
231 |
- "or resulting value for chroma temporal strength is nan.\n"); |
|
232 |
- return AVERROR(EINVAL); |
|
233 |
- } |
|
194 |
+ hqdn3d->strength[LUMA_SPATIAL], hqdn3d->strength[CHROMA_SPATIAL], |
|
195 |
+ hqdn3d->strength[LUMA_TMP], hqdn3d->strength[CHROMA_TMP]); |
|
234 | 196 |
|
235 | 197 |
return 0; |
236 | 198 |
} |
... | ... |
@@ -343,6 +309,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
343 | 343 |
return ff_filter_frame(outlink, out); |
344 | 344 |
} |
345 | 345 |
|
346 |
+#define OFFSET(x) offsetof(HQDN3DContext, x) |
|
347 |
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM |
|
348 |
+static const AVOption options[] = { |
|
349 |
+ { "luma_spatial", "spatial luma strength", OFFSET(strength[LUMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS }, |
|
350 |
+ { "chroma_spatial", "spatial chroma strength", OFFSET(strength[CHROMA_SPATIAL]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS }, |
|
351 |
+ { "luma_tmp", "temporal luma strength", OFFSET(strength[LUMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS }, |
|
352 |
+ { "chroma_tmp", "temporal chroma strength", OFFSET(strength[CHROMA_TMP]), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0, DBL_MAX, FLAGS }, |
|
353 |
+ { NULL }, |
|
354 |
+}; |
|
355 |
+ |
|
356 |
+static const AVClass hqdn3d_class = { |
|
357 |
+ .class_name = "hqdn3d", |
|
358 |
+ .item_name = av_default_item_name, |
|
359 |
+ .option = options, |
|
360 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
361 |
+}; |
|
362 |
+ |
|
346 | 363 |
static const AVFilterPad avfilter_vf_hqdn3d_inputs[] = { |
347 | 364 |
{ |
348 | 365 |
.name = "default", |
... | ... |
@@ -366,6 +349,7 @@ AVFilter avfilter_vf_hqdn3d = { |
366 | 366 |
.description = NULL_IF_CONFIG_SMALL("Apply a High Quality 3D Denoiser."), |
367 | 367 |
|
368 | 368 |
.priv_size = sizeof(HQDN3DContext), |
369 |
+ .priv_class = &hqdn3d_class, |
|
369 | 370 |
.init = init, |
370 | 371 |
.uninit = uninit, |
371 | 372 |
.query_formats = query_formats, |
... | ... |
@@ -22,7 +22,10 @@ |
22 | 22 |
#include <stddef.h> |
23 | 23 |
#include <stdint.h> |
24 | 24 |
|
25 |
+#include "libavutil/opt.h" |
|
26 |
+ |
|
25 | 27 |
typedef struct { |
28 |
+ const AVClass *class; |
|
26 | 29 |
int16_t *coefs[4]; |
27 | 30 |
uint16_t *line; |
28 | 31 |
uint16_t *frame_prev[3]; |
... | ... |
@@ -32,6 +35,11 @@ typedef struct { |
32 | 32 |
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); |
33 | 33 |
} HQDN3DContext; |
34 | 34 |
|
35 |
+#define LUMA_SPATIAL 0 |
|
36 |
+#define LUMA_TMP 1 |
|
37 |
+#define CHROMA_SPATIAL 2 |
|
38 |
+#define CHROMA_TMP 3 |
|
39 |
+ |
|
35 | 40 |
void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d); |
36 | 41 |
|
37 | 42 |
#endif /* AVFILTER_VF_HQDN3D_H */ |