Embedded Template Library 1.0
Loading...
Searching...
No Matches
gamma.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2021 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_GAMMA_INCLUDED
32#define ETL_GAMMA_INCLUDED
33
34#include "platform.h"
35#include "functional.h"
36#include "type_traits.h"
37
38#include <math.h>
39#include <stdint.h>
40
41namespace etl
42{
43 //***************************************************************************
45 //***************************************************************************
46 template <typename TInput>
47 class gamma_encode : public etl::unary_function<TInput, TInput>
48 {
49 public:
50
51 //*********************************
53 //*********************************
55 : one_over_gamma(1.0 / gamma_)
56 , maximum(maximum_)
57 {
58 }
59
60 //*********************************
63 //*********************************
65 {
66 return TInput(TInput(maximum * pow(double(value) / maximum, one_over_gamma)));
67 }
68
69 private:
70
71 const double one_over_gamma;
72 const double maximum;
73 };
74
75 //***************************************************************************
77 //***************************************************************************
78 template <typename TInput>
79 class gamma_decode : public etl::unary_function<TInput, TInput>
80 {
81 public:
82
83 //*********************************
85 //*********************************
87 : gamma(gamma_)
88 , maximum(maximum_)
89 {
90 }
91
92 //*********************************
95 //*********************************
97 {
98 return TInput(TInput(maximum * pow(double(value) / maximum, gamma)));
99 }
100
101 private:
102
103 const double gamma;
104 const double maximum;
105 };
106}
107
108#endif
Gamma decode function.
Definition gamma.h:80
gamma_decode(double gamma_, TInput maximum_)
Constructor.
Definition gamma.h:86
TInput operator()(TInput value) const
Definition gamma.h:96
Gamma encode function.
Definition gamma.h:48
TInput operator()(TInput value) const
Definition gamma.h:64
gamma_encode(double gamma_, TInput maximum_)
Constructor.
Definition gamma.h:54
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164
Definition functional.h:118