1 /*****************************************************************************/ 2 // Copyright 2006-2019 Adobe Systems Incorporated 3 // All Rights Reserved. 4 // 5 // NOTICE: Adobe permits you to use, modify, and distribute this file in 6 // accordance with the terms of the Adobe license agreement accompanying it. 7 /*****************************************************************************/ 8 9 #include "dng_1d_function.h" 10 11 #include "dng_utils.h" 12 13 /*****************************************************************************/ 14 ~dng_1d_function()15dng_1d_function::~dng_1d_function () 16 { 17 18 } 19 20 /*****************************************************************************/ 21 IsIdentity() const22bool dng_1d_function::IsIdentity () const 23 { 24 25 return false; 26 27 } 28 29 /*****************************************************************************/ 30 EvaluateInverse(real64 y) const31real64 dng_1d_function::EvaluateInverse (real64 y) const 32 { 33 34 const uint32 kMaxIterations = 30; 35 const real64 kNearZero = 1.0e-10; 36 37 real64 x0 = 0.0; 38 real64 y0 = Evaluate (x0); 39 40 real64 x1 = 1.0; 41 real64 y1 = Evaluate (x1); 42 43 for (uint32 iteration = 0; iteration < kMaxIterations; iteration++) 44 { 45 46 if (Abs_real64 (y1 - y0) < kNearZero) 47 { 48 break; 49 } 50 51 real64 x2 = Pin_real64 (0.0, 52 x1 + (y - y1) * (x1 - x0) / (y1 - y0), 53 1.0); 54 55 real64 y2 = Evaluate (x2); 56 57 x0 = x1; 58 y0 = y1; 59 60 x1 = x2; 61 y1 = y2; 62 63 } 64 65 return x1; 66 67 } 68 69 /*****************************************************************************/ 70 IsIdentity() const71bool dng_1d_identity::IsIdentity () const 72 { 73 74 return true; 75 76 } 77 78 /*****************************************************************************/ 79 Evaluate(real64 x) const80real64 dng_1d_identity::Evaluate (real64 x) const 81 { 82 83 return x; 84 85 } 86 87 /*****************************************************************************/ 88 EvaluateInverse(real64 x) const89real64 dng_1d_identity::EvaluateInverse (real64 x) const 90 { 91 92 return x; 93 94 } 95 96 /*****************************************************************************/ 97 Get()98const dng_1d_function & dng_1d_identity::Get () 99 { 100 101 static dng_1d_identity static_function; 102 103 return static_function; 104 105 } 106 107 /*****************************************************************************/ 108 dng_1d_concatenate(const dng_1d_function & function1,const dng_1d_function & function2)109dng_1d_concatenate::dng_1d_concatenate (const dng_1d_function &function1, 110 const dng_1d_function &function2) 111 112 : fFunction1 (function1) 113 , fFunction2 (function2) 114 115 { 116 117 } 118 119 /*****************************************************************************/ 120 IsIdentity() const121bool dng_1d_concatenate::IsIdentity () const 122 { 123 124 return fFunction1.IsIdentity () && 125 fFunction2.IsIdentity (); 126 127 } 128 129 /*****************************************************************************/ 130 Evaluate(real64 x) const131real64 dng_1d_concatenate::Evaluate (real64 x) const 132 { 133 134 real64 y = Pin_real64 (0.0, fFunction1.Evaluate (x), 1.0); 135 136 return fFunction2.Evaluate (y); 137 138 } 139 140 /*****************************************************************************/ 141 EvaluateInverse(real64 x) const142real64 dng_1d_concatenate::EvaluateInverse (real64 x) const 143 { 144 145 real64 y = fFunction2.EvaluateInverse (x); 146 147 return fFunction1.EvaluateInverse (y); 148 149 } 150 151 /*****************************************************************************/ 152 dng_1d_inverse(const dng_1d_function & f)153dng_1d_inverse::dng_1d_inverse (const dng_1d_function &f) 154 155 : fFunction (f) 156 157 { 158 159 } 160 161 /*****************************************************************************/ 162 IsIdentity() const163bool dng_1d_inverse::IsIdentity () const 164 { 165 166 return fFunction.IsIdentity (); 167 168 } 169 170 /*****************************************************************************/ 171 Evaluate(real64 x) const172real64 dng_1d_inverse::Evaluate (real64 x) const 173 { 174 175 return fFunction.EvaluateInverse (x); 176 177 } 178 179 /*****************************************************************************/ 180 EvaluateInverse(real64 y) const181real64 dng_1d_inverse::EvaluateInverse (real64 y) const 182 { 183 184 return fFunction.Evaluate (y); 185 186 } 187 188 /*****************************************************************************/ 189