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 
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 
77  void apply (half *data,
78  int nData,
79  int stride = 1) const;
80 
81 
82  //---------------------------------------------------------------
83  // Apply the table to a frame buffer slice (see ImfFrameBuffer.h)
84  //---------------------------------------------------------------
85 
86  void apply (const Slice &data,
87  const IMATH_NAMESPACE::Box2i &dataWindow) const;
88 
89  private:
90 
92 };
93 
94 
95 //
96 // Lookup table for combined RGBA data.
97 //
98 
100 {
101  public:
102 
103  //------------
104  // Constructor
105  //------------
106 
107  template <class Function>
108  RgbaLut (Function f, RgbaChannels chn = WRITE_RGB);
109 
110 
111  //----------------------------------------------------------------------
112  // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
113  //----------------------------------------------------------------------
114 
115  void apply (Rgba *data,
116  int nData,
117  int stride = 1) const;
118 
119 
120  //-----------------------------------------------------------------------
121  // Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer())
122  //-----------------------------------------------------------------------
123 
124  void apply (Rgba *base,
125  int xStride,
126  int yStride,
127  const IMATH_NAMESPACE::Box2i &dataWindow) const;
128 
129  private:
130 
131  halfFunction <half> _lut;
132  RgbaChannels _chn;
133 };
134 
135 
136 //
137 // 12bit log rounding reduces data to 20 stops with 200 steps per stop.
138 // That makes 4000 numbers. An extra 96 just come along for the ride.
139 // Zero explicitly remains zero. The first non-zero half will map to 1
140 // in the 0-4095 12log space. A nice power of two number is placed at
141 // the center [2000] and that number is near 0.18.
142 //
143 
144 IMF_EXPORT
146 
147 
148 //
149 // Round to n-bit precision (n should be between 0 and 10).
150 // After rounding, the significand's 10-n least significant
151 // bits will be zero.
152 //
153 
154 struct roundNBit
155 {
156  roundNBit (int n): n(n) {}
157  half operator () (half x) {return x.round(n);}
158  int n;
159 };
160 
161 
162 //
163 // Template definitions
164 //
165 
166 
167 template <class Function>
168 HalfLut::HalfLut (Function f):
169  _lut(f, -HALF_MAX, HALF_MAX, half (0),
170  half::posInf(), half::negInf(), half::qNan())
171 {
172  // empty
173 }
174 
175 
176 template <class Function>
178  _lut(f, -HALF_MAX, HALF_MAX, half (0),
179  half::posInf(), half::negInf(), half::qNan()),
180  _chn(chn)
181 {
182  // empty
183 }
184 
185 
187 
188 #endif
HalfLut(Function f)
Definition: ImfLut.h:168
#define HALF_MAX
Definition: half.h:267
#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:177
RgbaChannels
Definition: ImfRgba.h:81
half round(unsigned int n) const
Definition: half.h:504
half operator()(half x)
Definition: ImfLut.h:157
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
Box< V2i > Box2i
Definition: ImathBox.h:133
int n
Definition: ImfLut.h:158
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
roundNBit(int n)
Definition: ImfLut.h:156
#define IMF_EXPORT
Definition: ImfExport.h:59
GLboolean * data
Definition: glcorearb.h:130
Definition: ImfLut.h:61
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
Definition: ImfRgba.h:55
Definition: half.h:91
Definition: ImfLut.h:99