139 int w = inlink->
w,
h = inlink->
h;
141 double var_values[
VARS_NB], res;
152 var_values[
VAR_W] = inlink->
w;
153 var_values[
VAR_H] = inlink->
h;
159 #define EVAL_RADIUS_EXPR(comp) \
160 expr = s->comp##_param.radius_expr; \
161 ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
162 NULL, NULL, NULL, NULL, NULL, 0, ctx); \
163 s->comp##_param.radius = res; \
165 av_log(NULL, AV_LOG_ERROR, \
166 "Error when evaluating " #comp " radius expression '%s'\n", expr); \
174 "luma_radius:%d luma_power:%d "
175 "chroma_radius:%d chroma_power:%d "
176 "alpha_radius:%d alpha_power:%d "
177 "w:%d chroma_w:%d h:%d chroma_h:%d\n",
183 #define CHECK_RADIUS_VAL(w_, h_, comp) \
184 if (s->comp##_param.radius < 0 || \
185 2*s->comp##_param.radius > FFMIN(w_, h_)) { \
186 av_log(ctx, AV_LOG_ERROR, \
187 "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
188 s->comp##_param.radius, FFMIN(w_, h_)/2); \
189 return AVERROR(EINVAL); \
223 const int length = radius*2 + 1;
224 const int inv = ((1<<16) + length/2)/
length;
225 int x, sum = src[radius*src_step];
227 for (x = 0; x < radius; x++)
228 sum += src[x*src_step]<<1;
230 sum = sum*inv + (1<<15);
232 for (x = 0; x <= radius; x++) {
233 sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
234 dst[x*dst_step] = sum>>16;
237 for (; x < len-radius; x++) {
238 sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
239 dst[x*dst_step] = sum >>16;
242 for (; x <
len; x++) {
243 sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
244 dst[x*dst_step] = sum>>16;
248 static inline void blur16(uint16_t *dst,
int dst_step,
const uint16_t *
src,
int src_step,
251 const int length = radius*2 + 1;
252 const int inv = ((1<<16) + length/2)/
length;
253 int x, sum = src[radius*src_step];
255 for (x = 0; x < radius; x++)
256 sum += src[x*src_step]<<1;
258 sum = sum*inv + (1<<15);
260 for (x = 0; x <= radius; x++) {
261 sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
262 dst[x*dst_step] = sum>>16;
265 for (; x < len-radius; x++) {
266 sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
267 dst[x*dst_step] = sum >>16;
270 for (; x <
len; x++) {
271 sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
272 dst[x*dst_step] = sum>>16;
277 int len,
int radius,
int pixsize)
279 if (pixsize == 1)
blur8 (dst, dst_step , src, src_step , len, radius);
280 else blur16((uint16_t*)dst, dst_step>>1, (
const uint16_t*)src, src_step>>1, len, radius);
288 if (radius && power) {
289 blur(a, pixsize, src, src_step, len, radius, pixsize);
290 for (; power > 2; power--) {
292 blur(b, pixsize, a, pixsize, len, radius, pixsize);
296 blur(dst, dst_step, a, pixsize, len, radius, pixsize);
300 for (i = 0; i <
len; i++)
301 dst[i*dst_step] = a[i];
303 for (i = 0; i <
len; i++)
304 *(uint16_t*)(dst + i*dst_step) = ((uint16_t*)
a)[i];
309 for (i = 0; i <
len; i++)
310 dst[i*dst_step] = src[i*src_step];
312 for (i = 0; i <
len; i++)
313 *(uint16_t*)(dst + i*dst_step) = *(uint16_t*)(src + i*src_step);
318 int w,
int h,
int radius,
int power,
uint8_t *
temp[2],
int pixsize)
322 if (radius == 0 && dst == src)
325 for (y = 0; y <
h; y++)
326 blur_power(dst + y*dst_linesize, pixsize, src + y*src_linesize, pixsize,
327 w, radius, power, temp, pixsize);
331 int w,
int h,
int radius,
int power,
uint8_t *
temp[2],
int pixsize)
335 if (radius == 0 && dst == src)
338 for (x = 0; x < w; x++)
339 blur_power(dst + x*pixsize, dst_linesize, src + x*pixsize, src_linesize,
340 h, radius, power, temp, pixsize);
351 int w[4] = { inlink->
w, cw, cw, inlink->
w };
355 const int pixsize = (depth+7)/8;
367 w[plane], h[plane], s->
radius[plane], s->
power[plane],
373 w[plane], h[plane], s->
radius[plane], s->
power[plane],
381 #define OFFSET(x) offsetof(BoxBlurContext, x)
382 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
387 {
"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 },
388 {
"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 },
392 {
"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 },
393 {
"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 },
397 {
"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 },
398 {
"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 },
427 .priv_class = &boxblur_class,
431 .
inputs = avfilter_vf_boxblur_inputs,
432 .
outputs = avfilter_vf_boxblur_outputs,
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
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], int pixsize)
static void blur16(uint16_t *dst, int dst_step, const uint16_t *src, int src_step, int len, int radius)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad outputs[]
Main libavfilter public API header.
static int config_input(AVFilterLink *inlink)
int h
agreed upon image height
static void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int pixsize)
static enum AVSampleFormat formats[]
static av_cold int init(AVFilterContext *ctx)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
static void blur8(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t * temp[2]
temporary buffer used in blur_power()
static const AVFilterPad avfilter_vf_boxblur_outputs[]
static const AVOption boxblur_options[]
#define AV_LOG_VERBOSE
Detailed information.
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], int pixsize)
A filter pad used for either input or output.
A link between two filters.
uint16_t depth_minus1
Number of bits in the component minus 1.
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#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)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
static const AVFilterPad avfilter_vf_boxblur_inputs[]
int w
agreed upon image width
uint8_t nb_components
The number of components each pixel has, (1-4)
#define FF_CEIL_RSHIFT(a, b)
static const char *const var_names[]
int format
agreed upon media format
#define EVAL_RADIUS_EXPR(comp)
char * av_strdup(const char *s)
Duplicate the string s.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
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], int pixsize)
static av_cold void uninit(AVFilterContext *ctx)
const char * name
Filter name.
AVFILTER_DEFINE_CLASS(boxblur)
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
AVFilterLink ** outputs
array of pointers to output links
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal and external API header
#define CHECK_RADIUS_VAL(w_, h_, comp)
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
AVFilterContext * dst
dest filter
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
simple arithmetic expression evaluator