1 /*****************************************************************************
2 
3         TransOpPow.cpp
4         Author: Laurent de Soras, 2015
5 
6 --- Legal stuff ---
7 
8 This program is free software. It comes without any warranty, to
9 the extent permitted by applicable law. You can redistribute it
10 and/or modify it under the terms of the Do What The Fuck You Want
11 To Public License, Version 2, as published by Sam Hocevar. See
12 http://sam.zoy.org/wtfpl/COPYING for more details.
13 
14 *Tab=3***********************************************************************/
15 
16 
17 
18 #if defined (_MSC_VER)
19 	#pragma warning (1 : 4130 4223 4705 4706)
20 	#pragma warning (4 : 4355 4786 4800)
21 #endif
22 
23 
24 
25 /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
26 
27 #include "fmtcl/TransOpPow.h"
28 
29 #include <algorithm>
30 
31 #include <cassert>
32 #include <cmath>
33 
34 
35 
36 namespace fmtcl
37 {
38 
39 
40 
41 /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
42 
43 
44 
45 // p_i: power curve for the EOTF or OETF^-1 ( > 1)
46 // alpha: scaling factor after EOTF^-1 or OETF
TransOpPow(bool inv_flag,double p_i,double alpha,double val_max,double scale_cdm2,double wpeak_cdm2)47 TransOpPow::TransOpPow (bool inv_flag, double p_i, double alpha, double val_max, double scale_cdm2, double wpeak_cdm2)
48 :	_inv_flag (inv_flag)
49 ,	_p_i (p_i)
50 ,	_alpha (alpha)
51 ,	_p (1 / p_i)
52 ,	_val_max (val_max)
53 ,	_scale_cdm2 (scale_cdm2)
54 ,	_wpeak_cdm2 (wpeak_cdm2)
55 {
56 	// Nothing
57 }
58 
59 
60 
61 /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
62 
63 
64 
do_convert(double x) const65 double	TransOpPow::do_convert (double x) const
66 {
67 	x = std::max (x, 0.0);
68 	double         y = x;
69 
70 	if (_inv_flag)
71 	{
72 		y = pow (x / _alpha, _p_i);
73 		y = std::min (y, _val_max);
74 	}
75 	else
76 	{
77 		x = std::min (x, _val_max);
78 		y = _alpha * pow (x, _p);
79 	}
80 
81 	return y;
82 }
83 
84 
85 
do_get_info() const86 TransOpInterface::LinInfo	TransOpPow::do_get_info () const
87 {
88 	return { Type::UNDEF, Range::SDR, _val_max, 1.0, _scale_cdm2, _wpeak_cdm2 };
89 }
90 
91 
92 
93 /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
94 
95 
96 
97 }	// namespace fmtcl
98 
99 
100 
101 /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
102