48#define MIN_MATRIX_SIZE 3
49#define MAX_MATRIX_SIZE 63
80typedef struct TheadData {
90#define DEF_UNSHARP_SLICE_FUNC(name, nbits) \
91static int name##_##nbits(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
93 ThreadData *td = arg; \
94 UnsharpFilterParam *fp = td->fp; \
95 UnsharpContext *s = ctx->priv; \
96 uint32_t **sc = fp->sc; \
97 uint32_t *sr = fp->sr; \
98 const uint##nbits##_t *src2 = NULL; \
99 const int amount = fp->amount; \
100 const int steps_x = fp->steps_x; \
101 const int steps_y = fp->steps_y; \
102 const int scalebits = fp->scalebits; \
103 const int32_t halfscale = fp->halfscale; \
105 uint##nbits##_t *dst = (uint##nbits##_t*)td->dst; \
106 const uint##nbits##_t *src = (const uint##nbits##_t *)td->src; \
107 int dst_stride = td->dst_stride; \
108 int src_stride = td->src_stride; \
109 const int width = td->width; \
110 const int height = td->height; \
111 const int sc_offset = jobnr * 2 * steps_y; \
112 const int sr_offset = jobnr * (MAX_MATRIX_SIZE - 1); \
113 const int slice_start = ff_slice_pos(height, jobnr, nb_jobs); \
114 const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs); \
118 uint32_t tmp1, tmp2; \
121 av_image_copy_plane(td->dst + slice_start * dst_stride, dst_stride, \
122 td->src + slice_start * src_stride, src_stride, \
123 width * s->bps, slice_end - slice_start); \
127 for (y = 0; y < 2 * steps_y; y++) \
128 memset(sc[sc_offset + y], 0, sizeof(sc[y][0]) * (width + 2 * steps_x)); \
130 dst_stride = dst_stride / s->bps; \
131 src_stride = src_stride / s->bps; \
134 if (slice_start > steps_y) { \
135 src += (slice_start - steps_y) * src_stride; \
136 dst += (slice_start - steps_y) * dst_stride; \
139 for (y = -steps_y + slice_start; y < steps_y + slice_end; y++) { \
143 memset(sr + sr_offset, 0, sizeof(sr[0]) * (2 * steps_x - 1)); \
144 for (x = -steps_x; x < width + steps_x; x++) { \
145 tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x]; \
146 for (z = 0; z < steps_x * 2; z += 2) { \
147 tmp2 = sr[sr_offset + z + 0] + tmp1; sr[sr_offset + z + 0] = tmp1; \
148 tmp1 = sr[sr_offset + z + 1] + tmp2; sr[sr_offset + z + 1] = tmp2; \
150 for (z = 0; z < steps_y * 2; z += 2) { \
151 tmp2 = sc[sc_offset + z + 0][x + steps_x] + tmp1; \
152 sc[sc_offset + z + 0][x + steps_x] = tmp1; \
153 tmp1 = sc[sc_offset + z + 1][x + steps_x] + tmp2; \
154 sc[sc_offset + z + 1][x + steps_x] = tmp2; \
156 if (x >= steps_x && y >= (steps_y + slice_start)) { \
157 const uint##nbits##_t *srx = src - steps_y * src_stride + x - steps_x; \
158 uint##nbits##_t *dsx = dst - steps_y * dst_stride + x - steps_x; \
160 res = (int32_t)*srx + (int32_t)(((int64_t)((int32_t)*srx - \
161 (int32_t)((tmp1 + halfscale) >> scalebits)) * amount) >> 16); \
162 *dsx = av_clip_uintp2(res, s->bitdepth); \
179 int i, plane_w[4], plane_h[4];
183 plane_w[0] = plane_w[3] = inlink->
w;
185 plane_h[0] = plane_h[3] = inlink->
h;
188 fp[1] = fp[2] = &
s->chroma;
190 for (
i = 0;
i <
s->nb_planes;
i++) {
193 td.
src = in->data[
i];
199 FFMIN(plane_h[
i],
s->nb_threads));
204#define MAX_SCALEBITS 25
211 fp->
amount = amount * 65536.0;
232#define SET_FILTER_PARAM(name_, short_) \
233 ret = set_filter_param(ctx, #name_, #short_, &s->name_, \
234 s->short_##msize_x, s->short_##msize_y, s->short_##amount); \
263 const char *effect = fp->
amount == 0 ?
"none" : fp->
amount < 0 ?
"blur" :
"sharpen";
267 "Invalid even size for %s matrix size %dx%d\n",
277 if (!fp->
sr || !fp->
sc)
280 for (z = 0; z < 2 * fp->
steps_y *
s->nb_threads; z++)
282 sizeof(*(fp->
sc[z])))))
294 s->nb_planes =
desc->nb_components;
295 s->hsub =
desc->log2_chroma_w;
296 s->vsub =
desc->log2_chroma_h;
297 s->bitdepth =
desc->comp[0].depth;
298 s->bps =
s->bitdepth > 8 ? 2 : 1;
299 s->unsharp_slice =
s->bitdepth > 8 ? unsharp_slice_16 : unsharp_slice_8;
304 inlink->
h / (4 *
s->luma.steps_y));
321 for (z = 0; z < 2 * fp->
steps_y * nb_threads; z++)
360#define OFFSET(x) offsetof(UnsharpContext, x)
361#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
400 .p.priv_class = &unsharp_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_unsharp
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
common internal and external API header
#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...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
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_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ 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_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ 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_YUVA422P12
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Used for passing data between threads.
UnsharpFilterParam luma
luma parameters (width, height, amount)
UnsharpFilterParam chroma
chroma parameters (width, height, amount)
int(* unsharp_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
UnsharpFilterParam alpha
alpha parameters (width, height, amount)
int32_t halfscale
amount to add to pixel
int steps_y
vertical step count
uint32_t * sr
finite state machine storage within a row
uint32_t ** sc
finite state machine storage across rows
int steps_x
horizontal step count
int scalebits
bits to shift pixel
#define av_malloc_array(a, b)
static AVFormatContext * ctx
static int apply_unsharp(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
static void free_filter_param(UnsharpFilterParam *fp, int nb_threads)
static int filter_frame(AVFilterLink *link, AVFrame *in)
static const AVFilterPad avfilter_vf_unsharp_inputs[]
static int config_input(AVFilterLink *inlink)
static int init_filter_param(AVFilterContext *ctx, UnsharpFilterParam *fp, const char *effect_type, int width)
static int set_filter_param(AVFilterContext *ctx, const char *name, const char *short_name, UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
static av_cold void uninit(AVFilterContext *ctx)
#define DEF_UNSHARP_SLICE_FUNC(name, nbits)
#define SET_FILTER_PARAM(name_, short_)
static const AVOption unsharp_options[]
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.