Project

General

Profile

BitmapToolkit Scol plugin
scaler.h
Go to the documentation of this file.
1#ifndef _RASPICAM_SCALER_H_
2#define _RASPICAM_SCALER_H_
3namespace raspicam {
4
7 class Scaler
8 {
9 float a,b;
10 float _inMin, _inMax, _outMin,_outMax;
11 public:
12 float aa;
13 float bb;
14 Scaler() {}
15 Scaler ( float inMin, float inMax, float outMin,float outMax ) {
16 setParams ( inMin,inMax,outMin,outMax );
17 }
18
19
20 void setParams ( float inMin, float inMax, float outMin,float outMax ) {
21 _inMin=inMin;
22 _inMax=inMax;
23 _outMin=outMin;
24 _outMax=outMax;
25 double aux = ( _inMax - _inMin );
26 if ( aux != 0.0 ) {
27 a = ( _outMax - _outMin ) /aux;
28 b = _outMax - ( a * _inMax );
29 } else
30 a = b = 0.0;
31 aa = ( _outMax - _outMin ) / ( _inMax - _inMin );
32 bb= ( _outMax - ( aa * _inMax ) );
33 }
34 inline float operator() ( float val ) const
35 {
36 if ( val<=_inMin ) return _outMin;
37 else if ( val>=_inMax ) return _outMax;
38 return val * aa + bb;
39 }
40
41 static float scale ( float inMin, float inMax, float outMin,float outMax,float val ) {
42 Scaler s ( inMin,inMax,outMin,outMax );
43 return s ( val );
44 }
45 };
46}
47#endif
void setParams(float inMin, float inMax, float outMin, float outMax)
Definition scaler.h:20
float operator()(float val) const
Definition scaler.h:34
Scaler(float inMin, float inMax, float outMin, float outMax)
Definition scaler.h:15
static float scale(float inMin, float inMax, float outMin, float outMax, float val)
Definition scaler.h:41