From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 74A9247970 for ; Sat, 28 Oct 2023 14:45:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 677B068CBFB; Sat, 28 Oct 2023 17:44:50 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9E82968CB9D for ; Sat, 28 Oct 2023 17:44:40 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id DFD614BBC9; Sat, 28 Oct 2023 16:44:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698504277; bh=oT9+KIvsSacAFctM4PBCEZBkpantgQLd5I3k2X6QlJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VyAh8LGmWYhdOoLe+pwKaPsDi94CT2CCc9fWCkpm7aOsqyIM583zpNls2C/yznIUI mS/8DJv+TLpn8W/eogf9Ph/c9kDHmRd+dYN7a9+M4w6cPJlwK9PLsx7yASshcBh4g6 Pg/MdZfMp2T7EUvt5FUw3OW1KPTLu2KhVTGQNwhM= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Oct 2023 16:41:15 +0200 Message-ID: <20231028144430.60538-9-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231028144430.60538-1-ffmpeg@haasn.xyz> References: <20231028144430.60538-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 08/10] avfilter/vf_scale: simplify color matrix parsing logic X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas No need to write a custom string parser when we can just use an integer option with preset values. The various bits of fallback logic are wholly redundant with equivalent logic already inside sws_getCoefficients. Note: I disallowed setting 'out_color_matrix=auto', because this does not do anything meaningful in the current code (just hard-codes AVCOL_SPC_BT470BG fallback). --- libavfilter/vf_scale.c | 60 +++++++++++++----------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index cde6f52169..21cac60779 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -139,8 +139,8 @@ typedef struct ScaleContext { char *flags_str; - char *in_color_matrix; - char *out_color_matrix; + int in_color_matrix; + int out_color_matrix; int in_range; int out_range; @@ -407,30 +407,6 @@ static int query_formats(AVFilterContext *ctx) return 0; } -static const int *parse_yuv_type(const char *s, enum AVColorSpace colorspace) -{ - if (!s) - s = "bt601"; - - if (s && strstr(s, "bt709")) { - colorspace = AVCOL_SPC_BT709; - } else if (s && strstr(s, "fcc")) { - colorspace = AVCOL_SPC_FCC; - } else if (s && strstr(s, "smpte240m")) { - colorspace = AVCOL_SPC_SMPTE240M; - } else if (s && (strstr(s, "bt601") || strstr(s, "bt470") || strstr(s, "smpte170m"))) { - colorspace = AVCOL_SPC_BT470BG; - } else if (s && strstr(s, "bt2020")) { - colorspace = AVCOL_SPC_BT2020_NCL; - } - - if (colorspace < 1 || colorspace > 10 || colorspace == 8) { - colorspace = AVCOL_SPC_BT470BG; - } - - return sws_getCoefficients(colorspace); -} - static int scale_eval_dimensions(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; @@ -802,11 +778,13 @@ scale: (int **)&table, &out_full, &brightness, &contrast, &saturation); - if (scale->in_color_matrix) - inv_table = parse_yuv_type(scale->in_color_matrix, in->colorspace); - if (scale->out_color_matrix) - table = parse_yuv_type(scale->out_color_matrix, AVCOL_SPC_UNSPECIFIED); - else if (scale->in_color_matrix) + if (scale->in_color_matrix == -1 /* auto */) + inv_table = sws_getCoefficients(in->colorspace); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) + inv_table = sws_getCoefficients(scale->in_color_matrix); + if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) + table = sws_getCoefficients(scale->out_color_matrix); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) table = inv_table; if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) @@ -992,16 +970,16 @@ static const AVOption scale_options[] = { { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_BOOL, {.i64 = 0 }, -1, 1, FLAGS }, { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS }, { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS }, - { "in_color_matrix", "set input YCbCr type", OFFSET(in_color_matrix), AV_OPT_TYPE_STRING, { .str = "auto" }, .flags = FLAGS, "color" }, - { "out_color_matrix", "set output YCbCr type", OFFSET(out_color_matrix), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS, "color"}, - { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .str = "auto" }, 0, 0, FLAGS, "color" }, - { "bt601", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt601" }, 0, 0, FLAGS, "color" }, - { "bt470", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt470" }, 0, 0, FLAGS, "color" }, - { "smpte170m", NULL, 0, AV_OPT_TYPE_CONST, { .str = "smpte170m" }, 0, 0, FLAGS, "color" }, - { "bt709", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt709" }, 0, 0, FLAGS, "color" }, - { "fcc", NULL, 0, AV_OPT_TYPE_CONST, { .str = "fcc" }, 0, 0, FLAGS, "color" }, - { "smpte240m", NULL, 0, AV_OPT_TYPE_CONST, { .str = "smpte240m" }, 0, 0, FLAGS, "color" }, - { "bt2020", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt2020" }, 0, 0, FLAGS, "color" }, + { "in_color_matrix", "set input YCbCr type", OFFSET(in_color_matrix), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AVCOL_SPC_NB-1, .flags = FLAGS, "color" }, + { "out_color_matrix", "set output YCbCr type", OFFSET(out_color_matrix), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, .flags = FLAGS, "color"}, + { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, FLAGS, "color" }, + { "bt601", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "bt470", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "smpte170m", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "bt709", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT709 }, 0, 0, FLAGS, "color" }, + { "fcc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_FCC }, 0, 0, FLAGS, "color" }, + { "smpte240m", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE240M }, 0, 0, FLAGS, "color" }, + { "bt2020", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT2020_NCL }, 0, 0, FLAGS, "color" }, { "in_range", "set input color range", OFFSET( in_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "out_range", "set output color range", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 0, FLAGS, "range" }, -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".