FFmpeg
boxblur.c
Go to the documentation of this file.
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 {
44 };
45 
46 
48  FilterParam *luma_param,
49  FilterParam *chroma_param,
50  FilterParam *alpha_param)
51 {
53  AVFilterContext *ctx = inlink->dst;
54  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  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  if (!chroma_param->radius_expr) {
67  chroma_param->radius_expr = av_strdup(luma_param->radius_expr);
68  if (!chroma_param->radius_expr)
69  return AVERROR(ENOMEM);
70  }
71  if (chroma_param->power < 0)
72  chroma_param->power = luma_param->power;
73 
74  if (!alpha_param->radius_expr) {
75  alpha_param->radius_expr = av_strdup(luma_param->radius_expr);
76  if (!alpha_param->radius_expr)
77  return AVERROR(ENOMEM);
78  }
79  if (alpha_param->power < 0)
80  alpha_param->power = luma_param->power;
81 
82  var_values[VAR_W] = inlink->w;
83  var_values[VAR_H] = inlink->h;
84  var_values[VAR_CW] = cw = w>>(desc->log2_chroma_w);
85  var_values[VAR_CH] = ch = h>>(desc->log2_chroma_h);
86  var_values[VAR_HSUB] = 1<<(desc->log2_chroma_w);
87  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  EVAL_RADIUS_EXPR(luma_param);
101  EVAL_RADIUS_EXPR(chroma_param);
102  EVAL_RADIUS_EXPR(alpha_param);
103 
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  CHECK_RADIUS_VAL(w, h, luma_param);
124  CHECK_RADIUS_VAL(cw, ch, chroma_param);
125  CHECK_RADIUS_VAL(w, h, alpha_param);
126 
127  return 0;
128 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
VAR_CH
@ VAR_CH
Definition: boxblur.c:40
var_name
var_name
Definition: noise.c:47
CHECK_RADIUS_VAL
#define CHECK_RADIUS_VAL(w_, h_, comp)
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
w
uint8_t w
Definition: llviddspenc.c:38
FilterParam::radius_expr
char * radius_expr
Definition: boxblur.h:34
VAR_HSUB
@ VAR_HSUB
Definition: boxblur.c:41
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
FilterParam::radius
int radius
Definition: boxblur.h:32
VAR_VSUB
@ VAR_VSUB
Definition: boxblur.c:42
EVAL_RADIUS_EXPR
#define EVAL_RADIUS_EXPR(comp)
ff_boxblur_eval_filter_params
int ff_boxblur_eval_filter_params(AVFilterLink *inlink, FilterParam *luma_param, FilterParam *chroma_param, FilterParam *alpha_param)
Definition: boxblur.c:47
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
VAR_H
@ VAR_H
Definition: boxblur.c:38
VAR_W
@ VAR_W
Definition: boxblur.c:37
ctx
AVFormatContext * ctx
Definition: movenc.c:49
VAR_CW
@ VAR_CW
Definition: boxblur.c:39
NULL
#define NULL
Definition: coverity.c:32
FilterParam
Definition: boxblur.h:31
VARS_NB
@ VARS_NB
Definition: boxblur.c:43
boxblur.h
ret
ret
Definition: filter_design.txt:187
var_names
static const char *const var_names[]
Definition: boxblur.c:26
power
static float power(float r, float g, float b, float max)
Definition: preserve_color.h:45
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:79
mem.h
FilterParam::power
int power
Definition: boxblur.h:33
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070