Home | History | Annotate | Download | only in source
      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_4/dng_sdk/source/dng_1d_function.h#1 $ */
     10 /* $DateTime: 2012/05/30 13:28:51 $ */
     11 /* $Change: 832332 $ */
     12 /* $Author: tknoll $ */
     13 
     14 /** \file
     15  * Classes for a 1D floating-point to floating-point function abstraction.
     16  */
     17 
     18 /*****************************************************************************/
     19 
     20 #ifndef __dng_1d_function__
     21 #define __dng_1d_function__
     22 
     23 /*****************************************************************************/
     24 
     25 #include "dng_classes.h"
     26 #include "dng_types.h"
     27 
     28 /*****************************************************************************/
     29 
     30 /// \brief A 1D floating-point function.
     31 ///
     32 /// The domain (input) is always from 0.0 to 1.0, while the range (output) can be an arbitrary interval.
     33 
     34 class dng_1d_function
     35 	{
     36 
     37 	public:
     38 
     39 		virtual ~dng_1d_function ();
     40 
     41 		/// Returns true if this function is the map x -> y such that x == y for all x . That is if Evaluate(x) == x for all x.
     42 
     43 		virtual bool IsIdentity () const;
     44 
     45 		/// Return the mapping for value x.
     46 		/// This method must be implemented by a derived class of dng_1d_function and the derived class determines the
     47 		/// lookup method and function used.
     48 		/// \param x A value between 0.0 and 1.0 (inclusive).
     49 		/// \retval Mapped value for x
     50 
     51 		virtual real64 Evaluate (real64 x) const = 0;
     52 
     53 		/// Return the reverse mapped value for y.
     54 		/// This method can be implemented by derived classes. The default implementation uses Newton's method to solve
     55 		/// for x such that Evaluate(x) == y.
     56 		/// \param y A value to reverse map. Should be within the range of the function implemented by this dng_1d_function .
     57 		/// \retval A value x such that Evaluate(x) == y (to very close approximation).
     58 
     59 		virtual real64 EvaluateInverse (real64 y) const;
     60 
     61 	};
     62 
     63 /*****************************************************************************/
     64 
     65 /// An identity (x -> y such that x == y for all x) mapping function.
     66 
     67 class dng_1d_identity: public dng_1d_function
     68 	{
     69 
     70 	public:
     71 		/// Always returns true for this class.
     72 
     73 		virtual bool IsIdentity () const;
     74 
     75 		/// Always returns x for this class.
     76 
     77 		virtual real64 Evaluate (real64 x) const;
     78 
     79 		/// Always returns y for this class.
     80 
     81 		virtual real64 EvaluateInverse (real64 y) const;
     82 
     83 		/// This class is a singleton, and is entirely threadsafe. Use this method to get an instance of the class.
     84 
     85 		static const dng_1d_function & Get ();
     86 
     87 	};
     88 
     89 /*****************************************************************************/
     90 
     91 /// A dng_1d_function that represents the composition (curry) of two other dng_1d_functions.
     92 
     93 class dng_1d_concatenate: public dng_1d_function
     94 	{
     95 
     96 	protected:
     97 
     98 		const dng_1d_function &fFunction1;
     99 
    100 		const dng_1d_function &fFunction2;
    101 
    102 	public:
    103 
    104 		/// Create a dng_1d_function which computes y = function2.Evaluate(function1.Evaluate(x)).
    105 		/// Compose function1 and function2 to compute y = function2.Evaluate(function1.Evaluate(x)). The range of function1.Evaluate must be a subset of 0.0 to 1.0 inclusive,
    106 		/// otherwise the result of function1(x) will be pinned (clipped) to 0.0 if <0.0 and to 1.0 if > 1.0 .
    107 		/// \param function1 Inner function of composition.
    108 		/// \param function2 Outer function of composition.
    109 
    110 		dng_1d_concatenate (const dng_1d_function &function1,
    111 							const dng_1d_function &function2);
    112 
    113 		/// Only true if both function1 and function2 have IsIdentity equal to true.
    114 
    115 		virtual bool IsIdentity () const;
    116 
    117 		/// Return the composed mapping for value x.
    118 		/// \param x A value between 0.0 and 1.0 (inclusive).
    119 		/// \retval function2.Evaluate(function1.Evaluate(x)).
    120 
    121 		virtual real64 Evaluate (real64 x) const;
    122 
    123 		/// Return the reverse mapped value for y.
    124 		/// Be careful using this method with compositions where the inner function does not have a range 0.0 to 1.0 . (Or better yet, do not use such functions.)
    125 		/// \param y A value to reverse map. Should be within the range of function2.Evaluate.
    126 		/// \retval A value x such that function2.Evaluate(function1.Evaluate(x)) == y (to very close approximation).
    127 
    128 		virtual real64 EvaluateInverse (real64 y) const;
    129 
    130 	};
    131 
    132 /*****************************************************************************/
    133 
    134 /// A dng_1d_function that represents the inverse of another dng_1d_function.
    135 
    136 class dng_1d_inverse: public dng_1d_function
    137 	{
    138 
    139 	protected:
    140 
    141 		const dng_1d_function &fFunction;
    142 
    143 	public:
    144 
    145 		dng_1d_inverse (const dng_1d_function &f);
    146 
    147 		virtual bool IsIdentity () const;
    148 
    149 		virtual real64 Evaluate (real64 x) const;
    150 
    151 		virtual real64 EvaluateInverse (real64 y) const;
    152 
    153 	};
    154 
    155 /*****************************************************************************/
    156 
    157 #endif
    158 
    159 /*****************************************************************************/
    160