From patchwork Wed Oct 12 23:05:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 980 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp63605vsd; Wed, 12 Oct 2016 16:23:11 -0700 (PDT) X-Received: by 10.194.57.136 with SMTP id i8mr5033828wjq.202.1476314591191; Wed, 12 Oct 2016 16:23:11 -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 ll4si13495132wjb.39.2016.10.12.16.23.09; Wed, 12 Oct 2016 16:23:11 -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 349B76808C0; Thu, 13 Oct 2016 02:23:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B40E5687ED4 for ; Thu, 13 Oct 2016 02:23:00 +0300 (EEST) Received: by mail-pf0-f195.google.com with SMTP id 128so3631077pfz.1 for ; Wed, 12 Oct 2016 16:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=xp7Rf6AOjEIrTpxL7g385pRliaHBmcLIxCwpM1v9PEQ=; b=VsWfFKRbUlzwm7F9iyClpHgpz9UcjJh1uZEqV1qAXmY86kdntOQJvsXnzUkkZ5wjrV rL31n9AmGRwqKQ9WhjhR9gvVQFaDvyoxb6y7DD6RKnEluswXTLQf+KaNYFWH4HeInUjT Y8oYx0wj/Ubutey0wUULfK4m73LvVUeH4PHAsTZbbUaOrmau+ZBoUsmkAnFNc99HkSo4 eGGllldBxkl+lEo6LDwasvppPjP1tANHo623CDDAxPpKy7EXsh6XvdxPDoGTjA8iL1fZ sFKQwhMXx1uZCMWtgJzphzPYeapckl7FU2uXGfT+4FkoGft20yXpE8YwUCwjH+TVnt3j ytIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xp7Rf6AOjEIrTpxL7g385pRliaHBmcLIxCwpM1v9PEQ=; b=TAAp/+isTKvjwSs94jZmnzkdj9/AngZj/z0PghgiOTTXqzg3JU4c/NrzmY0PWTvzFv S4qxDcqwrvkphiGbdyoXJ07wyR8co6m40vmWE5RZEIfLxivDG9dg8Abr47/J5AcuU0ZO u8PgxF0kl9IPPnqggK1n7/TU6ltVGW78n0GcpgIWTe9zArdTgrfB+s1OWQrdufmERp/I yJv8LtDc4lnjt+9B82Ah6eVd98hjp+uahDIhEp+lzYC9hseYVnRJ2LZuuQcWXaByxGZr L9az+tRaQhuKd9sfx+/BP2Rlqox9AR7P10EWav2iiHsk6hZ8+IPX2/hKR6jLhj+Z8PFL Dd0g== X-Gm-Message-State: AA6/9RnqwlfP2pqv6TDejBoFc6CCECciTaiQdgvSNivSusxotKro7FLmHbhnIO7zViIbvw== X-Received: by 10.99.143.82 with SMTP id r18mr4452537pgn.171.1476313633601; Wed, 12 Oct 2016 16:07:13 -0700 (PDT) Received: from localhost.localdomain.localdomain ([202.67.40.218]) by smtp.gmail.com with ESMTPSA id b83sm14232098pfl.41.2016.10.12.16.07.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Oct 2016 16:07:12 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Oct 2016 06:05:19 +0700 Message-Id: <1476313519-4109-1-git-send-email-mfcc64@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH] avfilter/showcqt: add csp option 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 Cc: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" from colorspace filter Signed-off-by: Muhammad Faiz --- doc/filters.texi | 26 ++++++++++++++++++++++ libavfilter/avf_showcqt.c | 56 ++++++++++++++++++++++++++++++++++++++++++----- libavfilter/avf_showcqt.h | 2 ++ 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 76265e7..a79972b 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16884,6 +16884,32 @@ Enable/disable drawing text to the axis. If it is set to @code{0}, drawing to the axis is disabled, ignoring @var{fontfile} and @var{axisfile} option. Default value is @code{1}. +@item csp +Set colorspace. The accepted values are: +@table @samp +@item unspecified +Unspecified (default) + +@item bt709 +BT.709 + +@item fcc +FCC + +@item bt470bg +BT.470BG or BT.601-6 625 + +@item smpte170m +SMPTE-170M or BT.601-6 525 + +@item smpte240m +SMPTE-240M + +@item bt2020ncl +BT.2020 with non-constant luminance + +@end table + @end table @subsection Examples diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c index 16bb2be..7c76b1f 100644 --- a/libavfilter/avf_showcqt.c +++ b/libavfilter/avf_showcqt.c @@ -83,6 +83,14 @@ static const AVOption showcqt_options[] = { { "axisfile", "set axis image", OFFSET(axisfile), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, FLAGS }, { "axis", "draw axis", OFFSET(axis), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, { "text", "draw axis", OFFSET(axis), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, + { "csp", "set color space", OFFSET(csp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, INT_MAX, FLAGS, "csp" }, + { "unspecified", "unspecified", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, 0, FLAGS, "csp" }, + { "bt709", "bt709", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT709 }, 0, 0, FLAGS, "csp" }, + { "fcc", "fcc", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_FCC }, 0, 0, FLAGS, "csp" }, + { "bt470bg", "bt470bg", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "csp" }, + { "smpte170m", "smpte170m", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE170M }, 0, 0, FLAGS, "csp" }, + { "smpte240m", "smpte240m", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE240M }, 0, 0, FLAGS, "csp" }, + { "bt2020ncl", "bt2020ncl", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT2020_NCL }, 0, 0, FLAGS, "csp" }, { NULL } }; @@ -656,7 +664,7 @@ static void rgb_from_cqt(ColorFloat *c, const FFTComplex *v, float g, int len) } } -static void yuv_from_cqt(ColorFloat *c, const FFTComplex *v, float gamma, int len) +static void yuv_from_cqt(ColorFloat *c, const FFTComplex *v, float gamma, int len, float cm[3][3]) { int x; for (x = 0; x < len; x++) { @@ -664,9 +672,9 @@ static void yuv_from_cqt(ColorFloat *c, const FFTComplex *v, float gamma, int le r = calculate_gamma(FFMIN(1.0f, v[x].re), gamma); g = calculate_gamma(FFMIN(1.0f, 0.5f * (v[x].re + v[x].im)), gamma); b = calculate_gamma(FFMIN(1.0f, v[x].im), gamma); - c[x].yuv.y = 65.481f * r + 128.553f * g + 24.966f * b; - c[x].yuv.u = -37.797f * r - 74.203f * g + 112.0f * b; - c[x].yuv.v = 112.0f * r - 93.786f * g - 18.214 * b; + c[x].yuv.y = cm[0][0] * r + cm[0][1] * g + cm[0][2] * b; + c[x].yuv.u = cm[1][0] * r + cm[1][1] * g + cm[1][2] * b; + c[x].yuv.v = cm[2][0] * r + cm[2][1] * g + cm[2][2] * b; } } @@ -1036,7 +1044,7 @@ static void process_cqt(ShowCQTContext *s) if (s->format == AV_PIX_FMT_RGB24) rgb_from_cqt(s->c_buf, s->cqt_result, s->sono_g, s->width); else - yuv_from_cqt(s->c_buf, s->cqt_result, s->sono_g, s->width); + yuv_from_cqt(s->c_buf, s->cqt_result, s->sono_g, s->width, s->cmatrix); } static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout) @@ -1075,6 +1083,7 @@ static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout) return AVERROR(ENOMEM); out->sample_aspect_ratio = av_make_q(1, 1); av_frame_set_color_range(out, AVCOL_RANGE_MPEG); + av_frame_set_colorspace(out, s->csp); UPDATE_TIME(s->alloc_time); if (s->bar_h) { @@ -1100,6 +1109,41 @@ static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout) return 0; } +static void init_colormatrix(ShowCQTContext *s) +{ + double kr, kg, kb; + + /* from vf_colorspace.c */ + switch (s->csp) { + default: + av_log(s->ctx, AV_LOG_WARNING, "unsupported colorspace, setting it to unspecified.\n"); + s->csp = AVCOL_SPC_UNSPECIFIED; + case AVCOL_SPC_UNSPECIFIED: + case AVCOL_SPC_BT470BG: + case AVCOL_SPC_SMPTE170M: + kr = 0.299; kb = 0.114; break; + case AVCOL_SPC_BT709: + kr = 0.2126; kb = 0.0722; break; + case AVCOL_SPC_FCC: + kr = 0.30; kb = 0.11; break; + case AVCOL_SPC_SMPTE240M: + kr = 0.212; kb = 0.087; break; + case AVCOL_SPC_BT2020_NCL: + kr = 0.2627; kb = 0.0593; break; + } + + kg = 1.0 - kr - kb; + s->cmatrix[0][0] = 219.0 * kr; + s->cmatrix[0][1] = 219.0 * kg; + s->cmatrix[0][2] = 219.0 * kb; + s->cmatrix[1][0] = -112.0 * kr / (1.0 - kb); + s->cmatrix[1][1] = -112.0 * kg / (1.0 - kb); + s->cmatrix[1][2] = 112.0; + s->cmatrix[2][0] = 112.0; + s->cmatrix[2][1] = -112.0 * kg / (1.0 - kr); + s->cmatrix[2][2] = -112.0 * kb / (1.0 - kr); +} + /* main filter control */ static av_cold int init(AVFilterContext *ctx) { @@ -1153,6 +1197,8 @@ static av_cold int init(AVFilterContext *ctx) } while(s->fcount * s->width < 1920 && s->fcount < 10); } + init_colormatrix(s); + return 0; } diff --git a/libavfilter/avf_showcqt.h b/libavfilter/avf_showcqt.h index 588830f..71e9d13 100644 --- a/libavfilter/avf_showcqt.h +++ b/libavfilter/avf_showcqt.h @@ -71,6 +71,7 @@ typedef struct { float *rcp_h_buf; float *sono_v_buf; float *bar_v_buf; + float cmatrix[3][3]; /* callback */ void (*cqt_calc)(FFTComplex *dst, const FFTComplex *src, const Coeffs *coeffs, int len, int fft_len); @@ -111,6 +112,7 @@ typedef struct { char *fontcolor; char *axisfile; int axis; + int csp; } ShowCQTContext; void ff_showcqt_init_x86(ShowCQTContext *s);