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
101 "luma_radius:%f luma_strength:%f luma_threshold:%d "
102 "chroma_radius:%f chroma_strength:%f chroma_threshold:%d\n",
145 sws_filter.
lumH = sws_filter.
lumV = vec;
179 const int w,
const int h,
const int threshold,
186 const uint8_t*
const src_array[4] = {src};
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;
261 if (inpic->
data[2]) {
301 .
inputs = smartblur_inputs,
303 .priv_class = &smartblur_class,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
AVFILTER_DEFINE_CLASS(smartblur)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality, lower is lower quality.
int h
agreed upon image height
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.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int length
number of coefficients in the vector
#define AV_LOG_VERBOSE
Detailed information.
struct SwsContext * filter_context
A filter pad used for either input or output.
A link between two filters.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static int config_props(AVFilterLink *inlink)
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
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
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.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
static int alloc_sws_context(FilterParam *f, int width, int height, unsigned int flags)
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
static int query_formats(AVFilterContext *ctx)
static const AVOption smartblur_options[]
static const AVFilterPad outputs[]
int format
agreed upon media format
double * coeff
pointer to the list of coefficients
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const AVFilterPad smartblur_inputs[]
void sws_freeVec(SwsVector *a)
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.
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
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_always_inline int diff(const uint32_t a, const uint32_t b)
AVFilterContext * dst
dest filter
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static const AVFilterPad smartblur_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
AVPixelFormat
Pixel format.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_CEIL_RSHIFT(a, b)
static av_cold int init(AVFilterContext *ctx)