From patchwork Mon Apr 11 15:36:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 35256 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp1111629pzh; Mon, 11 Apr 2022 08:37:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpleCmkLxzzaL9UJXiqzhAxL4VDRbGnZ1O9eoi4BfpvJmFp5kQHtwygeXNswThQd1k/id/ X-Received: by 2002:a17:906:478b:b0:6db:8b6e:d5de with SMTP id cw11-20020a170906478b00b006db8b6ed5demr31367273ejc.161.1649691440586; Mon, 11 Apr 2022 08:37:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649691440; cv=none; d=google.com; s=arc-20160816; b=DTZqU/Ix0wUtFtUnvqCFERNy9KbuG+eqj2Lt02vtRXmDujFk165CmcvAy5L6nMiKco DWbT9X/kCoE3+zMWkhtSwsy8zTYNFG4WgSqZN0ojioUTmwRVcPLgO5POFnA/Y+4sMhgs vkF9Tc97oUwq2x8cTyF1AiGu3xlVi3ijvlIMn36KcgBhMCzYxYH/TtiVAX6XuVN3rRVB ftQ6jfrTubWXcy0N+dfsh92S7nSIHSrkYYjxnVYA4LPiZ1OXaUaC4I1Wn+6PCRNfTF6T +WyKZeHCJ3uw7Y/dHC3uq56C+ZkznBJg6RQ7qfJ8CnLLOppekHGpFA/rq439Xjdslgif Pj+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=TApD+621N6ycokjyagd2k8YpgfBkgLXRWF8CKutf/OI=; b=RvbXZJLQuXU8VvOugiXyP5YszvIUZG7Xpl1VDxDFvI8nzrZMSJDl+BaZ86fwewb2Po qOukDAezII98rWl+4KRbctLl9aqmC7Ryf90SkuKdHHpIZPpfPCr37rBctp30YfY9J14W /TxwTi9E6x/Sb4AtaYHPYhM0/lfj44gTKv/hF5XGf32TSAcsRXSUkLfXAEj3U0Ao1wjL 6rbaoJlZAnvk0WIOSkwFA/Hfjkv0/EMLiXNKdbFtBngBytk1Y9fI5ppegiLw0LsSy2QU RqvUMzWr5rJhFTefNykfgKnoHemPfDWmZw+P5rlm7z1gGGHL9D45r+SjYKVZnSRc+Uau LFTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="SJuOMjB/"; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ko11-20020a170907986b00b006e88a65ed8csi3281676ejc.353.2022.04.11.08.37.19; Mon, 11 Apr 2022 08:37:20 -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=@haasn.xyz header.s=mail header.b="SJuOMjB/"; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D1EB68B2A9; Mon, 11 Apr 2022 18:37:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zaGPZsm+qUQz 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,