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;
189static 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;
270 inlink->
w, inlink->
h,
s->luma.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]) {
287 inlink->
w, inlink->
h,
s->alpha.threshold,
288 s->alpha.filter_context);
305 .p.name =
"smartblur",
307 .p.priv_class = &smartblur_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vf_smartblur
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define flags(name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_VERBOSE
Detailed information.
void sws_freeVec(SwsVector *a)
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
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.
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.
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
@ SWS_BICUBIC
2-tap cubic B-spline
static const int16_t alpha[]
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static int config_props(AVBitStreamFilterLink *link)
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
struct SwsContext * filter_context
Main external API structure.
double * coeff
pointer to the list of coefficients
int length
number of coefficients in the vector
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static int alloc_sws_context(FilterParam *f, int width, int height, unsigned int flags)
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
static int config_props(AVFilterLink *inlink)
static const AVOption smartblur_options[]
static av_cold void uninit(AVFilterContext *ctx)
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 const AVFilterPad smartblur_inputs[]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.