Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * Copyright (c) 2011 Stefano Sabatini | ||
4 | * Copyright (c) 2018 Danil Iashchenko | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include "libavutil/mem.h" | ||
24 | #include "boxblur.h" | ||
25 | |||
26 | static const char *const var_names[] = { | ||
27 | "w", | ||
28 | "h", | ||
29 | "cw", | ||
30 | "ch", | ||
31 | "hsub", | ||
32 | "vsub", | ||
33 | NULL | ||
34 | }; | ||
35 | |||
36 | enum var_name { | ||
37 | VAR_W, | ||
38 | VAR_H, | ||
39 | VAR_CW, | ||
40 | VAR_CH, | ||
41 | VAR_HSUB, | ||
42 | VAR_VSUB, | ||
43 | VARS_NB | ||
44 | }; | ||
45 | |||
46 | |||
47 | 1 | int ff_boxblur_eval_filter_params(AVFilterLink *inlink, | |
48 | FilterParam *luma_param, | ||
49 | FilterParam *chroma_param, | ||
50 | FilterParam *alpha_param) | ||
51 | { | ||
52 | 1 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | |
53 | 1 | AVFilterContext *ctx = inlink->dst; | |
54 | 1 | int w = inlink->w, h = inlink->h; | |
55 | int cw, ch; | ||
56 | double var_values[VARS_NB], res; | ||
57 | char *expr; | ||
58 | int ret; | ||
59 | |||
60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!luma_param->radius_expr) { |
61 | ✗ | av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n"); | |
62 | ✗ | return AVERROR(EINVAL); | |
63 | } | ||
64 | |||
65 | /* fill missing params */ | ||
66 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!chroma_param->radius_expr) { |
67 | 1 | chroma_param->radius_expr = av_strdup(luma_param->radius_expr); | |
68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!chroma_param->radius_expr) |
69 | ✗ | return AVERROR(ENOMEM); | |
70 | } | ||
71 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (chroma_param->power < 0) |
72 | 1 | chroma_param->power = luma_param->power; | |
73 | |||
74 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!alpha_param->radius_expr) { |
75 | 1 | alpha_param->radius_expr = av_strdup(luma_param->radius_expr); | |
76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!alpha_param->radius_expr) |
77 | ✗ | return AVERROR(ENOMEM); | |
78 | } | ||
79 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (alpha_param->power < 0) |
80 | 1 | alpha_param->power = luma_param->power; | |
81 | |||
82 | 1 | var_values[VAR_W] = inlink->w; | |
83 | 1 | var_values[VAR_H] = inlink->h; | |
84 | 1 | var_values[VAR_CW] = cw = w>>(desc->log2_chroma_w); | |
85 | 1 | var_values[VAR_CH] = ch = h>>(desc->log2_chroma_h); | |
86 | 1 | var_values[VAR_HSUB] = 1<<(desc->log2_chroma_w); | |
87 | 1 | var_values[VAR_VSUB] = 1<<(desc->log2_chroma_h); | |
88 | |||
89 | #define EVAL_RADIUS_EXPR(comp) \ | ||
90 | expr = comp->radius_expr; \ | ||
91 | ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \ | ||
92 | NULL, NULL, NULL, NULL, NULL, 0, ctx); \ | ||
93 | comp->radius = res; \ | ||
94 | if (ret < 0) { \ | ||
95 | av_log(ctx, AV_LOG_ERROR, \ | ||
96 | "Error when evaluating " #comp " radius expression '%s'\n", expr); \ | ||
97 | return ret; \ | ||
98 | } | ||
99 | |||
100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | EVAL_RADIUS_EXPR(luma_param); |
101 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | EVAL_RADIUS_EXPR(chroma_param); |
102 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | EVAL_RADIUS_EXPR(alpha_param); |
103 | |||
104 | 1 | av_log(ctx, AV_LOG_VERBOSE, | |
105 | "luma_radius:%d luma_power:%d " | ||
106 | "chroma_radius:%d chroma_power:%d " | ||
107 | "alpha_radius:%d alpha_power:%d " | ||
108 | "w:%d chroma_w:%d h:%d chroma_h:%d\n", | ||
109 | luma_param ->radius, luma_param ->power, | ||
110 | chroma_param->radius, chroma_param->power, | ||
111 | alpha_param ->radius, alpha_param ->power, | ||
112 | w, cw, h, ch); | ||
113 | |||
114 | |||
115 | #define CHECK_RADIUS_VAL(w_, h_, comp) \ | ||
116 | if (comp->radius < 0 || \ | ||
117 | 2*comp->radius > FFMIN(w_, h_)) { \ | ||
118 | av_log(ctx, AV_LOG_ERROR, \ | ||
119 | "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \ | ||
120 | comp->radius, FFMIN(w_, h_)/2); \ | ||
121 | return AVERROR(EINVAL); \ | ||
122 | } | ||
123 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | CHECK_RADIUS_VAL(w, h, luma_param); |
124 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | CHECK_RADIUS_VAL(cw, ch, chroma_param); |
125 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | CHECK_RADIUS_VAL(w, h, alpha_param); |
126 | |||
127 | 1 | return 0; | |
128 | } | ||
129 |