Use BABL method for 16-to-8 bit conversion (#3429)

This commit is contained in:
Flössie
2016-09-22 21:52:07 +02:00
parent 7635559062
commit 759676788b
6 changed files with 30 additions and 26 deletions

View File

@@ -1,14 +1,15 @@
#ifndef _MYMATH_
#define _MYMATH_
#include <cmath>
#include <algorithm>
#pragma once
#include <algorithm>
#include <cmath>
#include <cstdint>
namespace rtengine
{
static const int MAXVAL = 0xffff;
static const float MAXVALF = float(MAXVAL); // float version of MAXVAL
static const double MAXVALD = double(MAXVAL); // double version of MAXVAL
constexpr int MAXVAL = 0xffff;
constexpr float MAXVALF = static_cast<float>(MAXVAL); // float version of MAXVAL
constexpr double MAXVALD = static_cast<double>(MAXVAL); // double version of MAXVAL
template <typename _Tp>
inline _Tp SQR (_Tp x)
@@ -107,6 +108,9 @@ inline int float2uint16range(float d) // clips input to [0;65535] and rounds
return d + 0.5f;
}
constexpr std::uint8_t uint16ToUint8Rounded(std::uint16_t i)
{
return ((i + 128) - ((i + 128) >> 8)) >> 8;
}
#endif
}