summaryrefslogtreecommitdiff
path: root/src/lib/util.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-25 00:32:39 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-25 21:35:12 +0200
commit71f3520ea315fb65ff151c99aa0b64fc8dccdb1d (patch)
treea09a8200a7ca14cada2e4b72ff40a1adb0b44f32 /src/lib/util.h
parentb26f4e4cfa0a3b6df794f3207b420a413c52e773 (diff)
Clamp results correctly when shifting video levels, and account for that in tests.
Diffstat (limited to 'src/lib/util.h')
-rw-r--r--src/lib/util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/util.h b/src/lib/util.h
index fa0d9fdf2..013eabe12 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -150,4 +150,12 @@ list_to_vector (std::list<T> v)
extern double db_to_linear (double db);
extern double linear_to_db (double linear);
+
+template <class T>
+T clamp (T val, T minimum, T maximum)
+{
+ return std::max(std::min(val, maximum), minimum);
+}
+
+
#endif