Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
gamma.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2021 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
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
40
namespace
etl
41
{
42
//***************************************************************************
44
//***************************************************************************
45
template
<
typename
TInput>
46
class
gamma_encode
:
public
etl::unary_function
<TInput, TInput>
47
{
48
public
:
49
50
//*********************************
52
//*********************************
53
gamma_encode
(
double
gamma_, TInput maximum_)
54
: one_over_gamma(1.0 / gamma_)
55
, maximum(maximum_)
56
{
57
}
58
59
//*********************************
62
//*********************************
63
TInput
operator()
(TInput value)
const
64
{
65
// Calculate intermediate result because rounding + optimization
66
// lead to wrong values when returning directly (test on i386)
67
const
double
result = maximum * pow(
double
(value) / maximum, one_over_gamma);
68
69
return
TInput(result);
70
}
71
72
private
:
73
74
const
double
one_over_gamma;
75
const
double
maximum;
76
};
77
78
//***************************************************************************
80
//***************************************************************************
81
template
<
typename
TInput>
82
class
gamma_decode
:
public
etl::unary_function
<TInput, TInput>
83
{
84
public
:
85
86
//*********************************
88
//*********************************
89
gamma_decode
(
double
gamma_, TInput maximum_)
90
: gamma(gamma_)
91
, maximum(maximum_)
92
{
93
}
94
95
//*********************************
98
//*********************************
99
TInput
operator()
(TInput value)
const
100
{
101
// Calculate intermediate result because rounding + optimization
102
// lead to wrong values when returning directly (test on i386)
103
const
double
result = maximum * pow(
double
(value) / maximum, gamma);
104
return
TInput(result);
105
}
106
107
private
:
108
109
const
double
gamma;
110
const
double
maximum;
111
};
112
}
// namespace etl
113
114
#endif
etl::gamma_decode::gamma_decode
gamma_decode(double gamma_, TInput maximum_)
Constructor.
Definition
gamma.h:89
etl::gamma_decode::operator()
TInput operator()(TInput value) const
Definition
gamma.h:99
etl::gamma_encode::operator()
TInput operator()(TInput value) const
Definition
gamma.h:63
etl::gamma_encode::gamma_encode
gamma_encode(double gamma_, TInput maximum_)
Constructor.
Definition
gamma.h:53
functional.h
math.h
etl
Definition
absolute.h:40
platform.h
etl::unary_function
unary_function
Definition
functional.h:182
type_traits.h
include
etl
gamma.h
Generated on
for Embedded Template Library by
1.17.0