From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH 2/5] lavfi: add ff_detect_color_primaries helper Date: Mon, 11 Apr 2022 17:36:51 +0200 Message-ID: <20220411153654.116722-2-ffmpeg@haasn.xyz> (raw) In-Reply-To: <20220411153654.116722-1-ffmpeg@haasn.xyz> From: Niklas Haas <git@haasn.dev> 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 <git@haasn.dev> --- 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".
next prev parent reply other threads:[~2022-04-11 15:37 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-11 15:36 [FFmpeg-devel] [PATCH 1/5] lavfi: generalize colorspace coefficent helpers Niklas Haas 2022-04-11 15:36 ` Niklas Haas [this message] 2022-04-11 15:36 ` [FFmpeg-devel] [PATCH 3/5] lavfi: add ICC profile support via lcms2 Niklas Haas 2022-04-11 15:36 ` [FFmpeg-devel] [PATCH 4/5] lavfi: add vf_iccgen for generating ICC profiles Niklas Haas 2022-04-11 15:36 ` [FFmpeg-devel] [PATCH 5/5] lavfi: add vf_iccdetect for parsing " Niklas Haas
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220411153654.116722-2-ffmpeg@haasn.xyz \ --to=ffmpeg@haasn.xyz \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=git@haasn.dev \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git