Krita Source Code Documentation
Loading...
Searching...
No Matches
LutKey< float > Class Reference

#include <lut.h>

Classes

union  IFNumber
 

Public Member Functions

int inputToKey (float i) const
 
bool inrange (float i) const
 
float keyToInput (int k) const
 
 LutKey (float min, float max, float precision)
 
float maximum () const
 
float minimum () const
 
int size () const
 

Private Attributes

int m_diff_p
 
float m_max
 
float m_min
 
float m_precision
 
int m_shift
 
int m_tMax_n
 
int m_tMax_p
 
int m_tMin_n
 
int m_tMin_p
 

Detailed Description

This provide an implementation for a LutKey for floating point input values.

Based on "High-speed Conversion of Floating Point Images to 8-bit" by Bill Spitzaks (https://spitzak.github.io/conversion/sketches_0265.pdf)

Definition at line 208 of file lut.h.

Constructor & Destructor Documentation

◆ LutKey()

LutKey< float >::LutKey ( float min,
float max,
float precision )
inline

Definition at line 215 of file lut.h.

215 : m_min(min), m_max(max), m_precision(precision)
216 {
217 // Those values where computed using the test_linear and setting the shift and then using
218 // the standard deviation.
219 if (precision <= 0.000011809f) {
220 m_min = 1;
221 m_max = -1;
222 }
223 else if (precision <= 0.0000237291f) m_shift = 8;
224 else if (precision <= 0.0000475024f) m_shift = 9;
225 else if (precision <= 0.0000948575f) m_shift = 10;
226 else if (precision <= 0.00019013f) m_shift = 11;
227 else if (precision <= 0.000379523f) m_shift = 12;
228 else if (precision <= 0.000758431f) m_shift = 13;
229 else if (precision <= 0.00151891f) m_shift = 14;
230 else if (precision <= 0.00303725f) m_shift = 15;
231 else m_shift = 16;
232
233 if ( 0.0 <= m_min && m_min <= precision)
234 m_min = precision;
235 if ( -precision <= m_max && m_max <= 0.0)
236 m_max = -precision;
237
238 IFNumber uf;
239
240 if(m_min > 0 && m_max > 0)
241 {
242 uf.f = m_min;
243 m_tMin_p = uf.i >> m_shift;
244 uf.f = m_max;
245 m_tMax_p = uf.i >> m_shift;
248 } else if( m_max < 0)
249 {
250 uf.f = m_min;
251 m_tMax_n = uf.i >> m_shift;
252 uf.f = m_max;
253 m_tMin_n = uf.i >> m_shift;
256 } else { // m_min <0 && m_max > 0
257 uf.f = precision;
258 m_tMin_p = uf.i >> m_shift;
259 uf.f = m_max;
260 m_tMax_p = uf.i >> m_shift;
261 uf.f = -precision;
262 m_tMin_n = uf.i >> m_shift;
263 uf.f = m_min;
264 m_tMax_n = uf.i >> m_shift;
265 }
267 }
int m_tMax_n
Definition lut.h:309
int m_tMax_p
Definition lut.h:309
int m_tMin_n
Definition lut.h:309
int m_shift
Definition lut.h:310
int m_tMin_p
Definition lut.h:309
float m_min
Definition lut.h:308
float m_precision
Definition lut.h:308
int m_diff_p
Definition lut.h:309
float m_max
Definition lut.h:308

Member Function Documentation

◆ inputToKey()

int LutKey< float >::inputToKey ( float i) const
inline

Definition at line 269 of file lut.h.

270 {
271 IFNumber uf;
272 uf.f = i;
273 int k = (uf.i >> m_shift);
274 if(k <= m_tMax_p)
275 {
276 return k - m_tMin_p;
277 } else {
278 return k - m_tMin_n + m_diff_p;
279 }
280 }

◆ inrange()

bool LutKey< float >::inrange ( float i) const
inline

Definition at line 291 of file lut.h.

292 {
293 return i >= m_min && i <= m_max && (i < -m_precision || i > m_precision);
294 }

◆ keyToInput()

float LutKey< float >::keyToInput ( int k) const
inline

Definition at line 281 of file lut.h.

282 {
283 IFNumber uf;
284 if( k <= m_diff_p ) {
285 uf.i = ((k + m_tMin_p) << m_shift);
286 } else {
287 uf.i = ((k + m_tMin_n - m_diff_p ) << m_shift);
288 }
289 return uf.f;
290 }

◆ maximum()

float LutKey< float >::maximum ( ) const
inline

Definition at line 299 of file lut.h.

300 {
301 return m_max;
302 }

◆ minimum()

float LutKey< float >::minimum ( ) const
inline

Definition at line 295 of file lut.h.

296 {
297 return m_min;
298 }

◆ size()

int LutKey< float >::size ( ) const
inline

Definition at line 303 of file lut.h.

304 {
305 return m_diff_p + m_tMax_n - m_tMin_p + 1;
306 }

Member Data Documentation

◆ m_diff_p

int LutKey< float >::m_diff_p
private

Definition at line 309 of file lut.h.

◆ m_max

float LutKey< float >::m_max
private

Definition at line 308 of file lut.h.

◆ m_min

float LutKey< float >::m_min
private

Definition at line 308 of file lut.h.

◆ m_precision

float LutKey< float >::m_precision
private

Definition at line 308 of file lut.h.

◆ m_shift

int LutKey< float >::m_shift
private

Definition at line 310 of file lut.h.

◆ m_tMax_n

int LutKey< float >::m_tMax_n
private

Definition at line 309 of file lut.h.

◆ m_tMax_p

int LutKey< float >::m_tMax_p
private

Definition at line 309 of file lut.h.

◆ m_tMin_n

int LutKey< float >::m_tMin_n
private

Definition at line 309 of file lut.h.

◆ m_tMin_p

int LutKey< float >::m_tMin_p
private

Definition at line 309 of file lut.h.


The documentation for this class was generated from the following file: