138 int w = inlink->
w, h = inlink->
h;
140 double var_values[
VARS_NB], res;
151 var_values[
VAR_W] = inlink->
w;
152 var_values[
VAR_H] = inlink->
h;
158 #define EVAL_RADIUS_EXPR(comp) \
159 expr = s->comp##_param.radius_expr; \
160 ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
161 NULL, NULL, NULL, NULL, NULL, 0, ctx); \
162 s->comp##_param.radius = res; \
164 av_log(NULL, AV_LOG_ERROR, \
165 "Error when evaluating " #comp " radius expression '%s'\n", expr); \
173 "luma_radius:%d luma_power:%d "
174 "chroma_radius:%d chroma_power:%d "
175 "alpha_radius:%d alpha_power:%d "
176 "w:%d chroma_w:%d h:%d chroma_h:%d\n",
182 #define CHECK_RADIUS_VAL(w_, h_, comp) \
183 if (s->comp##_param.radius < 0 || \
184 2*s->comp##_param.radius > FFMIN(w_, h_)) { \
185 av_log(ctx, AV_LOG_ERROR, \
186 "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
187 s->comp##_param.radius, FFMIN(w_, h_)/2); \
188 return AVERROR(EINVAL); \
222 const int length = radius*2 + 1;
223 const int inv = ((1<<16) + length/2)/
length;
226 for (x = 0; x < radius; x++)
227 sum += src[x*src_step]<<1;
228 sum += src[radius*src_step];
230 for (x = 0; x <= radius; x++) {
231 sum += src[(radius+x)*src_step] - src[(radius-x)*src_step];
232 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
235 for (; x < len-radius; x++) {
236 sum += src[(radius+x)*src_step] - src[(x-radius-1)*src_step];
237 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
240 for (; x <
len; x++) {
241 sum += src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step];
242 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
251 if (radius && power) {
252 blur(a, 1, src, src_step, len, radius);
253 for (; power > 2; power--) {
255 blur(b, 1, a, 1, len, radius);
259 blur(dst, dst_step, a, 1, len, radius);
262 for (i = 0; i <
len; i++)
263 dst[i*dst_step] = a[i];
267 for (i = 0; i <
len; i++)
268 dst[i*dst_step] = src[i*src_step];
273 int w,
int h,
int radius,
int power,
uint8_t *
temp[2])
277 if (radius == 0 && dst == src)
280 for (y = 0; y < h; y++)
281 blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1,
282 w, radius, power, temp);
286 int w,
int h,
int radius,
int power,
uint8_t *
temp[2])
290 if (radius == 0 && dst == src)
293 for (x = 0; x < w; x++)
294 blur_power(dst + x, dst_linesize, src + x, src_linesize,
295 h, radius, power, temp);
306 int w[4] = { inlink->
w, cw, cw, inlink->
w };
316 for (plane = 0; plane < 4 && in->
data[plane] && in->
linesize[plane]; plane++)
319 w[plane], h[plane], s->
radius[plane], s->
power[plane],
322 for (plane = 0; plane < 4 && in->
data[plane] && in->
linesize[plane]; plane++)
325 w[plane], h[plane], s->
radius[plane], s->
power[plane],
333 #define OFFSET(x) offsetof(BoxBlurContext, x)
334 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
339 {
"luma_power",
"How many times should the boxblur be applied to luma",
OFFSET(luma_param.power),
AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags =
FLAGS },
340 {
"lp",
"How many times should the boxblur be applied to luma",
OFFSET(luma_param.power),
AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags =
FLAGS },
344 {
"chroma_power",
"How many times should the boxblur be applied to chroma",
OFFSET(chroma_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
345 {
"cp",
"How many times should the boxblur be applied to chroma",
OFFSET(chroma_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
349 {
"alpha_power",
"How many times should the boxblur be applied to alpha",
OFFSET(alpha_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
350 {
"ap",
"How many times should the boxblur be applied to alpha",
OFFSET(alpha_param.power),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags =
FLAGS },
379 .priv_class = &boxblur_class,
383 .
inputs = avfilter_vf_boxblur_inputs,
384 .
outputs = avfilter_vf_boxblur_outputs,