[FFmpeg-devel] [PATCH 01/10] lavu/internal: add hex to int functions.

Marton Balint cus at passwd.hu
Tue Jul 27 23:05:48 EEST 2021



On Tue, 27 Jul 2021, Nicolas George wrote:

> 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;
> +}

This seems a bit too general. What if somebody needs int and not unsigned? 
I just think it is better to not make this ff_*.

> +
> +/**
> + * Convert a hex digit to its value, -1 if not hex.
> + */
> +static inline int ff_hexchar2int(char c)
> +{
> +    if (ff_between('0', '9', c))

av_isdigit(c)

> +        return c - '0';
> +    c &= ~('a' - 'A');

c = av_toupper(c);

> +    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 */

Thanks,
Marton


More information about the ffmpeg-devel mailing list