From 0bf8d625ee691d9fe04cf4901f99debd86126477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Fri, 18 Dec 2015 20:04:07 +0100 Subject: [PATCH] avfilter/scale/WIP: brightness+contrast+saturation --- libavfilter/vf_scale.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index f2f475e..bda1bf7 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -110,6 +110,7 @@ typedef struct ScaleContext { int in_v_chr_pos; int force_original_aspect_ratio; + double brightness, contrast, saturation; } ScaleContext; AVFilter ff_vf_scale2ref; @@ -353,7 +354,10 @@ static int config_props(AVFilterLink *outlink) inlink0->h == outlink->h && !scale->out_color_matrix && scale->in_range == scale->out_range && - inlink0->format == outlink->format) + inlink0->format == outlink->format && + scale->brightness < 0 && + scale->contrast < 0 && + scale->saturation < 0) ; else { struct SwsContext **swscs[3] = {&scale->sws, &scale->isws[0], &scale->isws[1]}; @@ -532,7 +536,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) || scale->out_color_matrix || scale-> in_range != AVCOL_RANGE_UNSPECIFIED || in_range != AVCOL_RANGE_UNSPECIFIED - || scale->out_range != AVCOL_RANGE_UNSPECIFIED) { + || scale->out_range != AVCOL_RANGE_UNSPECIFIED + || scale->brightness >= 0 + || scale->contrast >= 0 + || scale->saturation >= 0) { int in_full, out_full, brightness, contrast, saturation; const int *inv_table, *table; @@ -540,6 +547,16 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) (int **)&table, &out_full, &brightness, &contrast, &saturation); + av_log(0,0,"ORIG: brightness:%d contrast:%d saturation:%d\n", + brightness, contrast, saturation); + + if (scale->brightness >= 0) brightness = av_clip_uint16(scale->brightness * UINT16_MAX); + if (scale->contrast >= 0) contrast = av_clip_uint16(scale->contrast * UINT16_MAX); + if (scale->saturation >= 0) saturation = av_clip_uint16(scale->saturation * UINT16_MAX); + + av_log(0,0,"TO: brightness:%d contrast:%d saturation:%d\n", + brightness, contrast, saturation); + if (scale->in_color_matrix) inv_table = parse_yuv_type(scale->in_color_matrix, av_frame_get_colorspace(in)); if (scale->out_color_matrix) @@ -651,6 +668,9 @@ static const AVOption scale_options[] = { { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" }, { "param0", "Scaler param 0", OFFSET(param[0]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, FLAGS }, { "param1", "Scaler param 1", OFFSET(param[1]), AV_OPT_TYPE_DOUBLE, { .dbl = SWS_PARAM_DEFAULT }, INT_MIN, INT_MAX, FLAGS }, + { "brightness", "override brightness colorspace", OFFSET(brightness), AV_OPT_TYPE_DOUBLE, { .dbl = -1 }, -1, 1, FLAGS }, + { "contrast", "override contrast colorspace", OFFSET(contrast), AV_OPT_TYPE_DOUBLE, { .dbl = -1 }, -1, 1, FLAGS }, + { "saturation", "override saturation colorspace", OFFSET(saturation), AV_OPT_TYPE_DOUBLE, { .dbl = -1 }, -1, 1, FLAGS }, { NULL } }; -- 2.6.4