From patchwork Sat Sep 3 13:19:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 406 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1936192vsd; Sat, 3 Sep 2016 06:38:14 -0700 (PDT) X-Received: by 10.28.199.131 with SMTP id x125mr4158238wmf.70.1472909894523; Sat, 03 Sep 2016 06:38:14 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id wk3si16759788wjb.207.2016.09.03.06.38.13; Sat, 03 Sep 2016 06:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C706F689DE1; Sat, 3 Sep 2016 16:38:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC88E689D03 for ; Sat, 3 Sep 2016 16:37:57 +0300 (EEST) Received: by mail-wm0-f68.google.com with SMTP id v143so6480622wmv.1 for ; Sat, 03 Sep 2016 06:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=1At6hH9MU8shWzkPpCjvoiFw4Uls8HmI4bGR83dJY0Y=; b=JEzYxTLpuApVnTxth4GWmKXjiZKLbK5bW5fPq+Fz6g8BUs4gXgimqFo60trOV1D0zb JbxHMrfBIc7hWrMcp+c3pcV4J7oqVRgUYB8jUUVnxj5A68TG89tD8kwvktq3nL8POAT5 vY3cw8JDhIIijX2r/idyJMHdm9ZwP52i9ERH5qAhICv4xN0/c1wN20L3Bdx4zD4xZ1eQ SBGx9lIcAoufniXESbBz1RBExmMwVBU3Y5OwgizuRttq51fa9/pZF2AORwuGdNI+NZ+3 UMzQo2dpxeUowmjPWySGa3rPkBDfUnAe4YgDJUkYSP2R0NNCR7ZqUarmYr6uEdYTCmac y7zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=1At6hH9MU8shWzkPpCjvoiFw4Uls8HmI4bGR83dJY0Y=; b=nAIyltDmAigadbBiK4gpCnbNdPf3zpwKbxxXXxMxzQ9KraNA+31n3OBwYMah/hlTq6 ItXNsQnisnNI+Y7UPKa/WC5JNnQ//t/Tm+Xs8edFcx7zKl16hsoOxxTGCMJVRfj/OB+g tWO/6PUW6k4QbrdgIt9M7w97nUqlBTbUfACqIDq5VHJ8f/xCehQzbNOV7+hAexy5mN/w F/MF66nq+nlsiHfMTH6RER3/vB5TWd/ZfpfwDp6atpCcyBEhnYbnjzOX0HkxuFt4BT36 Lts/Y52Vf/pq+/VOE+e/ShR/HtydJqg54svyVW48KZsLeWtlXIfgfB+2ez6FD/SY2CX+ kRdQ== X-Gm-Message-State: AE9vXwNIMX+vrqkXFsfBcqCMzYYVq4BpTlL6ezVxuW+d03uMgH8yZUc6K2bbGpFGGn4wAg== X-Received: by 10.194.89.9 with SMTP id bk9mr23012777wjb.181.1472908778336; Sat, 03 Sep 2016 06:19:38 -0700 (PDT) Received: from localhost.localdomain ([87.190.250.220]) by smtp.gmail.com with ESMTPSA id s6sm15447609wjm.25.2016.09.03.06.19.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 03 Sep 2016 06:19:37 -0700 (PDT) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Sep 2016 15:19:35 +0200 Message-Id: <20160903131935.45609-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCHv3] vf_colorspace: Allow overriding input color properties X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The filter needs input frames with color properties filled out by the decoder. Since this is not always possible, add input options to the filter so that user may override color space, color primaries, transfer characteristics, and color range, as well as a generic option to set all properties at once. Signed-off-by: Vittorio Giovara --- Options moved at the bottom of the list as requested. Vittorio doc/filters.texi | 20 ++++++++++++++++++++ libavfilter/vf_colorspace.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index c12b093..00ec1ea 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -5235,6 +5235,7 @@ Convert colorspace, transfer characteristics or color primaries. The filter accepts the following options: @table @option +@anchor{all} @item all Specify all color properties at once. @@ -5266,6 +5267,7 @@ BT.2020 @end table +@anchor{space} @item space Specify output colorspace. @@ -5291,6 +5293,7 @@ BT.2020 with non-constant luminance @end table +@anchor{trc} @item trc Specify output transfer characteristics. @@ -5319,6 +5322,7 @@ BT.2020 for 12-bits content @end table +@anchor{primaries} @item primaries Specify output color primaries. @@ -5344,6 +5348,7 @@ BT.2020 @end table +@anchor{range} @item range Specify output color range. @@ -5423,6 +5428,21 @@ von Kries whitepoint adaptation identity whitepoint adaptation (i.e. no whitepoint adaptation) @end table +@item iall +Override all input properties at once. Same accepted values as @ref{all}. + +@item ispace +Override input colorspace. Same accepted values as @ref{space}. + +@item iprimaries +Override input color primaries. Same accepted values as @ref{primaries}. + +@item itrc +Override input transfer characteristics. Same accepted values as @ref{trc}. + +@item irange +Override input color range. Same accepted values as @ref{range}. + @end table The filter converts the transfer characteristics, color space and color diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c index e4022f8..45fd917 100644 --- a/libavfilter/vf_colorspace.c +++ b/libavfilter/vf_colorspace.c @@ -128,11 +128,11 @@ typedef struct ColorSpaceContext { ColorSpaceDSPContext dsp; - enum Colorspace user_all; - enum AVColorSpace in_csp, out_csp, user_csp; - enum AVColorRange in_rng, out_rng, user_rng; - enum AVColorTransferCharacteristic in_trc, out_trc, user_trc; - enum AVColorPrimaries in_prm, out_prm, user_prm; + enum Colorspace user_all, user_iall; + enum AVColorSpace in_csp, out_csp, user_csp, user_icsp; + enum AVColorRange in_rng, out_rng, user_rng, user_irng; + enum AVColorTransferCharacteristic in_trc, out_trc, user_trc, user_itrc; + enum AVColorPrimaries in_prm, out_prm, user_prm, user_iprm; enum AVPixelFormat in_format, user_format; int fast_mode; enum DitherMode dither; @@ -581,6 +581,10 @@ static int create_filtergraph(AVFilterContext *ctx, if (!s->out_primaries || !s->in_primaries) { s->in_prm = in->color_primaries; + if (s->user_iall != CS_UNSPECIFIED) + s->in_prm = default_prm[FFMIN(s->user_iall, CS_NB)]; + if (s->user_iprm != AVCOL_PRI_UNSPECIFIED) + s->in_prm = s->user_iprm; s->in_primaries = get_color_primaries(s->in_prm); if (!s->in_primaries) { av_log(ctx, AV_LOG_ERROR, @@ -638,6 +642,10 @@ static int create_filtergraph(AVFilterContext *ctx, if (!s->in_txchr) { av_freep(&s->lin_lut); s->in_trc = in->color_trc; + if (s->user_iall != CS_UNSPECIFIED) + s->in_trc = default_trc[FFMIN(s->user_iall, CS_NB)]; + if (s->user_itrc != AVCOL_TRC_UNSPECIFIED) + s->in_trc = s->user_itrc; s->in_txchr = get_transfer_characteristics(s->in_trc); if (!s->in_txchr) { av_log(ctx, AV_LOG_ERROR, @@ -680,7 +688,13 @@ static int create_filtergraph(AVFilterContext *ctx, if (!s->in_lumacoef) { s->in_csp = in->colorspace; + if (s->user_iall != CS_UNSPECIFIED) + s->in_csp = default_csp[FFMIN(s->user_iall, CS_NB)]; + if (s->user_icsp != AVCOL_SPC_UNSPECIFIED) + s->in_csp = s->user_icsp; s->in_rng = in->color_range; + if (s->user_irng != AVCOL_RANGE_UNSPECIFIED) + s->in_rng = s->user_irng; s->in_lumacoef = get_luma_coefficients(s->in_csp); if (!s->in_lumacoef) { av_log(ctx, AV_LOG_ERROR, @@ -1078,6 +1092,22 @@ static const AVOption colorspace_options[] = { ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"), ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"), + { "iall", "Set all input color properties together", + OFFSET(user_iall), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED }, + CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" }, + { "ispace", "Input colorspace", + OFFSET(user_icsp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, + AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "csp" }, + { "irange", "Input color range", + OFFSET(user_irng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED }, + AVCOL_RANGE_UNSPECIFIED, AVCOL_RANGE_NB - 1, FLAGS, "rng" }, + { "iprimaries", "Input color primaries", + OFFSET(user_iprm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED }, + AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" }, + { "itrc", "Input transfer characteristics", + OFFSET(user_itrc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED }, + AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" }, + { NULL } };