FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_blend.c File Reference
#include "libavutil/imgutils.h"
#include "libavutil/intfloat.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"
#include "formats.h"
#include "framesync.h"
#include "internal.h"
#include "video.h"
#include "blend.h"

Go to the source code of this file.

Data Structures

struct  BlendContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

Macros

#define TOP   0
 
#define BOTTOM   1
 
#define COMMON_OPTIONS
 
#define OFFSET(x)   offsetof(BlendContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define COPY(src, depth)
 
#define DEFINE_BLEND8(name, expr)
 
#define DEFINE_BLEND16(name, expr, depth)
 
#define DEFINE_BLEND32(name, expr, depth)
 
#define A   top[j]
 
#define B   bottom[j]
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 255))
 
#define SCREEN(x, a, b)   (255 - (x) * ((255 - (a)) * (255 - (b)) / 255))
 
#define BURN(a, b)   (((a) == 0) ? (a) : FFMAX(0, 255 - ((255 - (b)) << 8) / (a)))
 
#define DODGE(a, b)   (((a) == 255) ? (a) : FFMIN(255, (((b) << 8) / (255 - (a)))))
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 65535))
 
#define SCREEN(x, a, b)   (65535 - (x) * ((65535 - (a)) * (65535 - (b)) / 65535))
 
#define BURN(a, b)   (((a) == 0) ? (a) : FFMAX(0, 65535 - ((65535 - (b)) << 16) / (a)))
 
#define DODGE(a, b)   (((a) == 65535) ? (a) : FFMIN(65535, (((b) << 16) / (65535 - (a)))))
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 1023))
 
#define SCREEN(x, a, b)   (1023 - (x) * ((1023 - (a)) * (1023 - (b)) / 1023))
 
#define BURN(a, b)   (((a) == 0) ? (a) : FFMAX(0, 1023 - ((1023 - (b)) << 10) / (a)))
 
#define DODGE(a, b)   (((a) == 1023) ? (a) : FFMIN(1023, (((b) << 10) / (1023 - (a)))))
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 4095))
 
#define SCREEN(x, a, b)   (4095 - (x) * ((4095 - (a)) * (4095 - (b)) / 4095))
 
#define BURN(a, b)   (((a) == 0) ? (a) : FFMAX(0, 4095 - ((4095 - (b)) << 12) / (a)))
 
#define DODGE(a, b)   (((a) == 4095) ? (a) : FFMIN(4095, (((b) << 12) / (4095 - (a)))))
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 511))
 
#define SCREEN(x, a, b)   (511 - (x) * ((511 - (a)) * (511 - (b)) / 511))
 
#define BURN(a, b)   (((a) == 0) ? (a) : FFMAX(0, 511 - ((511 - (b)) << 9) / (a)))
 
#define DODGE(a, b)   (((a) == 511) ? (a) : FFMIN(511, (((b) << 9) / (511 - (a)))))
 
#define MULTIPLY(x, a, b)   ((x) * (((a) * (b)) / 1.0))
 
#define SCREEN(x, a, b)   (1.0 - (x) * ((1.0 - (a)) * (1.0 - (b)) / 1.0))
 
#define BURN(a, b)   (((a) <= 0.0) ? (a) : FFMAX(0.0, 1.0 - (1.0 - (b)) / (a)))
 
#define DODGE(a, b)   (((a) >= 1.0) ? (a) : FFMIN(1.0, ((b) / (1.0 - (a)))))
 
#define DEFINE_BLEND_EXPR(type, name, div)
 
#define DEFINE_INIT_BLEND_FUNC(depth, nbits)
 

Enumerations

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
}
 

Functions

 FRAMESYNC_DEFINE_CLASS (blend, BlendContext, fs)
 
static void blend_normal_8bit (const uint8_t *top, ptrdiff_t top_linesize, const uint8_t *bottom, ptrdiff_t bottom_linesize, uint8_t *dst, ptrdiff_t dst_linesize, ptrdiff_t width, ptrdiff_t height, FilterParams *param, double *values, int starty)
 
static void blend_normal_16bit (const uint8_t *_top, ptrdiff_t top_linesize, const uint8_t *_bottom, ptrdiff_t bottom_linesize, uint8_t *_dst, ptrdiff_t dst_linesize, ptrdiff_t width, ptrdiff_t height, FilterParams *param, double *values, int starty)
 
static void blend_normal_32bit (const uint8_t *_top, ptrdiff_t top_linesize, const uint8_t *_bottom, ptrdiff_t bottom_linesize, uint8_t *_dst, ptrdiff_t dst_linesize, ptrdiff_t width, ptrdiff_t height, FilterParams *param, double *values, int starty)
 
 DEFINE_BLEND8 (multiply128, av_clip_uint8((A - 128) *B/32.+128))
 
static AVFrameblend_frame (AVFilterContext *ctx, AVFrame *top_buf, const AVFrame *bottom_buf)
 
static int blend_frame_for_dualinput (FFFrameSync *fs)
 
static av_cold int init (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
void ff_blend_init (FilterParams *param, int depth)
 
static int config_output (AVFilterLink *outlink)
 

Variables

static const char *const var_names [] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL }
 
static const AVOption blend_options []
 

Macro Definition Documentation

◆ TOP

#define TOP   0

Definition at line 33 of file vf_blend.c.

◆ BOTTOM

#define BOTTOM   1

Definition at line 34 of file vf_blend.c.

◆ COMMON_OPTIONS

#define COMMON_OPTIONS

Definition at line 63 of file vf_blend.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(BlendContext, x)

Definition at line 115 of file vf_blend.c.

◆ FLAGS

Definition at line 116 of file vf_blend.c.

◆ COPY

#define COPY (   src,
  depth 
)
Value:
static void blend_copy ## src##_##depth(const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize,\
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, double *values, int starty) \
{ \
av_image_copy_plane(dst, dst_linesize, src, src ## _linesize, \
width * depth / 8, height); \
}

Definition at line 125 of file vf_blend.c.

◆ DEFINE_BLEND8

#define DEFINE_BLEND8 (   name,
  expr 
)
Value:
static void blend_## name##_8bit(const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, double *values, int starty) \
{ \
double opacity = param->opacity; \
int i, j; \
for (i = 0; i < height; i++) { \
for (j = 0; j < width; j++) { \
dst[j] = top[j] + ((expr) - top[j]) * opacity; \
} \
dst += dst_linesize; \
top += top_linesize; \
bottom += bottom_linesize; \
} \
}

Definition at line 216 of file vf_blend.c.

◆ DEFINE_BLEND16

#define DEFINE_BLEND16 (   name,
  expr,
  depth 
)
Value:
static void blend_## name##_##depth##bit(const uint8_t *_top, ptrdiff_t top_linesize,\
const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
uint8_t *_dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, double *values, int starty) \
{ \
const uint16_t *top = (const uint16_t*)_top; \
const uint16_t *bottom = (const uint16_t*)_bottom; \
uint16_t *dst = (uint16_t*)_dst; \
double opacity = param->opacity; \
int i, j; \
dst_linesize /= 2; \
top_linesize /= 2; \
bottom_linesize /= 2; \
for (i = 0; i < height; i++) { \
for (j = 0; j < width; j++) { \
dst[j] = top[j] + ((expr) - top[j]) * opacity; \
} \
dst += dst_linesize; \
top += top_linesize; \
bottom += bottom_linesize; \
} \
}

Definition at line 236 of file vf_blend.c.

◆ DEFINE_BLEND32

#define DEFINE_BLEND32 (   name,
  expr,
  depth 
)
Value:
static void blend_## name##_##depth##bit(const uint8_t *_top, ptrdiff_t top_linesize,\
const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
uint8_t *_dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, double *values, int starty) \
{ \
const float *top = (const float*)_top; \
const float *bottom = (const float*)_bottom; \
float *dst = (float*)_dst; \
double opacity = param->opacity; \
int i, j; \
dst_linesize /= 4; \
top_linesize /= 4; \
bottom_linesize /= 4; \
for (i = 0; i < height; i++) { \
for (j = 0; j < width; j++) { \
dst[j] = top[j] + ((expr) - top[j]) * opacity; \
} \
dst += dst_linesize; \
top += top_linesize; \
bottom += bottom_linesize; \
} \
}

Definition at line 262 of file vf_blend.c.

◆ A

#define A   top[j]

Definition at line 288 of file vf_blend.c.

◆ B

#define B   bottom[j]

Definition at line 289 of file vf_blend.c.

◆ MULTIPLY [1/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 255))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [1/6]

#define SCREEN (   x,
  a,
  b 
)    (255 - (x) * ((255 - (a)) * (255 - (b)) / 255))

Definition at line 292 of file vf_blend.c.

◆ BURN [1/6]

#define BURN (   a,
  b 
)    (((a) == 0) ? (a) : FFMAX(0, 255 - ((255 - (b)) << 8) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [1/6]

#define DODGE (   a,
  b 
)    (((a) == 255) ? (a) : FFMIN(255, (((b) << 8) / (255 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ MULTIPLY [2/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 65535))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [2/6]

#define SCREEN (   x,
  a,
  b 
)    (65535 - (x) * ((65535 - (a)) * (65535 - (b)) / 65535))

Definition at line 292 of file vf_blend.c.

◆ BURN [2/6]

#define BURN (   a,
  b 
)    (((a) == 0) ? (a) : FFMAX(0, 65535 - ((65535 - (b)) << 16) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [2/6]

#define DODGE (   a,
  b 
)    (((a) == 65535) ? (a) : FFMIN(65535, (((b) << 16) / (65535 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ MULTIPLY [3/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 1023))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [3/6]

#define SCREEN (   x,
  a,
  b 
)    (1023 - (x) * ((1023 - (a)) * (1023 - (b)) / 1023))

Definition at line 292 of file vf_blend.c.

◆ BURN [3/6]

#define BURN (   a,
  b 
)    (((a) == 0) ? (a) : FFMAX(0, 1023 - ((1023 - (b)) << 10) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [3/6]

#define DODGE (   a,
  b 
)    (((a) == 1023) ? (a) : FFMIN(1023, (((b) << 10) / (1023 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ MULTIPLY [4/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 4095))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [4/6]

#define SCREEN (   x,
  a,
  b 
)    (4095 - (x) * ((4095 - (a)) * (4095 - (b)) / 4095))

Definition at line 292 of file vf_blend.c.

◆ BURN [4/6]

#define BURN (   a,
  b 
)    (((a) == 0) ? (a) : FFMAX(0, 4095 - ((4095 - (b)) << 12) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [4/6]

#define DODGE (   a,
  b 
)    (((a) == 4095) ? (a) : FFMIN(4095, (((b) << 12) / (4095 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ MULTIPLY [5/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 511))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [5/6]

#define SCREEN (   x,
  a,
  b 
)    (511 - (x) * ((511 - (a)) * (511 - (b)) / 511))

Definition at line 292 of file vf_blend.c.

◆ BURN [5/6]

#define BURN (   a,
  b 
)    (((a) == 0) ? (a) : FFMAX(0, 511 - ((511 - (b)) << 9) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [5/6]

#define DODGE (   a,
  b 
)    (((a) == 511) ? (a) : FFMIN(511, (((b) << 9) / (511 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ MULTIPLY [6/6]

#define MULTIPLY (   x,
  a,
  b 
)    ((x) * (((a) * (b)) / 1.0))

Definition at line 291 of file vf_blend.c.

◆ SCREEN [6/6]

#define SCREEN (   x,
  a,
  b 
)    (1.0 - (x) * ((1.0 - (a)) * (1.0 - (b)) / 1.0))

Definition at line 292 of file vf_blend.c.

◆ BURN [6/6]

#define BURN (   a,
  b 
)    (((a) <= 0.0) ? (a) : FFMAX(0.0, 1.0 - (1.0 - (b)) / (a)))

Definition at line 293 of file vf_blend.c.

◆ DODGE [6/6]

#define DODGE (   a,
  b 
)    (((a) >= 1.0) ? (a) : FFMIN(1.0, ((b) / (1.0 - (a)))))

Definition at line 294 of file vf_blend.c.

◆ DEFINE_BLEND_EXPR

#define DEFINE_BLEND_EXPR (   type,
  name,
  div 
)
Value:
static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \
const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
uint8_t *_dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, double *values, int starty) \
{ \
const type *top = (type*)_top; \
const type *bottom = (type*)_bottom; \
type *dst = (type*)_dst; \
AVExpr *e = param->e; \
int y, x; \
dst_linesize /= div; \
top_linesize /= div; \
bottom_linesize /= div; \
for (y = 0; y < height; y++) { \
values[VAR_Y] = y + starty; \
for (x = 0; x < width; x++) { \
values[VAR_X] = x; \
values[VAR_TOP] = values[VAR_A] = top[x]; \
values[VAR_BOTTOM] = values[VAR_B] = bottom[x]; \
dst[x] = av_expr_eval(e, values, NULL); \
} \
dst += dst_linesize; \
top += top_linesize; \
bottom += bottom_linesize; \
} \
}

◆ DEFINE_INIT_BLEND_FUNC

#define DEFINE_INIT_BLEND_FUNC (   depth,
  nbits 
)

Definition at line 704 of file vf_blend.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
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 

Definition at line 52 of file vf_blend.c.

Function Documentation

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( blend  ,
BlendContext  ,
fs   
)

◆ blend_normal_8bit()

static void blend_normal_8bit ( const uint8_t top,
ptrdiff_t  top_linesize,
const uint8_t bottom,
ptrdiff_t  bottom_linesize,
uint8_t dst,
ptrdiff_t  dst_linesize,
ptrdiff_t  width,
ptrdiff_t  height,
FilterParams param,
double *  values,
int  starty 
)
static

Definition at line 147 of file vf_blend.c.

◆ blend_normal_16bit()

static void blend_normal_16bit ( const uint8_t _top,
ptrdiff_t  top_linesize,
const uint8_t _bottom,
ptrdiff_t  bottom_linesize,
uint8_t _dst,
ptrdiff_t  dst_linesize,
ptrdiff_t  width,
ptrdiff_t  height,
FilterParams param,
double *  values,
int  starty 
)
static

Definition at line 166 of file vf_blend.c.

◆ blend_normal_32bit()

static void blend_normal_32bit ( const uint8_t _top,
ptrdiff_t  top_linesize,
const uint8_t _bottom,
ptrdiff_t  bottom_linesize,
uint8_t _dst,
ptrdiff_t  dst_linesize,
ptrdiff_t  width,
ptrdiff_t  height,
FilterParams param,
double *  values,
int  starty 
)
static

Definition at line 191 of file vf_blend.c.

◆ DEFINE_BLEND8()

DEFINE_BLEND8 ( multiply128  ,
av_clip_uint8((A - 128) *B/32.+128)   
)

Definition at line 301 of file vf_blend.c.

◆ blend_frame()

static AVFrame* blend_frame ( AVFilterContext ctx,
AVFrame top_buf,
const AVFrame bottom_buf 
)
static

Definition at line 606 of file vf_blend.c.

Referenced by blend_frame_for_dualinput().

◆ blend_frame_for_dualinput()

static int blend_frame_for_dualinput ( FFFrameSync fs)
static

Definition at line 639 of file vf_blend.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 654 of file vf_blend.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 664 of file vf_blend.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 692 of file vf_blend.c.

◆ ff_blend_init()

void ff_blend_init ( FilterParams param,
int  depth 
)

Definition at line 750 of file vf_blend.c.

Referenced by config_output().

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 786 of file vf_blend.c.

Variable Documentation

◆ var_names

const char* const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL }
static

Definition at line 51 of file vf_blend.c.

Referenced by config_output().

◆ blend_options

const AVOption blend_options[]
static
Initial value:
= {
{ NULL }
}

Definition at line 118 of file vf_blend.c.

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
COMMON_OPTIONS
#define COMMON_OPTIONS
Definition: vf_blend.c:63
VAR_B
@ VAR_B
Definition: vf_blend.c:52
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
width
#define width
VAR_BOTTOM
@ VAR_BOTTOM
Definition: vf_blend.c:52
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
VAR_X
@ VAR_X
Definition: vf_blend.c:52
NULL
#define NULL
Definition: coverity.c:32
VAR_A
@ VAR_A
Definition: vf_blend.c:52
src
#define src
Definition: vp8dsp.c:254
VAR_Y
@ VAR_Y
Definition: vf_blend.c:52
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
FilterParams
filter data
Definition: mlp.h:74
height
#define height
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
uint8_t
uint8_t
Definition: audio_convert.c:194
VAR_TOP
@ VAR_TOP
Definition: vf_blend.c:52
values
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Definition: filter_design.txt:263
_
#define _