63 static const char *
const var_names[] = {
"X",
"Y",
"W",
"H",
"SW",
"SH",
"T",
"A",
"B",
"TOP",
"BOTTOM",
NULL };
64 enum {
VAR_X,
VAR_Y,
VAR_W,
VAR_H,
VAR_SW,
VAR_SH,
VAR_T,
VAR_A,
VAR_B,
VAR_TOP,
VAR_BOTTOM,
VAR_VARS_NB };
73 const uint8_t *bottom,
int bottom_linesize,
91 #define OFFSET(x) offsetof(BlendContext, x)
92 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
140 const uint8_t *bottom,
int bottom_linesize,
147 #define DEFINE_BLEND(name, expr) \
148 static void blend_## name(const uint8_t *top, int top_linesize, \
149 const uint8_t *bottom, int bottom_linesize, \
150 uint8_t *dst, int dst_linesize, \
151 int width, int height, FilterParams *param) \
153 double opacity = param->opacity; \
156 for (i = 0; i < height; i++) { \
157 for (j = 0; j < width; j++) { \
158 dst[j] = top[j] + ((expr) - top[j]) * opacity; \
160 dst += dst_linesize; \
161 top += top_linesize; \
162 bottom += bottom_linesize; \
169 #define MULTIPLY(x, a, b) (x * ((a * b) / 255))
170 #define SCREEN(x, a, b) (255 - x * ((255 - a) * (255 - b) / 255))
171 #define BURN(a, b) ((a == 0) ? a : FFMAX(0, 255 - ((255 - b) << 8) / a))
172 #define DODGE(a, b) ((a == 255) ? a : FFMIN(255, ((b << 8) / (255 - a))))
182 DEFINE_BLEND(hardlight, (
B < 128) ? MULTIPLY(2,
B, A) : SCREEN(2, B, A))
188 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))
198 static
void blend_expr(const
uint8_t *top,
int top_linesize,
199 const
uint8_t *bottom,
int bottom_linesize,
205 double *values = param->values;
208 for (y = 0; y <
height; y++) {
210 for (x = 0; x <
width; x++) {
218 bottom += bottom_linesize;
227 b->
class = &blend_class;
241 switch (param->
mode) {
278 param->
blend = blend_expr;
307 if (toplink->
w != bottomlink->
w ||
308 toplink->
h != bottomlink->
h ||
312 "(size %dx%d, SAR %d:%d) do not match the corresponding "
313 "second input link %s parameters (%dx%d, SAR %d:%d)\n",
323 outlink->
w = toplink->
w;
324 outlink->
h = bottomlink->
h;
380 for (plane = 0; dst_buf->
data[plane]; plane++) {
381 int hsub = plane == 1 || plane == 2 ? b->
hsub : 0;
382 int vsub = plane == 1 || plane == 2 ? b->
vsub : 0;
383 int outw = dst_buf->
video->
w >> hsub;
384 int outh = dst_buf->
video->
h >> vsub;
389 param = &b->
params[plane];
396 bottom, bottom_buf->
linesize[plane],
397 dst, dst_buf->
linesize[plane], outw, outh, param);
423 outlink->
w, outlink->
h);
473 .priv_class = &blend_class,