avfilter/vf_blend: add geometric mode

This commit is contained in:
Paul B Mahol 2021-09-29 19:10:29 +02:00
parent f3b07b8b12
commit 8ebcff9111
4 changed files with 8 additions and 0 deletions

View File

@ -7543,6 +7543,7 @@ Available values for component modes are:
@item freeze @item freeze
@item exclusion @item exclusion
@item extremity @item extremity
@item geometric
@item glow @item glow
@item hardlight @item hardlight
@item hardmix @item hardmix

View File

@ -60,6 +60,7 @@ enum BlendMode {
BLEND_FREEZE, BLEND_FREEZE,
BLEND_EXTREMITY, BLEND_EXTREMITY,
BLEND_SOFTDIFFERENCE, BLEND_SOFTDIFFERENCE,
BLEND_GEOMETRIC,
BLEND_NB BLEND_NB
}; };

View File

@ -52,6 +52,7 @@
#undef SCREEN #undef SCREEN
#undef BURN #undef BURN
#undef DODGE #undef DODGE
#undef GEOMETRIC
#undef INT2FLOAT #undef INT2FLOAT
#undef FLOAT2INT #undef FLOAT2INT
#undef MDIV #undef MDIV
@ -61,6 +62,7 @@
#define SCREEN(x, a, b) (MAX - (x) * ((MAX - (a)) * (MAX - (b)) / MAX)) #define SCREEN(x, a, b) (MAX - (x) * ((MAX - (a)) * (MAX - (b)) / MAX))
#define BURN(a, b) (((a) == 0) ? (a) : FFMAX(0, MAX - ((MAX - (b)) << DEPTH) / (a))) #define BURN(a, b) (((a) == 0) ? (a) : FFMAX(0, MAX - ((MAX - (b)) << DEPTH) / (a)))
#define DODGE(a, b) (((a) == MAX) ? (a) : FFMIN(MAX, (((b) << DEPTH) / (MAX - (a))))) #define DODGE(a, b) (((a) == MAX) ? (a) : FFMIN(MAX, (((b) << DEPTH) / (MAX - (a)))))
#define GEOMETRIC(a, b) (lrintf(sqrtf((unsigned)A * B)))
#define INT2FLOAT(x) (x) #define INT2FLOAT(x) (x)
#define FLOAT2INT(x) (x) #define FLOAT2INT(x) (x)
#define MDIV (0.125f * (1 << DEPTH)) #define MDIV (0.125f * (1 << DEPTH))
@ -69,6 +71,7 @@
#define SCREEN(x, a, b) (1.0 - (x) * ((1.0 - (a)) * (1.0 - (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 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 DODGE(a, b) (((a) >= 1.0) ? (a) : FFMIN(1.0, ((b) / (1.0 - (a)))))
#define GEOMETRIC(a, b) (sqrtf(fmaxf(A, 0) * fmaxf(B, 0)))
#define INT2FLOAT(x) av_int2float(x) #define INT2FLOAT(x) av_int2float(x)
#define FLOAT2INT(x) av_float2int(x) #define FLOAT2INT(x) av_float2int(x)
#define MDIV 0.125f #define MDIV 0.125f
@ -140,3 +143,4 @@ fn(xor, INT2FLOAT(FLOAT2INT(A) ^ FLOAT2INT(B)))
fn(vividlight, (A < HALF) ? BURN(2 * A, B) : DODGE(2 * (A - HALF), B)) fn(vividlight, (A < HALF) ? BURN(2 * A, B) : DODGE(2 * (A - HALF), B))
fn(linearlight,CLIP((B < HALF) ? B + 2 * A - MAX : B + 2 * (A - HALF))) fn(linearlight,CLIP((B < HALF) ? B + 2 * A - MAX : B + 2 * (A - HALF)))
fn(softdifference,CLIP((A > B) ? (B == MAX) ? 0 : (A - B) * MAX / (MAX - B) : (B == 0) ? 0 : (B - A) * MAX / B)) fn(softdifference,CLIP((A > B) ? (B == MAX) ? 0 : (A - B) * MAX / (MAX - B) : (B == 0) ? 0 : (B - A) * MAX / B))
fn(geometric, GEOMETRIC(A, B))

View File

@ -132,6 +132,7 @@ static const AVOption blend_options[] = {
{ "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" }, { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
{ "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, "mode" }, { "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, "mode" },
{ "softdifference","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTDIFFERENCE}, 0, 0, FLAGS, "mode" }, { "softdifference","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTDIFFERENCE}, 0, 0, FLAGS, "mode" },
{ "geometric", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GEOMETRIC}, 0, 0, FLAGS, "mode" },
{ "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, { "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
{ "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, { "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
{ "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, { "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
@ -396,6 +397,7 @@ static av_cold void init_blend_func_##depth##_##nbits##bit(FilterParams *param)
case BLEND_VIVIDLIGHT: param->blend = blend_vividlight_##depth##bit; break; \ case BLEND_VIVIDLIGHT: param->blend = blend_vividlight_##depth##bit; break; \
case BLEND_XOR: param->blend = blend_xor_##depth##bit; break; \ case BLEND_XOR: param->blend = blend_xor_##depth##bit; break; \
case BLEND_SOFTDIFFERENCE:param->blend = blend_softdifference_##depth##bit; break;\ case BLEND_SOFTDIFFERENCE:param->blend = blend_softdifference_##depth##bit; break;\
case BLEND_GEOMETRIC: param->blend = blend_geometric_##depth##bit; break; \
} \ } \
} }
DEFINE_INIT_BLEND_FUNC(8, 8) DEFINE_INIT_BLEND_FUNC(8, 8)