History

avfilter/vf_lumakey: change options to doubles, so that values are automatically scaled

Paul B Mahol committed 6 years ago

Commit 6b9862f1 parent 08f79681 file · +15 −12Browse files

Unified · Split

libavfilter/vf_lumakey.c+15−12
@@ -28,12 +28,13 @@ · 27 unmodified lines
2828 typedef struct LumakeyContext {
2929 const AVClass *class;
3030
31− int threshold;
32− int tolerance;
33− int softness;
31+ double threshold;
32+ double tolerance;
33+ double softness;
3434
3535 int white;
3636 int black;
37+ int so;
3738 int max;
3839
3940 int (*do_lumakey_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
@@ -47,7 +48,7 @@ static int do_lumakey_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_ · 7 unmodified lines
4748 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
4849 uint8_t *alpha = frame->data[3] + slice_start * frame->linesize[3];
4950 const uint8_t *luma = frame->data[0] + slice_start * frame->linesize[0];
50− const int so = s->softness;
51+ const int so = s->so;
5152 const int w = s->white;
5253 const int b = s->black;
5354 int x, y;
@@ -79,7 +80,7 @@ static int do_lumakey_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb · 25 unmodified lines
7980 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
8081 uint16_t *alpha = (uint16_t *)(frame->data[3] + slice_start * frame->linesize[3]);
8182 const uint16_t *luma = (const uint16_t *)(frame->data[0] + slice_start * frame->linesize[0]);
82− const int so = s->softness;
83+ const int so = s->so;
8384 const int w = s->white;
8485 const int b = s->black;
8586 const int m = s->max;
@@ -113,14 +114,16 @@ static int config_input(AVFilterLink *inlink) · 27 unmodified lines
113114
114115 depth = desc->comp[0].depth;
115116 if (depth == 8) {
116− s->white = av_clip_uint8(s->threshold + s->tolerance);
117− s->black = av_clip_uint8(s->threshold - s->tolerance);
117+ s->white = av_clip_uint8((s->threshold + s->tolerance) * 255);
118+ s->black = av_clip_uint8((s->threshold - s->tolerance) * 255);
118119 s->do_lumakey_slice = do_lumakey_slice8;
120+ s->so = s->softness * 255;
119121 } else {
120122 s->max = (1 << depth) - 1;
121− s->white = av_clip(s->threshold + s->tolerance, 0, s->max);
122− s->black = av_clip(s->threshold - s->tolerance, 0, s->max);
123+ s->white = av_clip((s->threshold + s->tolerance) * s->max, 0, s->max);
124+ s->black = av_clip((s->threshold - s->tolerance) * s->max, 0, s->max);
123125 s->do_lumakey_slice = do_lumakey_slice16;
126+ s->so = s->softness * s->max;
124127 }
125128
126129 return 0;
@@ -182,9 +185,9 @@ static const AVFilterPad lumakey_outputs[] = { · 55 unmodified lines
182185 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
183186
184187 static const AVOption lumakey_options[] = {
185− { "threshold", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, FLAGS },
186− { "tolerance", "set the tolerance value", OFFSET(tolerance), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, FLAGS },
187− { "softness", "set the softness value", OFFSET(softness), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, FLAGS },
188+ { "threshold", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
189+ { "tolerance", "set the tolerance value", OFFSET(tolerance), AV_OPT_TYPE_DOUBLE, {.dbl=0.01}, 0, 1, FLAGS },
190+ { "softness", "set the softness value", OFFSET(softness), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
188191 { NULL }
189192 };
190193

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t