History

avfilter/vf_maskfun: add support for commands

Paul B Mahol committed 5 years ago

Commit ca042671 parent 8e027ca2 files · +71 −31Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_maskfun.c+67−31
@@ -47,14 +47,14 @@ typedef struct MaskFunContext { · 46 unmodified lines
4747 } MaskFunContext;
4848
4949 #define OFFSET(x) offsetof(MaskFunContext, x)
50−#define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
50+#define VFT AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
5151
5252 static const AVOption maskfun_options[] = {
53− { "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },
54− { "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },
55− { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, VF },
56− { "fill", "set fill value", OFFSET(fill), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, VF },
57− { "sum", "set sum value", OFFSET(sum), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },
53+ { "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
54+ { "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
55+ { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, VFT },
56+ { "fill", "set fill value", OFFSET(fill), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, VFT },
57+ { "sum", "set sum value", OFFSET(sum), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
5858 { NULL }
5959 };
6060
@@ -182,6 +182,45 @@ static int maskfun##name(AVFilterContext *ctx, void *arg, \ · 121 unmodified lines
182182 MASKFUN(8, uint8_t, 1)
183183 MASKFUN(16, uint16_t, 2)
184184
185+static void fill_frame(AVFilterContext *ctx)
186+{
187+ MaskFunContext *s = ctx->priv;
188+
189+ s->fill = FFMIN(s->fill, s->max);
190+ if (s->depth == 8) {
191+ for (int p = 0; p < s->nb_planes; p++) {
192+ uint8_t *dst = s->empty->data[p];
193+
194+ for (int y = 0; y < s->height[p]; y++) {
195+ memset(dst, s->fill, s->width[p]);
196+ dst += s->empty->linesize[p];
197+ }
198+ }
199+ } else {
200+ for (int p = 0; p < s->nb_planes; p++) {
201+ uint16_t *dst = (uint16_t *)s->empty->data[p];
202+
203+ for (int y = 0; y < s->height[p]; y++) {
204+ for (int x = 0; x < s->width[p]; x++)
205+ dst[x] = s->fill;
206+ dst += s->empty->linesize[p] / 2;
207+ }
208+ }
209+ }
210+}
211+
212+static void set_max_sum(AVFilterContext *ctx)
213+{
214+ MaskFunContext *s = ctx->priv;
215+
216+ s->max_sum = 0;
217+ for (int p = 0; p < s->nb_planes; p++) {
218+ if (!((1 << p) & s->planes))
219+ continue;
220+ s->max_sum += (uint64_t)s->sum * s->width[p] * s->height[p];
221+ }
222+}
223+
185224 static int config_input(AVFilterLink *inlink)
186225 {
187226 AVFilterContext *ctx = inlink->dst;
@@ -203,7 +242,6 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines
203242
204243 s->depth = desc->comp[0].depth;
205244 s->max = (1 << s->depth) - 1;
206− s->fill = FFMIN(s->fill, s->max);
207245
208246 if (s->depth == 8) {
209247 s->maskfun = maskfun8;
@@ -217,33 +255,30 @@ static int config_input(AVFilterLink *inlink) · 7 unmodified lines
217255 if (!s->empty)
218256 return AVERROR(ENOMEM);
219257
220− if (s->depth == 8) {
221− for (int p = 0; p < s->nb_planes; p++) {
222− uint8_t *dst = s->empty->data[p];
258+ fill_frame(ctx);
223259
224− for (int y = 0; y < s->height[p]; y++) {
225− memset(dst, s->fill, s->width[p]);
226− dst += s->empty->linesize[p];
227− }
228− }
229− } else {
230− for (int p = 0; p < s->nb_planes; p++) {
231− uint16_t *dst = (uint16_t *)s->empty->data[p];
260+ set_max_sum(ctx);
232261
233− for (int y = 0; y < s->height[p]; y++) {
234− for (int x = 0; x < s->width[p]; x++)
235− dst[x] = s->fill;
236− dst += s->empty->linesize[p] / 2;
237− }
238− }
239− }
262+ return 0;
263+}
240264
241− s->max_sum = 0;
242− for (int p = 0; p < s->nb_planes; p++) {
243− if (!((1 << p) & s->planes))
244− continue;
245− s->max_sum += (uint64_t)s->sum * s->width[p] * s->height[p];
246− }
265+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
266+ char *res, int res_len, int flags)
267+{
268+ MaskFunContext *s = ctx->priv;
269+ int fill = s->fill;
270+ int sum = s->sum;
271+ int ret;
272+
273+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
274+ if (ret < 0)
275+ return ret;
276+
277+ if (sum != s->sum)
278+ set_max_sum(ctx);
279+
280+ if (fill != s->fill)
281+ fill_frame(ctx);
247282
248283 return 0;
249284 }
@@ -284,4 +319,5 @@ AVFilter ff_vf_maskfun = { · 34 unmodified lines
284319 .outputs = maskfun_outputs,
285320 .priv_class = &maskfun_class,
286321 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
322+ .process_command = process_command,
287323 };

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