21 #include "libavutil/imgutils.h"
22 #include "libavutil/eval.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/pixfmt.h"
64 static const char *
const var_names[] = {
"X",
"Y",
"W",
"H",
"SW",
"SH",
"T",
"N",
"A",
"B",
"TOP",
"BOTTOM", NULL };
65 enum {
VAR_X,
VAR_Y,
VAR_W,
VAR_H,
VAR_SW,
VAR_SH,
VAR_T,
VAR_N,
VAR_A,
VAR_B,
VAR_TOP,
VAR_BOTTOM,
VAR_VARS_NB };
73 const uint8_t *bottom,
int bottom_linesize,
100 #define OFFSET(x) offsetof(BlendContext, x)
101 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
143 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(dinput.shortest),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
151 const uint8_t *bottom,
int bottom_linesize,
152 uint8_t *dst,
int dst_linesize,
159 #define DEFINE_BLEND(name, expr) \
160 static void blend_## name(const uint8_t *top, int top_linesize, \
161 const uint8_t *bottom, int bottom_linesize, \
162 uint8_t *dst, int dst_linesize, \
163 int width, int start, int end, \
164 FilterParams *param, double *values) \
166 double opacity = param->opacity; \
169 for (i = start; i < end; i++) { \
170 for (j = 0; j < width; j++) { \
171 dst[j] = top[j] + ((expr) - top[j]) * opacity; \
173 dst += dst_linesize; \
174 top += top_linesize; \
175 bottom += bottom_linesize; \
182 #define MULTIPLY(x, a, b) (x * ((a * b) / 255))
183 #define SCREEN(x, a, b) (255 - x * ((255 - a) * (255 - b) / 255))
184 #define BURN(a, b) ((a == 0) ? a : FFMAX(0, 255 - ((255 - b) << 8) / a))
185 #define DODGE(a, b) ((a == 255) ? a : FFMIN(255, ((b << 8) / (255 - a))))
195 DEFINE_BLEND(hardlight, (
B < 128) ? MULTIPLY(2,
B, A) : SCREEN(2, B, A))
201 DEFINE_BLEND(softlight, (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 -
FFABS(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 -
FFABS(B - 127.5)/255))
211 static
void blend_expr(const
uint8_t *top,
int top_linesize,
212 const
uint8_t *bottom,
int bottom_linesize,
213 uint8_t *dst,
int dst_linesize,
220 for (y = start; y <
end; y++) {
222 for (x = 0; x <
width; x++) {
230 bottom += bottom_linesize;
237 int slice_start = (td->
h * jobnr ) / nb_jobs;
238 int slice_end = (td->
h * (jobnr+1)) / nb_jobs;
257 td->
w, slice_start, slice_end, td->
param, &values[0]);
275 for (plane = 0; plane < b->
nb_planes; plane++) {
276 int hsub = plane == 1 || plane == 2 ? b->
hsub : 0;
277 int vsub = plane == 1 || plane == 2 ? b->
vsub : 0;
281 ThreadData td = { .top = top_buf, .bottom = bottom_buf, .dst = dst_buf,
282 .w = outw, .h = outh, .param = param, .plane = plane,
306 switch (param->
mode) {
340 NULL, NULL, NULL, NULL, 0, ctx);
343 param->
blend = blend_expr;
377 if (toplink->
w != bottomlink->
w ||
378 toplink->
h != bottomlink->
h ||
382 "(size %dx%d, SAR %d:%d) do not match the corresponding "
383 "second input link %s parameters (%dx%d, SAR %d:%d)\n",
393 outlink->
w = toplink->
w;
394 outlink->
h = toplink->
h;
463 .priv_class = &blend_class,
FFDualInputContext dinput
static AVFrame * blend_frame(AVFilterContext *ctx, AVFrame *top_buf, const AVFrame *bottom_buf)
static const AVOption blend_options[]
static const char *const var_names[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
const char * name
Filter name.
void(* blend)(const uint8_t *top, int top_linesize, const uint8_t *bottom, int bottom_linesize, uint8_t *dst, int dst_linesize, int width, int start, int end, struct FilterParams *param, double *values)
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
int h
agreed upon image height
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
static av_cold void uninit(AVFilterContext *ctx)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
const char * name
Pad name.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define FF_CEIL_RSHIFT(a, b)
static int request_frame(AVFilterLink *outlink)
static double av_q2d(AVRational a)
Convert rational to double.
int nb_threads
Maximum number of threads used by filters in this graph.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static int config_output(AVFilterLink *outlink)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
A filter pad used for either input or output.
A link between two filters.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
planar GBRA 4:4:4:4 32bpp
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
AVFilter avfilter_vf_blend
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
AVPixelFormat
Pixel format.
int w
agreed upon image width
#define FF_ARRAY_ELEMS(a)
static SDL_Surface * screen
static av_cold int init(AVFilterContext *ctx)
AVFrame *(* process)(AVFilterContext *ctx, AVFrame *main, const AVFrame *second)
int format
agreed upon media format
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
AVFilterLink ** outputs
array of pointers to output links
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
typedef void(RENAME(mix_any_func_type))
AVFilterPad * input_pads
array of input pads
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const AVFilterPad blend_inputs[]
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
static void blend_normal(const uint8_t *top, int top_linesize, const uint8_t *bottom, int bottom_linesize, uint8_t *dst, int dst_linesize, int width, int start, int end, FilterParams *param, double *values)
const char const char * params
int vsub
chroma subsampling values
struct AVFilterGraph * graph
filtergraph this filter belongs to
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#define AVFILTER_DEFINE_CLASS(fname)
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
#define MULTIPLY(x, a, b)
static const AVFilterPad blend_outputs[]
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int query_formats(AVFilterContext *ctx)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int64_t frame_count
Number of past frames sent through the link.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define DEFINE_BLEND(name, expr)