Go to the documentation of this file.
36 #define RADIUS_MIN 0.1
37 #define RADIUS_MAX 5.0
39 #define STRENGTH_MIN -1.0
40 #define STRENGTH_MAX 1.0
42 #define THRESHOLD_MIN -30
43 #define THRESHOLD_MAX 30
63 #define OFFSET(x) offsetof(SmartblurContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
99 s->chroma.radius =
s->luma.radius;
101 s->chroma.strength =
s->luma.strength;
103 s->chroma.threshold =
s->luma.threshold;
107 s->alpha.radius =
s->luma.radius;
109 s->alpha.strength =
s->luma.strength;
111 s->alpha.threshold =
s->luma.threshold;
113 s->luma.quality =
s->chroma.quality =
s->alpha.quality = 3.0;
117 "luma_radius:%f luma_strength:%f luma_threshold:%d "
118 "chroma_radius:%f chroma_strength:%f chroma_threshold:%d "
119 "alpha_radius:%f alpha_strength:%f alpha_threshold:%d\n",
120 s->luma.radius,
s->luma.strength,
s->luma.threshold,
121 s->chroma.radius,
s->chroma.strength,
s->chroma.threshold,
122 s->alpha.radius,
s->alpha.strength,
s->alpha.threshold);
156 sws_filter.
lumH = sws_filter.
lumV = vec;
165 if (!
f->filter_context)
176 s->hsub =
desc->log2_chroma_w;
177 s->vsub =
desc->log2_chroma_h;
189 static void blur(uint8_t *
dst,
const int dst_linesize,
190 const uint8_t *
src,
const int src_linesize,
191 const int w,
const int h,
const int threshold,
198 const uint8_t*
const src_array[4] = {
src};
199 uint8_t *dst_array[4] = {
dst};
200 int src_linesize_array[4] = {src_linesize};
201 int dst_linesize_array[4] = {dst_linesize};
203 sws_scale(filter_context, src_array, src_linesize_array,
204 0,
h, dst_array, dst_linesize_array);
207 for (y = 0; y <
h; ++y) {
208 for (x = 0; x <
w; ++x) {
209 orig =
src[x + y * src_linesize];
210 filtered =
dst[x + y * dst_linesize];
211 diff = orig - filtered;
214 if (
diff > 2 * threshold)
215 dst[x + y * dst_linesize] = orig;
216 else if (
diff > threshold)
218 dst[x + y * dst_linesize] = orig - threshold;
220 if (-
diff > 2 * threshold)
221 dst[x + y * dst_linesize] = orig;
222 else if (-
diff > threshold)
224 dst[x + y * dst_linesize] = orig + threshold;
228 }
else if (threshold < 0) {
229 for (y = 0; y <
h; ++y) {
230 for (x = 0; x <
w; ++x) {
231 orig =
src[x + y * src_linesize];
232 filtered =
dst[x + y * dst_linesize];
233 diff = orig - filtered;
236 if (
diff <= -threshold)
237 dst[x + y * dst_linesize] = orig;
238 else if (
diff <= -2 * threshold)
240 dst[x + y * dst_linesize] = filtered - threshold;
242 if (
diff >= threshold)
243 dst[x + y * dst_linesize] = orig;
244 else if (
diff >= 2 * threshold)
246 dst[x + y * dst_linesize] = filtered + threshold;
271 s->luma.filter_context);
273 if (
inpic->data[2]) {
276 cw, ch,
s->chroma.threshold,
277 s->chroma.filter_context);
280 cw, ch,
s->chroma.threshold,
281 s->chroma.filter_context);
284 if (
inpic->data[3]) {
288 s->alpha.filter_context);
313 .priv_class = &smartblur_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
const AVFilter ff_vf_smartblur
AVPixelFormat
Pixel format.
static int config_props(AVFilterLink *inlink)
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
#define FILTER_PIXFMTS_ARRAY(array)
AVFILTER_DEFINE_CLASS(smartblur)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
static int alloc_sws_context(FilterParam *f, int width, int height, unsigned int flags)
static const AVOption smartblur_options[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
void sws_freeVec(SwsVector *a)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void blur(uint8_t *dst, const int dst_linesize, const uint8_t *src, const int src_linesize, const int w, const int h, const int threshold, struct SwsContext *filter_context)
SwsContext * sws_getCachedContext(SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
static av_cold int init(AVFilterContext *ctx)
A filter pad used for either input or output.
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, b)
int length
number of coefficients in the vector
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ SWS_BICUBIC
2-tap cubic B-spline
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
double * coeff
pointer to the list of coefficients
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
static const AVFilterPad smartblur_inputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold void uninit(AVFilterContext *ctx)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
int w
agreed upon image width
const char * name
Pad name.
int h
agreed upon image height
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
struct SwsContext * filter_context
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Main external API structure.
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)