Go to the documentation of this file.
60 #define DEF_UNSHARP_SLICE_FUNC(name, nbits) \
61 static int name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
63 ThreadData *td = arg; \
64 UnsharpFilterParam *fp = td->fp; \
65 UnsharpContext *s = ctx->priv; \
66 uint32_t **sc = fp->sc; \
67 uint32_t *sr = fp->sr; \
68 const uint##nbits##_t *src2 = NULL; \
69 const int amount = fp->amount; \
70 const int steps_x = fp->steps_x; \
71 const int steps_y = fp->steps_y; \
72 const int scalebits = fp->scalebits; \
73 const int32_t halfscale = fp->halfscale; \
75 uint##nbits##_t *dst = (uint##nbits##_t*)td->dst; \
76 const uint##nbits##_t *src = (const uint##nbits##_t *)td->src; \
77 int dst_stride = td->dst_stride; \
78 int src_stride = td->src_stride; \
79 const int width = td->width; \
80 const int height = td->height; \
81 const int sc_offset = jobnr * 2 * steps_y; \
82 const int sr_offset = jobnr * (MAX_MATRIX_SIZE - 1); \
83 const int slice_start = (height * jobnr) / nb_jobs; \
84 const int slice_end = (height * (jobnr+1)) / nb_jobs; \
88 uint32_t tmp1, tmp2; \
91 av_image_copy_plane(td->dst + slice_start * dst_stride, dst_stride, \
92 td->src + slice_start * src_stride, src_stride, \
93 width * s->bps, slice_end - slice_start); \
97 for (y = 0; y < 2 * steps_y; y++) \
98 memset(sc[sc_offset + y], 0, sizeof(sc[y][0]) * (width + 2 * steps_x)); \
100 dst_stride = dst_stride / s->bps; \
101 src_stride = src_stride / s->bps; \
104 if (slice_start > steps_y) { \
105 src += (slice_start - steps_y) * src_stride; \
106 dst += (slice_start - steps_y) * dst_stride; \
109 for (y = -steps_y + slice_start; y < steps_y + slice_end; y++) { \
113 memset(sr + sr_offset, 0, sizeof(sr[0]) * (2 * steps_x - 1)); \
114 for (x = -steps_x; x < width + steps_x; x++) { \
115 tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x]; \
116 for (z = 0; z < steps_x * 2; z += 2) { \
117 tmp2 = sr[sr_offset + z + 0] + tmp1; sr[sr_offset + z + 0] = tmp1; \
118 tmp1 = sr[sr_offset + z + 1] + tmp2; sr[sr_offset + z + 1] = tmp2; \
120 for (z = 0; z < steps_y * 2; z += 2) { \
121 tmp2 = sc[sc_offset + z + 0][x + steps_x] + tmp1; \
122 sc[sc_offset + z + 0][x + steps_x] = tmp1; \
123 tmp1 = sc[sc_offset + z + 1][x + steps_x] + tmp2; \
124 sc[sc_offset + z + 1][x + steps_x] = tmp2; \
126 if (x >= steps_x && y >= (steps_y + slice_start)) { \
127 const uint##nbits##_t *srx = src - steps_y * src_stride + x - steps_x; \
128 uint##nbits##_t *dsx = dst - steps_y * dst_stride + x - steps_x; \
130 res = (int32_t)*srx + ((((int32_t) * srx - \
131 (int32_t)((tmp1 + halfscale) >> scalebits)) * amount) >> (8+nbits)); \
132 *dsx = av_clip_uint##nbits(res); \
149 int i, plane_w[3], plane_h[3];
158 fp[1] =
fp[2] = &
s->chroma;
159 for (
i = 0;
i < 3;
i++) {
162 td.src = in->data[
i];
163 td.width = plane_w[
i];
164 td.height = plane_h[
i];
165 td.dst_stride =
out->linesize[
i];
166 td.src_stride = in->linesize[
i];
168 FFMIN(plane_h[
i],
s->nb_threads));
175 fp->msize_x = msize_x;
176 fp->msize_y = msize_y;
177 fp->amount = amount * 65536.0;
179 fp->steps_x = msize_x / 2;
180 fp->steps_y = msize_y / 2;
181 fp->scalebits = (
fp->steps_x +
fp->steps_y) * 2;
182 fp->halfscale = 1 << (
fp->scalebits - 1);
192 if (
s->luma.scalebits >= 26 ||
s->chroma.scalebits >= 26) {
214 const char *effect =
fp->amount == 0 ?
"none" :
fp->amount < 0 ?
"blur" :
"sharpen";
216 if (!(
fp->msize_x &
fp->msize_y & 1)) {
218 "Invalid even size for %s matrix size %dx%d\n",
219 effect_type,
fp->msize_x,
fp->msize_y);
224 effect, effect_type,
fp->msize_x,
fp->msize_y,
fp->amount / 65535.0);
228 if (!
fp->sr || !
fp->sc)
231 for (z = 0; z < 2 *
fp->steps_y *
s->nb_threads; z++)
233 sizeof(*(
fp->sc[z])))))
245 s->hsub =
desc->log2_chroma_w;
246 s->vsub =
desc->log2_chroma_h;
247 s->bitdepth =
desc->comp[0].depth;
248 s->bps =
s->bitdepth > 8 ? 2 : 1;
249 s->unsharp_slice =
s->bitdepth > 8 ? unsharp_slice_16 : unsharp_slice_8;
254 inlink->h / (4 *
s->luma.steps_y));
271 for (z = 0; z < 2 *
fp->steps_y * nb_threads; z++)
311 #define OFFSET(x) offsetof(UnsharpContext, x)
312 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
354 .priv_class = &unsharp_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVPixelFormat
Pixel format.
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
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)
#define FILTER_PIXFMTS_ARRAY(array)
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 av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
const AVFilter ff_vf_unsharp
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUV420P10
#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.
static int apply_unsharp_c(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
A link between two filters.
static av_cold void uninit(AVFilterContext *ctx)
static int filter_frame(AVFilterLink *link, AVFrame *in)
static int config_input(AVFilterLink *inlink)
#define AV_PIX_FMT_YUV422P9
static av_cold int init(AVFilterContext *ctx)
A filter pad used for either input or output.
static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
#define AV_PIX_FMT_YUV444P10
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
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 link
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static void free_filter_param(UnsharpFilterParam *fp, int nb_threads)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV422P10
static int init_filter_param(AVFilterContext *ctx, UnsharpFilterParam *fp, const char *effect_type, int width)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define DEF_UNSHARP_SLICE_FUNC(name, nbits)
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
static const AVOption unsharp_options[]
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define i(width, name, range_min, range_max)
static const AVFilterPad avfilter_vf_unsharp_outputs[]
int w
agreed upon image width
#define av_malloc_array(a, b)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define AV_PIX_FMT_YUV444P9
AVFILTER_DEFINE_CLASS(unsharp)
#define AV_PIX_FMT_YUV420P12
int h
agreed upon image height
static const AVFilterPad avfilter_vf_unsharp_inputs[]
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define AV_PIX_FMT_YUV440P12
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)