Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -47,14 +47,14 @@ typedef struct MaskFunContext { · 46 unmodified lines | ||
| 47 | 47 | } MaskFunContext; |
| 48 | 48 | |
| 49 | 49 | #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 | |
| 51 | 51 | |
| 52 | 52 | 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 }, | |
| 58 | 58 | { NULL } |
| 59 | 59 | }; |
| 60 | 60 | |
| @@ -182,6 +182,45 @@ static int maskfun##name(AVFilterContext *ctx, void *arg, \ · 121 unmodified lines | ||
| 182 | 182 | MASKFUN(8, uint8_t, 1) |
| 183 | 183 | MASKFUN(16, uint16_t, 2) |
| 184 | 184 | |
| 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 | + | |
| 185 | 224 | static int config_input(AVFilterLink *inlink) |
| 186 | 225 | { |
| 187 | 226 | AVFilterContext *ctx = inlink->dst; |
| @@ -203,7 +242,6 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines | ||
| 203 | 242 | |
| 204 | 243 | s->depth = desc->comp[0].depth; |
| 205 | 244 | s->max = (1 << s->depth) - 1; |
| 206 | − s->fill = FFMIN(s->fill, s->max); | |
| 207 | 245 | |
| 208 | 246 | if (s->depth == 8) { |
| 209 | 247 | s->maskfun = maskfun8; |
| @@ -217,33 +255,30 @@ static int config_input(AVFilterLink *inlink) · 7 unmodified lines | ||
| 217 | 255 | if (!s->empty) |
| 218 | 256 | return AVERROR(ENOMEM); |
| 219 | 257 | |
| 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); | |
| 223 | 259 | |
| 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); | |
| 232 | 261 | |
| 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 | +} | |
| 240 | 264 | |
| 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); | |
| 247 | 282 | |
| 248 | 283 | return 0; |
| 249 | 284 | } |
| @@ -284,4 +319,5 @@ AVFilter ff_vf_maskfun = { · 34 unmodified lines | ||
| 284 | 319 | .outputs = maskfun_outputs, |
| 285 | 320 | .priv_class = &maskfun_class, |
| 286 | 321 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, |
| 322 | + .process_command = process_command, | |
| 287 | 323 | }; |