11 extern const std::array<BGRA8Pixel,256> RainbowTable;
14 template<
int32_t LBound = 0,
int32_t UBound = 255,
class TResult = u
int8_t,
class TArg = u
int16_t>
22 typename std::array<TResult, UBound - LBound + 1>::iterator
lut;
28 explicit LUT_function ( std::function<TResult(
double)> f,
const double& coeff = 1 ) {
29 lut = lut_array.begin() + LBound;
30 for ( uint32_t i = LBound ; i <= UBound ; ++i )
31 *(lut+i) = f(i*coeff);
41 enum ColorEnum { None, Gray, Red, Green, Blue, Yellow, Rainbow, Limits };
44 extern const std::array<CString, 8> gColorStrings;
67 ColorProps(
const ColorEnum& _col = None,
const uint16_t& _ll = 0,
const uint16_t& _ul = UINT16_MAX >> 1)
90 uint16_t Range()
const { std::lock_guard<std::mutex> lock(mutex);
return ul-
ll; }
91 ColorEnum Color()
const { std::lock_guard<std::mutex> lock(mutex);
return col; }
92 uint16_t LowerLimit()
const { std::lock_guard<std::mutex> lock(mutex);
return ll; }
93 uint16_t UpperLimit()
const { std::lock_guard<std::mutex> lock(mutex);
return ul; }
98 void SetColor(
const ColorEnum& _col) { std::lock_guard<std::mutex> lock(mutex); col = _col; }
99 void SetLowerLimit(
const uint16_t& _ll) { std::lock_guard<std::mutex> lock(mutex); ll = _ll; }
100 void SetUpperLimit(
const uint16_t& _ul) { std::lock_guard<std::mutex> lock(mutex); ul = _ul; }
104 operator ColorEnum()
const { std::lock_guard<std::mutex> lock(mutex);
return Color(); }
108 #define BGRA8BLACK BGRA8Pixel(0)
111 #define BGRA8WHITE BGRA8Pixel(255)
114 inline BGRA8Pixel U16ToBGRA8(
const uint16_t& gray,
const ColorEnum& pixelcolor) {
115 switch (pixelcolor) {
117 return BGRA8Pixel(to8(gray));
119 return BGRA8Pixel(to8(gray), 0U, 0U);
121 return BGRA8Pixel(0U, to8(gray), 0U);
123 return BGRA8Pixel(0U, 0U, to8(gray));
125 return BGRA8Pixel(0U, to8(gray), to8(gray));
127 return BGRA8Pixel(0U);
129 return RainbowTable[to8(gray)];
131 return ( (to8(gray) == 0)
132 ? BGRA8Pixel(255,0,0)
134 ? BGRA8Pixel(0,0,255)
135 : BGRA8Pixel(to8(gray))
138 return BGRA8Pixel(0U);
143 inline BGRA8Pixel U16ToBGRA8Histo(
const uint16_t& gray,
const ColorEnum& pixelcolor,
const uint16_t& l,
const uint16_t& u) {
144 const uint8_t tmp8 = to8hist_mod(gray, l, u);
145 switch (pixelcolor) {
147 return BGRA8Pixel(tmp8);
149 return BGRA8Pixel(tmp8, 0U, 0U);
151 return BGRA8Pixel(0U, tmp8, 0U);
153 return BGRA8Pixel(0U, 0U, tmp8);
155 return BGRA8Pixel(0U, tmp8, tmp8);
157 return BGRA8Pixel(0U);
159 return RainbowTable[tmp8];
162 ? BGRA8Pixel(255,0,0)
164 ? BGRA8Pixel(0,0,255)
168 return BGRA8Pixel(0U);
173 inline BGRA8Pixel U16ToBGRA8Histo2(
const uint16_t& gray,
const ColorEnum& pixelcolor,
const uint16_t& l,
const uint16_t& u,
const uint16_t& scaler) {
174 const uint8_t tmp8 = to8hist_mod2(gray, l, u, scaler);
175 switch (pixelcolor) {
177 return BGRA8Pixel(tmp8);
179 return BGRA8Pixel(tmp8, 0U, 0U);
181 return BGRA8Pixel(0U, tmp8, 0U);
183 return BGRA8Pixel(0U, 0U, tmp8);
185 return BGRA8Pixel(0U, tmp8, tmp8);
187 return BGRA8Pixel(0U);
189 return RainbowTable[tmp8];
192 ? BGRA8Pixel(255,0,0)
194 ? BGRA8Pixel(0,0,255)
198 return BGRA8Pixel(0U);
std::array< TResult, UBound-LBound+1 >::iterator lut
iterator to beginning of lookup table
const TResult & operator()(TArg i) const
std::mutex mutex
for protection
LUT_function(std::function< TResult(double)> f, const double &coeff=1)
Fills lookup table with function f.
The BGRA8Pixel struct and various related helpers for color conversions.
class for generating a lookup table by providing a function to the constructor
ColorProps(const ColorEnum &_col=None, const uint16_t &_ll=0, const uint16_t &_ul=UINT16_MAX >> 1)
NI-DAQ devices have range of +-x volts digitized to int16, we read this as uint16, thus only values from 0-32767 are used => maximum pixel value is 65534 / 2 = 32767.
std::array< TResult, UBound-LBound+1 > lut_array
the lookup table
uint16_t ul
upper limit to display
uint16_t ll
lower limit to display
ColorProps(const ColorProps &cp)
Safe copy constructor.
ColorProps & operator=(const ColorProps &cp)
Safe assignment.
ColorEnum col
the color map type
Encapsulated lower and upper limit for range adjustment and color for displaying. ...