• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*****************************************************************************/
2 // Copyright 2006-2008 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_table.h#1 $ */
10 /* $DateTime: 2012/05/30 13:28:51 $ */
11 /* $Change: 832332 $ */
12 /* $Author: tknoll $ */
13 
14 /** \file
15  * Definition of a lookup table based 1D floating-point to floating-point function abstraction using linear interpolation.
16  */
17 
18 /*****************************************************************************/
19 
20 #ifndef __dng_1d_table__
21 #define __dng_1d_table__
22 
23 /*****************************************************************************/
24 
25 #include "dng_assertions.h"
26 #include "dng_auto_ptr.h"
27 #include "dng_classes.h"
28 #include "dng_types.h"
29 
30 /*****************************************************************************/
31 
32 /// \brief A 1D floating-point lookup table using linear interpolation.
33 
34 class dng_1d_table
35 	{
36 
37 	public:
38 
39 		/// Constants denoting size of table.
40 
41 		enum
42 			{
43 			kTableBits = 12,				//< Table is always a power of 2 in size. This is log2(kTableSize).
44 			kTableSize = (1 << kTableBits)	//< Number of entries in table.
45 			};
46 
47 	protected:
48 
49 		AutoPtr<dng_memory_block> fBuffer;
50 
51 		real32 *fTable;
52 
53 	public:
54 
55 		dng_1d_table ();
56 
57 		virtual ~dng_1d_table ();
58 
59 		/// Set up table, initialize entries using functiion.
60 		/// This method can throw an exception, e.g. if there is not enough memory.
61 		/// \param allocator Memory allocator from which table memory is allocated.
62 		/// \param function Table is initialized with values of finction.Evalluate(0.0) to function.Evaluate(1.0).
63 		/// \param subSample If true, only sample the function a limited number of times and interpolate.
64 
65 		void Initialize (dng_memory_allocator &allocator,
66 						 const dng_1d_function &function,
67 						 bool subSample = false);
68 
69 		/// Lookup and interpolate mapping for an input.
70 		/// \param x value from 0.0 to 1.0 used as input for mapping
71 		/// \retval Approximation of function.Evaluate(x)
72 
Interpolate(real32 x)73 		real32 Interpolate (real32 x) const
74 			{
75 
76 			real32 y = x * (real32) kTableSize;
77 
78 			int32 index = (int32) y;
79 
80 			if (index < 0 || index > kTableSize)
81 				{
82 
83 				ThrowBadFormat("Index out of range.");
84 
85 				}
86 
87 			DNG_ASSERT (index >= 0 && index <= kTableSize,
88 						"dng_1d_table::Interpolate parameter out of range");
89 
90 			real32 z = (real32) index;
91 
92 			real32 fract = y - z;
93 
94 			return fTable [index    ] * (1.0f - fract) +
95 				   fTable [index + 1] * (       fract);
96 
97 			}
98 
99 		/// Direct access function for table data.
100 
Table()101 		const real32 * Table () const
102 			{
103 			return fTable;
104 			}
105 
106 		/// Expand the table to a 16-bit to 16-bit table.
107 
108 		void Expand16 (uint16 *table16) const;
109 
110 	private:
111 
112 		void SubDivide (const dng_1d_function &function,
113 						uint32 lower,
114 						uint32 upper,
115 						real32 maxDelta);
116 
117 		// Hidden copy constructor and assignment operator.
118 
119 		dng_1d_table (const dng_1d_table &table);
120 
121 		dng_1d_table & operator= (const dng_1d_table &table);
122 
123 	};
124 
125 /*****************************************************************************/
126 
127 #endif
128 
129 /*****************************************************************************/
130