libcamera: utils: Add clamp()
C++11 does not support std::clamp(), add a custom implementation in utils. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
1a7f1610e9
commit
c4b9ccb45a
2 changed files with 16 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
#ifndef __LIBCAMERA_UTILS_H__
|
#ifndef __LIBCAMERA_UTILS_H__
|
||||||
#define __LIBCAMERA_UTILS_H__
|
#define __LIBCAMERA_UTILS_H__
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||||
|
@ -45,6 +46,13 @@ unsigned int set_overlap(InputIt1 first1, InputIt1 last1,
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* C++11 doesn't provide std::clamp */
|
||||||
|
template <typename T>
|
||||||
|
const T& clamp(const T& v, const T& lo, const T& hi)
|
||||||
|
{
|
||||||
|
return std::max(lo, std::min(v, hi));
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace utils */
|
} /* namespace utils */
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
|
@ -85,6 +85,14 @@ char *secure_getenv(const char *name)
|
||||||
* \return The number of elements in the intersection of the two ranges
|
* \return The number of elements in the intersection of the two ranges
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \fn libcamera::utils::clamp(const T& v, const T& lo, const T& hi)
|
||||||
|
* \param[in] v The value to clamp
|
||||||
|
* \param[in] lo The lower boundary to clamp v to
|
||||||
|
* \param[in] hi The higher boundary to clamp v to
|
||||||
|
* \return lo if v is less than lo, hi if v is greater than hi, otherwise v
|
||||||
|
*/
|
||||||
|
|
||||||
} /* namespace utils */
|
} /* namespace utils */
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue