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
62 #define OFFSET(x) offsetof(SmartblurContext, x)
63 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
91 s->chroma.radius =
s->luma.radius;
93 s->chroma.strength =
s->luma.strength;
95 s->chroma.threshold =
s->luma.threshold;
97 s->luma.quality =
s->chroma.quality = 3.0;
101 "luma_radius:%f luma_strength:%f luma_threshold:%d "
102 "chroma_radius:%f chroma_strength:%f chroma_threshold:%d\n",
103 s->luma.radius,
s->luma.strength,
s->luma.threshold,
104 s->chroma.radius,
s->chroma.strength,
s->chroma.threshold);
145 sws_filter.
lumH = sws_filter.
lumV = vec;
154 if (!
f->filter_context)
165 s->hsub =
desc->log2_chroma_w;
166 s->vsub =
desc->log2_chroma_h;
179 const int w,
const int h,
const int threshold,
188 int src_linesize_array[4] = {src_linesize};
189 int dst_linesize_array[4] = {dst_linesize};
191 sws_scale(filter_context, src_array, src_linesize_array,
192 0,
h, dst_array, dst_linesize_array);
195 for (y = 0; y <
h; ++y) {
196 for (x = 0; x <
w; ++x) {
197 orig =
src[x + y * src_linesize];
198 filtered = dst[x + y * dst_linesize];
199 diff = orig - filtered;
202 if (
diff > 2 * threshold)
203 dst[x + y * dst_linesize] = orig;
204 else if (
diff > threshold)
206 dst[x + y * dst_linesize] = orig - threshold;
208 if (-
diff > 2 * threshold)
209 dst[x + y * dst_linesize] = orig;
210 else if (-
diff > threshold)
212 dst[x + y * dst_linesize] = orig + threshold;
216 }
else if (threshold < 0) {
217 for (y = 0; y <
h; ++y) {
218 for (x = 0; x <
w; ++x) {
219 orig =
src[x + y * src_linesize];
220 filtered = dst[x + y * dst_linesize];
221 diff = orig - filtered;
224 if (
diff <= -threshold)
225 dst[x + y * dst_linesize] = orig;
226 else if (
diff <= -2 * threshold)
228 dst[x + y * dst_linesize] = filtered - threshold;
230 if (
diff >= threshold)
231 dst[x + y * dst_linesize] = orig;
232 else if (
diff >= 2 * threshold)
234 dst[x + y * dst_linesize] = filtered + threshold;
259 s->luma.filter_context);
261 if (
inpic->data[2]) {
264 cw, ch,
s->chroma.threshold,
265 s->chroma.filter_context);
268 cw, ch,
s->chroma.threshold,
269 s->chroma.filter_context);
303 .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.
struct SwsContext * sws_getCachedContext(struct 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.
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
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
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.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
int attribute_align_arg sws_scale(struct SwsContext *c, 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.
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)
static av_cold int init(AVFilterContext *ctx)
A filter pad used for either input or output.
#define AV_CEIL_RSHIFT(a, b)
int length
number of coefficients in the vector
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
@ 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,...
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.
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
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)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int w
agreed upon image width
const char * name
Pad name.
static const AVFilterPad smartblur_outputs[]
static int query_formats(AVFilterContext *ctx)
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int h
agreed upon image height
@ 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 av_always_inline int diff(const uint32_t a, const uint32_t b)
@ 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, size in bytes of each picture line.
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)