HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfLut.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
4 // Digital Ltd. LLC
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 ///////////////////////////////////////////////////////////////////////////
34 
35 
36 
37 #ifndef INCLUDED_IMF_LUT_H
38 #define INCLUDED_IMF_LUT_H
39 
40 //-----------------------------------------------------------------------------
41 //
42 // Lookup tables for efficient application
43 // of half --> half functions to pixel data,
44 // and some commonly applied functions.
45 //
46 //-----------------------------------------------------------------------------
47 
48 #include "ImfRgbaFile.h"
49 #include "ImfFrameBuffer.h"
50 #include "ImathBox.h"
51 #include "halfFunction.h"
52 #include "ImfNamespace.h"
53 #include "ImfExport.h"
54 
56 
57 //
58 // Lookup table for individual half channels.
59 //
60 
61 class HalfLut
62 {
63  public:
64 
65  //------------
66  // Constructor
67  //------------
68 
69  template <class Function>
70  HalfLut (Function f);
71 
72 
73  //----------------------------------------------------------------------
74  // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
75  //----------------------------------------------------------------------
76 
78  void apply (half *data,
79  int nData,
80  int stride = 1) const;
81 
82 
83  //---------------------------------------------------------------
84  // Apply the table to a frame buffer slice (see ImfFrameBuffer.h)
85  //---------------------------------------------------------------
86 
88  void apply (const Slice &data,
89  const IMATH_NAMESPACE::Box2i &dataWindow) const;
90 
91  private:
92 
94 };
95 
96 
97 //
98 // Lookup table for combined RGBA data.
99 //
100 
101 class RgbaLut
102 {
103  public:
104 
105  //------------
106  // Constructor
107  //------------
108 
109  template <class Function>
110  RgbaLut (Function f, RgbaChannels chn = WRITE_RGB);
111 
112 
113  //----------------------------------------------------------------------
114  // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
115  //----------------------------------------------------------------------
116 
117  IMF_EXPORT
118  void apply (Rgba *data,
119  int nData,
120  int stride = 1) const;
121 
122 
123  //-----------------------------------------------------------------------
124  // Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer())
125  //-----------------------------------------------------------------------
126 
127  IMF_EXPORT
128  void apply (Rgba *base,
129  int xStride,
130  int yStride,
131  const IMATH_NAMESPACE::Box2i &dataWindow) const;
132 
133  private:
134 
135  halfFunction <half> _lut;
136  RgbaChannels _chn;
137 };
138 
139 
140 //
141 // 12bit log rounding reduces data to 20 stops with 200 steps per stop.
142 // That makes 4000 numbers. An extra 96 just come along for the ride.
143 // Zero explicitly remains zero. The first non-zero half will map to 1
144 // in the 0-4095 12log space. A nice power of two number is placed at
145 // the center [2000] and that number is near 0.18.
146 //
147 
148 IMF_EXPORT
150 
151 
152 //
153 // Round to n-bit precision (n should be between 0 and 10).
154 // After rounding, the significand's 10-n least significant
155 // bits will be zero.
156 //
157 
158 struct roundNBit
159 {
160  roundNBit (int n): n(n) {}
161  half operator () (half x) {return x.round(n);}
162  int n;
163 };
164 
165 
166 //
167 // Template definitions
168 //
169 
170 
171 template <class Function>
172 HalfLut::HalfLut (Function f):
173  _lut(f, -HALF_MAX, HALF_MAX, half (0),
174  half::posInf(), half::negInf(), half::qNan())
175 {
176  // empty
177 }
178 
179 
180 template <class Function>
182  _lut(f, -HALF_MAX, HALF_MAX, half (0),
183  half::posInf(), half::negInf(), half::qNan()),
184  _chn(chn)
185 {
186  // empty
187 }
188 
189 
191 
192 #endif
HalfLut(Function f)
Definition: ImfLut.h:172
#define HALF_MAX
Definition: half.h:271
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
IMF_EXPORT half round12log(half x)
RgbaLut(Function f, RgbaChannels chn=WRITE_RGB)
Definition: ImfLut.h:181
RgbaChannels
Definition: ImfRgba.h:71
half round(unsigned int n) const
Definition: half.h:504
GLint GLenum GLint x
Definition: glcorearb.h:408
half operator()(half x)
Definition: ImfLut.h:161
Box< V2i > Box2i
Definition: ImathBox.h:133
int n
Definition: ImfLut.h:162
roundNBit(int n)
Definition: ImfLut.h:160
#define IMF_EXPORT
Definition: ImfExport.h:44
GLdouble n
Definition: glcorearb.h:2007
GLboolean * data
Definition: glcorearb.h:130
IMF_EXPORT void apply(half *data, int nData, int stride=1) const
Definition: ImfLut.h:61
GLfloat f
Definition: glcorearb.h:1925
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
Definition: ImfRgba.h:55
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
Definition: half.h:91
IMF_EXPORT void apply(Rgba *data, int nData, int stride=1) const