66 char luma_radius_expr [256];
67 char chroma_radius_expr[256];
68 char alpha_radius_expr [256];
88 "Filter expects 2 or 4 or 6 arguments, none provided\n");
92 e = sscanf(args,
"%255[^:]:%d:%255[^:]:%d:%255[^:]:%d",
97 if (e != 2 && e != 4 && e != 6) {
99 "Filter expects 2 or 4 or 6 params, provided %d\n", e);
145 int w = inlink->
w, h = inlink->
h;
147 double var_values[
VARS_NB], res;
163 var_values[
VAR_W] = inlink->
w;
164 var_values[
VAR_H] = inlink->
h;
170 #define EVAL_RADIUS_EXPR(comp) \
171 expr = boxblur->comp##_radius_expr; \
172 ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
173 NULL, NULL, NULL, NULL, NULL, 0, ctx); \
174 boxblur->comp##_param.radius = res; \
176 av_log(NULL, AV_LOG_ERROR, \
177 "Error when evaluating " #comp " radius expression '%s'\n", expr); \
185 "luma_radius:%d luma_power:%d "
186 "chroma_radius:%d chroma_power:%d "
187 "alpha_radius:%d alpha_power:%d "
188 "w:%d chroma_w:%d h:%d chroma_h:%d\n",
194 #define CHECK_RADIUS_VAL(w_, h_, comp) \
195 if (boxblur->comp##_param.radius < 0 || \
196 2*boxblur->comp##_param.radius > FFMIN(w_, h_)) { \
197 av_log(ctx, AV_LOG_ERROR, \
198 "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
199 boxblur->comp##_param.radius, FFMIN(w_, h_)/2); \
200 return AVERROR(EINVAL); \
234 const int length = radius*2 + 1;
235 const int inv = ((1<<16) + length/2)/length;
238 for (x = 0; x < radius; x++)
239 sum += src[x*src_step]<<1;
240 sum += src[radius*src_step];
242 for (x = 0; x <= radius; x++) {
243 sum += src[(radius+x)*src_step] - src[(radius-x)*src_step];
244 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
247 for (; x < len-radius; x++) {
248 sum += src[(radius+x)*src_step] - src[(x-radius-1)*src_step];
249 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
252 for (; x <
len; x++) {
253 sum += src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step];
254 dst[x*dst_step] = (sum*inv + (1<<15))>>16;
259 int len,
int radius,
int power,
uint8_t *temp[2])
263 if (radius && power) {
264 blur(a, 1, src, src_step, len, radius);
265 for (; power > 2; power--) {
267 blur(b, 1, a, 1, len, radius);
271 blur(dst, dst_step, a, 1, len, radius);
274 for (i = 0; i <
len; i++)
275 dst[i*dst_step] = a[i];
279 for (i = 0; i <
len; i++)
280 dst[i*dst_step] = src[i*src_step];
285 int w,
int h,
int radius,
int power,
uint8_t *temp[2])
289 if (radius == 0 && dst == src)
292 for (y = 0; y < h; y++)
293 blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1,
294 w, radius, power, temp);
298 int w,
int h,
int radius,
int power,
uint8_t *temp[2])
302 if (radius == 0 && dst == src)
305 for (x = 0; x < w; x++)
306 blur_power(dst + x, dst_linesize, src + x, src_linesize,
307 h, radius, power, temp);
317 int cw = inlink->
w >> boxblur->
hsub, ch = in->
video->
h >> boxblur->
vsub;
318 int w[4] = { inlink->
w, cw, cw, inlink->
w };
328 for (plane = 0; in->
data[plane] && plane < 4; plane++)
331 w[plane], h[plane], boxblur->
radius[plane], boxblur->
power[plane],
334 for (plane = 0; in->
data[plane] && plane < 4; plane++)
337 w[plane], h[plane], boxblur->
radius[plane], boxblur->
power[plane],
372 .
inputs = avfilter_vf_boxblur_inputs,
373 .
outputs = avfilter_vf_boxblur_outputs,
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVFilter avfilter_vf_boxblur
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterBufferRefVideoProps * video
video buffer specific properties
static av_cold int init(AVFilterContext *ctx, const char *args)
int linesize[8]
number of bytes per line
static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2])
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const AVFilterPad outputs[]
static int config_input(AVFilterLink *inlink)
int h
agreed upon image height
char chroma_radius_expr[256]
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
#define AV_PERM_READ
can read from the buffer
const char * name
Pad name.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
uint8_t * temp[2]
temporary buffer used in blur_power()
struct FilterParam FilterParam
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
static const AVFilterPad avfilter_vf_boxblur_outputs[]
static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2])
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
A filter pad used for either input or output.
A link between two filters.
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
static int query_formats(AVFilterContext *ctx)
void av_log(void *avcl, int level, const char *fmt,...)
static const AVFilterPad avfilter_vf_boxblur_inputs[]
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
char alpha_radius_expr[256]
static const char *const var_names[]
int format
agreed upon media format
#define EVAL_RADIUS_EXPR(comp)
A reference to an AVFilterBuffer.
static void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius)
static void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int power, uint8_t *temp[2])
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static const AVFilterPad inputs[]
static av_cold void uninit(AVFilterContext *ctx)
const char * name
filter name
AVFilterLink ** outputs
array of pointers to output links
char luma_radius_expr[256]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
#define CHECK_RADIUS_VAL(w_, h_, comp)
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AV_PERM_WRITE
can write to the buffer
AVFilterContext * dst
dest filter
uint8_t * data[8]
picture/audio data for each plane
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
AVPixelFormat
Pixel format.
simple arithmetic expression evaluator