1 /*****************************************************************************/
2 // Copyright 2006 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 /* $Id: //mondo/dng_sdk_1_2/dng_sdk/source/dng_1d_function.cpp#1 $ */
10 /* $DateTime: 2008/03/09 14:29:54 $ */
11 /* $Change: 431850 $ */
12 /* $Author: tknoll $ */
13 
14 /*****************************************************************************/
15 
16 #include "dng_1d_function.h"
17 
18 #include "dng_utils.h"
19 
20 /*****************************************************************************/
21 
~dng_1d_function()22 dng_1d_function::~dng_1d_function ()
23 	{
24 
25 	}
26 
27 /*****************************************************************************/
28 
IsIdentity() const29 bool dng_1d_function::IsIdentity () const
30 	{
31 
32 	return false;
33 
34 	}
35 
36 /*****************************************************************************/
37 
EvaluateInverse(real64 y) const38 real64 dng_1d_function::EvaluateInverse (real64 y) const
39 	{
40 
41 	const uint32 kMaxIterations = 30;
42 	const real64 kNearZero      = 1.0e-10;
43 
44 	real64 x0 = 0.0;
45 	real64 y0 = Evaluate (x0);
46 
47 	real64 x1 = 1.0;
48 	real64 y1 = Evaluate (x1);
49 
50 	for (uint32 iteration = 0; iteration < kMaxIterations; iteration++)
51 		{
52 
53 		if (Abs_real64 (y1 - y0) < kNearZero)
54 			{
55 			break;
56 			}
57 
58 		real64 x2 = Pin_real64 (0.0,
59 								x1 + (y - y1) * (x1 - x0) / (y1 - y0),
60 								1.0);
61 
62 		real64 y2 = Evaluate (x2);
63 
64 		x0 = x1;
65 		y0 = y1;
66 
67 		x1 = x2;
68 		y1 = y2;
69 
70 		}
71 
72 	return x1;
73 
74 	}
75 
76 /*****************************************************************************/
77 
IsIdentity() const78 bool dng_1d_identity::IsIdentity () const
79 	{
80 
81 	return true;
82 
83 	}
84 
85 /*****************************************************************************/
86 
Evaluate(real64 x) const87 real64 dng_1d_identity::Evaluate (real64 x) const
88 	{
89 
90 	return x;
91 
92 	}
93 
94 /*****************************************************************************/
95 
EvaluateInverse(real64 x) const96 real64 dng_1d_identity::EvaluateInverse (real64 x) const
97 	{
98 
99 	return x;
100 
101 	}
102 
103 /*****************************************************************************/
104 
Get()105 const dng_1d_function & dng_1d_identity::Get ()
106 	{
107 
108 	static dng_1d_identity static_function;
109 
110 	return static_function;
111 
112 	}
113 
114 /*****************************************************************************/
115 
dng_1d_concatenate(const dng_1d_function & function1,const dng_1d_function & function2)116 dng_1d_concatenate::dng_1d_concatenate (const dng_1d_function &function1,
117 										const dng_1d_function &function2)
118 
119 	:	fFunction1 (function1)
120 	,	fFunction2 (function2)
121 
122 	{
123 
124 	}
125 
126 /*****************************************************************************/
127 
IsIdentity() const128 bool dng_1d_concatenate::IsIdentity () const
129 	{
130 
131 	return fFunction1.IsIdentity () &&
132 		   fFunction2.IsIdentity ();
133 
134 	}
135 
136 /*****************************************************************************/
137 
Evaluate(real64 x) const138 real64 dng_1d_concatenate::Evaluate (real64 x) const
139 	{
140 
141 	real64 y = Pin_real64 (0.0, fFunction1.Evaluate (x), 1.0);
142 
143 	return fFunction2.Evaluate (y);
144 
145 	}
146 
147 /*****************************************************************************/
148 
EvaluateInverse(real64 x) const149 real64 dng_1d_concatenate::EvaluateInverse (real64 x) const
150 	{
151 
152 	real64 y = fFunction2.EvaluateInverse (x);
153 
154 	return fFunction1.EvaluateInverse (y);
155 
156 	}
157 
158 /*****************************************************************************/
159 
dng_1d_inverse(const dng_1d_function & f)160 dng_1d_inverse::dng_1d_inverse (const dng_1d_function &f)
161 
162 	:	fFunction (f)
163 
164 	{
165 
166 	}
167 
168 /*****************************************************************************/
169 
IsIdentity() const170 bool dng_1d_inverse::IsIdentity () const
171 	{
172 
173 	return fFunction.IsIdentity ();
174 
175 	}
176 
177 /*****************************************************************************/
178 
Evaluate(real64 x) const179 real64 dng_1d_inverse::Evaluate (real64 x) const
180 	{
181 
182 	return fFunction.EvaluateInverse (x);
183 
184 	}
185 
186 /*****************************************************************************/
187 
EvaluateInverse(real64 y) const188 real64 dng_1d_inverse::EvaluateInverse (real64 y) const
189 	{
190 
191 	return fFunction.Evaluate (y);
192 
193 	}
194 
195 /*****************************************************************************/
196