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
28typedef struct LumakeyContext {28typedef struct LumakeyContext {
29 const AVClass *class;29 const AVClass *class;
30 30
31 int threshold;31 double threshold;
32 int tolerance;32 double tolerance;
33 int softness;33 double softness;
34 34
35 int white;35 int white;
36 int black;36 int black;
37 int so;
37 int max;38 int max;
38 39
39 int (*do_lumakey_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);40 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
47 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;48 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
48 uint8_t *alpha = frame->data[3] + slice_start * frame->linesize[3];49 uint8_t *alpha = frame->data[3] + slice_start * frame->linesize[3];
49 const uint8_t *luma = frame->data[0] + slice_start * frame->linesize[0];50 const uint8_t *luma = frame->data[0] + slice_start * frame->linesize[0];
50 const int so = s->softness;51 const int so = s->so;
51 const int w = s->white;52 const int w = s->white;
52 const int b = s->black;53 const int b = s->black;
53 int x, y;54 int x, y;
@@ -79,7 +80,7 @@ static int do_lumakey_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb · 25 unmodified lines
79 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;80 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
80 uint16_t *alpha = (uint16_t *)(frame->data[3] + slice_start * frame->linesize[3]);81 uint16_t *alpha = (uint16_t *)(frame->data[3] + slice_start * frame->linesize[3]);
81 const uint16_t *luma = (const uint16_t *)(frame->data[0] + slice_start * frame->linesize[0]);82 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;
83 const int w = s->white;84 const int w = s->white;
84 const int b = s->black;85 const int b = s->black;
85 const int m = s->max;86 const int m = s->max;
@@ -113,14 +114,16 @@ static int config_input(AVFilterLink *inlink) · 27 unmodified lines
113 114
114 depth = desc->comp[0].depth;115 depth = desc->comp[0].depth;
115 if (depth == 8) {116 if (depth == 8) {
116 s->white = av_clip_uint8(s->threshold + s->tolerance);117 s->white = av_clip_uint8((s->threshold + s->tolerance) * 255);
117 s->black = av_clip_uint8(s->threshold - s->tolerance);118 s->black = av_clip_uint8((s->threshold - s->tolerance) * 255);
118 s->do_lumakey_slice = do_lumakey_slice8;119 s->do_lumakey_slice = do_lumakey_slice8;
120 s->so = s->softness * 255;
119 } else {121 } else {
120 s->max = (1 << depth) - 1;122 s->max = (1 << depth) - 1;
121 s->white = av_clip(s->threshold + s->tolerance, 0, s->max);123 s->white = av_clip((s->threshold + s->tolerance) * s->max, 0, s->max);
122 s->black = av_clip(s->threshold - s->tolerance, 0, s->max);124 s->black = av_clip((s->threshold - s->tolerance) * s->max, 0, s->max);
123 s->do_lumakey_slice = do_lumakey_slice16;125 s->do_lumakey_slice = do_lumakey_slice16;
126 s->so = s->softness * s->max;
124 }127 }
125 128
126 return 0;129 return 0;
@@ -182,9 +185,9 @@ static const AVFilterPad lumakey_outputs[] = { · 55 unmodified lines
182#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM185#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
183 186
184static const AVOption lumakey_options[] = {187static const AVOption lumakey_options[] = {
185 { "threshold", "set the threshold value", OFFSET(threshold), 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 },
186 { "tolerance", "set the tolerance value", OFFSET(tolerance), AV_OPT_TYPE_INT, {.i64=1}, 0, UINT16_MAX, FLAGS },189 { "tolerance", "set the tolerance value", OFFSET(tolerance), AV_OPT_TYPE_DOUBLE, {.dbl=0.01}, 0, 1, FLAGS },
187 { "softness", "set the softness value", OFFSET(softness), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, FLAGS },190 { "softness", "set the softness value", OFFSET(softness), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
188 { NULL }191 { NULL }
189};192};
190 193

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