[vlc-commits] [Git][videolan/vlc][master] 2 commits: charset: add vlc_sscanf_c() and vlc_vsscanf_c()
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Sun May 29 19:45:54 UTC 2022
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
98102a6b by Rémi Denis-Courmont at 2022-05-29T19:27:01+00:00
charset: add vlc_sscanf_c() and vlc_vsscanf_c()
- - - - -
4eef8bb1 by Rémi Denis-Courmont at 2022-05-29T19:27:01+00:00
vout: allow non-integral crop ratio numbers
Fixes #24596.
- - - - -
3 changed files:
- include/vlc_charset.h
- src/text/charset.c
- src/video_output/vout_intf.c
Changes:
=====================================
include/vlc_charset.h
=====================================
@@ -430,6 +430,13 @@ VLC_API int vlc_vasprintf_c(char **restrict p, const char *restrict fmt,
*/
VLC_API int vlc_asprintf_c( char **, const char *, ... ) VLC_USED;
+int vlc_vsscanf_c(const char *, const char *, va_list) VLC_USED;
+int vlc_sscanf_c(const char*, const char*, ...) VLC_USED
+#ifdef __GNUC__
+__attribute__((format(scanf, 2, 3)))
+#endif
+;
+
/** @} */
/** @} */
=====================================
src/text/charset.c
=====================================
@@ -99,3 +99,31 @@ int vlc_asprintf_c(char **restrict ret, const char *restrict format, ...)
return i_rc;
}
+
+int vlc_vsscanf_c(const char *restrict buf, const char *restrict format,
+ va_list ap)
+{
+ locale_t loc = newlocale(LC_NUMERIC_MASK, "C", NULL);
+ locale_t oldloc = uselocale(loc);
+ int ret = vsscanf(buf, format, ap);
+
+ if (loc != (locale_t)0)
+ {
+ uselocale(oldloc);
+ freelocale(loc);
+ }
+
+ return ret;
+}
+
+int vlc_sscanf_c(const char *restrict buf, const char *restrict format, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, format);
+ ret = vlc_vsscanf_c(buf, format, ap);
+ va_end( ap );
+
+ return ret;
+}
=====================================
src/video_output/vout_intf.c
=====================================
@@ -468,6 +468,8 @@ exit:
bool vout_ParseCrop(struct vout_crop *restrict cfg, const char *crop_str)
{
+ float fnum, fden;
+
if (sscanf(crop_str, "%u:%u", &cfg->ratio.num, &cfg->ratio.den) == 2) {
if (cfg->ratio.num != 0 && cfg->ratio.den != 0)
cfg->mode = VOUT_CROP_RATIO;
@@ -481,6 +483,14 @@ bool vout_ParseCrop(struct vout_crop *restrict cfg, const char *crop_str)
&cfg->border.left, &cfg->border.top,
&cfg->border.right, &cfg->border.bottom) == 4) {
cfg->mode = VOUT_CROP_BORDER;
+ } else if (vlc_sscanf_c(crop_str, "%f:%f", &fnum, &fden) == 2) {
+ long num = lroundf(ldexp(fnum, 24/*-bit mantissa */));
+ long den = lroundf(ldexp(fden, 24));
+ long gcd = GCD(num, den);
+
+ cfg->mode = VOUT_CROP_RATIO;
+ cfg->ratio.num = num / gcd;
+ cfg->ratio.den = den / gcd;
} else if (*crop_str == '\0') {
cfg->mode = VOUT_CROP_NONE;
} else {
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/663af4870a5c1dccce891310d7d8f52f09049be2...4eef8bb16d9e432865f6e2c4b4dc58ba61f83d72
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/663af4870a5c1dccce891310d7d8f52f09049be2...4eef8bb16d9e432865f6e2c4b4dc58ba61f83d72
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list