genesys: Move math utilities to utilities.h

merge-requests/244/head
Povilas Kanapickas 2020-05-23 10:39:06 +03:00
rodzic fe323f19cb
commit 8981e583e2
2 zmienionych plików z 45 dodań i 45 usunięć

Wyświetl plik

@ -423,51 +423,6 @@ void build_image_pipeline(Genesys_Device* dev, const ScanSession& session);
std::uint8_t compute_frontend_gain(float value, float target_value,
FrontendType frontend_type);
template<class T>
inline T abs_diff(T a, T b)
{
if (a < b) {
return b - a;
} else {
return a - b;
}
}
inline uint64_t align_multiple_floor(uint64_t x, uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return (x / multiple) * multiple;
}
inline uint64_t align_multiple_ceil(uint64_t x, uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return ((x + multiple - 1) / multiple) * multiple;
}
inline uint64_t multiply_by_depth_ceil(uint64_t pixels, uint64_t depth)
{
if (depth == 1) {
return (pixels / 8) + ((pixels % 8) ? 1 : 0);
} else {
return pixels * (depth / 8);
}
}
template<class T>
inline T clamp(const T& value, const T& lo, const T& hi)
{
if (value < lo)
return lo;
if (value > hi)
return hi;
return value;
}
/*---------------------------------------------------------------------------*/
/* ASIC specific functions declarations */
/*---------------------------------------------------------------------------*/

Wyświetl plik

@ -76,6 +76,51 @@ inline double fixed_to_double(SANE_Word v)
return static_cast<double>(v) / (1 << SANE_FIXED_SCALE_SHIFT);
}
template<class T>
inline T abs_diff(T a, T b)
{
if (a < b) {
return b - a;
} else {
return a - b;
}
}
inline std::uint64_t align_multiple_floor(std::uint64_t x, std::uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return (x / multiple) * multiple;
}
inline std::uint64_t align_multiple_ceil(std::uint64_t x, std::uint64_t multiple)
{
if (multiple == 0) {
return x;
}
return ((x + multiple - 1) / multiple) * multiple;
}
inline std::uint64_t multiply_by_depth_ceil(std::uint64_t pixels, std::uint64_t depth)
{
if (depth == 1) {
return (pixels / 8) + ((pixels % 8) ? 1 : 0);
} else {
return pixels * (depth / 8);
}
}
template<class T>
inline T clamp(const T& value, const T& lo, const T& hi)
{
if (value < lo)
return lo;
if (value > hi)
return hi;
return value;
}
template<class T>
void compute_array_percentile_approx(T* result, const T* data,
std::size_t line_count, std::size_t elements_per_line,