From df7a0d0fec98d56cd88e4c28ceffa4ed18881477 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Wed, 20 Nov 2024 15:02:19 +0800 Subject: [PATCH] utils: Add gst_util_floor_log2 helper function Part-of: --- subprojects/gstreamer/gst/gstutils.c | 45 ++++++++++++++++++++++++++++ subprojects/gstreamer/gst/gstutils.h | 3 ++ 2 files changed, 48 insertions(+) diff --git a/subprojects/gstreamer/gst/gstutils.c b/subprojects/gstreamer/gst/gstutils.c index 3893aad552..d026db70c7 100644 --- a/subprojects/gstreamer/gst/gstutils.c +++ b/subprojects/gstreamer/gst/gstutils.c @@ -4518,6 +4518,51 @@ gst_util_ceil_log2 (guint32 v) return y; } +/** + * gst_util_floor_log2: + * @v: a #guint32 value. + * + * Returns smallest integral value not bigger than log2(v). + * + * Returns: a computed #guint val. + * + * Since: 1.26 + */ +guint +gst_util_floor_log2 (guint32 v) +{ + guint32 result = 0; + + g_return_val_if_fail (v != 0, -1); + + if (v & 0xffff0000) { + v >>= 16; + result += 16; + } + + if (v & 0xff00) { + v >>= 8; + result += 8; + } + + if (v & 0xf0) { + v >>= 4; + result += 4; + } + + if (v & 0xc) { + v >>= 2; + result += 2; + } + + if (v & 0x2) { + v >>= 1; + result += 1; + } + + return result; +} + /** * gst_calculate_linear_regression: (skip) * @xy: Pairs of (x,y) values diff --git a/subprojects/gstreamer/gst/gstutils.h b/subprojects/gstreamer/gst/gstutils.h index f42dab843a..9400507f71 100644 --- a/subprojects/gstreamer/gst/gstutils.h +++ b/subprojects/gstreamer/gst/gstutils.h @@ -1243,6 +1243,9 @@ gboolean gst_type_is_plugin_api (GType type, GstPluginAPIFlags * GST_API guint gst_util_ceil_log2 (guint32 v); +GST_API +guint gst_util_floor_log2 (guint32 x); + GST_API gint gst_util_filename_compare (const gchar *a, const gchar *b);