[FFmpeg-devel] [PATCH 01/10] lavu/internal: add hex to int functions.
Nicolas George
george at nsup.org
Tue Jul 27 17:48:04 EEST 2021
Signed-off-by: Nicolas George <george at nsup.org>
---
libavutil/internal.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/libavutil/internal.h b/libavutil/internal.h
index a33e8700c3..ba221438ed 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -291,4 +291,38 @@ void ff_check_pixfmt_descriptors(void);
*/
int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp);
+/**
+ * Test if val is between min and max, inclusive.
+ */
+static inline int ff_between(unsigned min, unsigned max, unsigned val)
+{
+ return val - min <= max - min;
+}
+
+/**
+ * Convert a hex digit to its value, -1 if not hex.
+ */
+static inline int ff_hexchar2int(char c)
+{
+ if (ff_between('0', '9', c))
+ return c - '0';
+ c &= ~('a' - 'A');
+ if (ff_between('A', 'F', c))
+ return c - 'A' + 10;
+ return -1;
+}
+
+/**
+ * Convert a hex digit to its value, -1 if not hex.
+ */
+static inline int ff_hexpair2int(const char *s)
+{
+ int a, b;
+
+ if ((a = ff_hexchar2int(s[0])) < 0 ||
+ (b = ff_hexchar2int(s[1])) < 0)
+ return -1;
+ return (a << 4) | b;
+}
+
#endif /* AVUTIL_INTERNAL_H */
--
2.30.2
More information about the ffmpeg-devel
mailing list