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 CC0F1429D5 for ; Mon, 11 Apr 2022 15:37:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1941668B2A5; Mon, 11 Apr 2022 18:37:09 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36DFD68B22C for ; Mon, 11 Apr 2022 18:37:02 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 025BC49DEE; Mon, 11 Apr 2022 17:37:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1649691422; bh=0xEp8OImyzjx222JDkL2IiVqvpI01Dmvwnotokm65+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJuOMjB/UNfyXBYd6RyyHQrevijFCHGJqEuz7HfInsNhs9kgbVfCqnjgf9kGKst59 PI43665T3Am3up/Zasq4iWjVJrxlzQlu+SHBZB7bhueGjxck5Z2jl8nAXynpvDV9m9 unV9dYl9BE3YDXL6HEVTYaf8PJkIO7hUZ6vmaI6g= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Apr 2022 17:36:51 +0200 Message-Id: <20220411153654.116722-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220411153654.116722-1-ffmpeg@haasn.xyz> References: <20220411153654.116722-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] lavfi: add ff_detect_color_primaries helper 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 Related to #9673, this helper exists to facilitate "guessing" the right primary tags from a given set of raw primary coefficients. The cutoff value of 0.001 was chosen by experimentation. The smallest "false negative" delta observed in practice was 0.023329, while the largest "false positive" delta was 0.00016. So, a value of 0.001 sits comfortably in the middle. Signed-off-by: Niklas Haas --- libavfilter/colorspace.c | 25 +++++++++++++++++++++++++ libavfilter/colorspace.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/libavfilter/colorspace.c b/libavfilter/colorspace.c index 25e99f4759..8d7b882375 100644 --- a/libavfilter/colorspace.c +++ b/libavfilter/colorspace.c @@ -170,6 +170,31 @@ const struct ColorPrimaries *ff_get_color_primaries(enum AVColorPrimaries prm) return p; } +enum AVColorPrimaries ff_detect_color_primaries(const struct ColorPrimaries *prm) +{ + double delta; + + for (enum AVColorPrimaries p = 0; p < AVCOL_PRI_NB; p++) { + const struct ColorPrimaries *ref = &color_primaries[p]; + if (!ref->prim.xr) + continue; + + delta = fabs(prm->prim.xr - ref->prim.xr) + + fabs(prm->prim.yr - ref->prim.yr) + + fabs(prm->prim.yg - ref->prim.yg) + + fabs(prm->prim.yg - ref->prim.yg) + + fabs(prm->prim.yb - ref->prim.yb) + + fabs(prm->prim.yb - ref->prim.yb) + + fabs(prm->wp.xw - ref->wp.xw) + + fabs(prm->wp.yw - ref->wp.yw); + + if (delta < 0.001) + return p; + } + + return AVCOL_PRI_UNSPECIFIED; +} + void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs, double rgb2yuv[3][3]) { diff --git a/libavfilter/colorspace.h b/libavfilter/colorspace.h index fc415fed05..6959133a49 100644 --- a/libavfilter/colorspace.h +++ b/libavfilter/colorspace.h @@ -49,6 +49,9 @@ void ff_fill_rgb2xyz_table(const struct PrimaryCoefficients *coeffs, const struct WhitepointCoefficients *wp, double rgb2xyz[3][3]); +/* Returns AVCOL_PRI_UNSPECIFIED if no clear match can be identified */ +enum AVColorPrimaries ff_detect_color_primaries(const struct ColorPrimaries *prm); + const struct ColorPrimaries *ff_get_color_primaries(enum AVColorPrimaries prm); const struct LumaCoefficients *ff_get_luma_coefficients(enum AVColorSpace csp); void ff_fill_rgb2yuv_table(const struct LumaCoefficients *coeffs, -- 2.35.1 _______________________________________________ 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".