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 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 
7 #ifndef INCLUDED_IMF_LUT_H
8 #define INCLUDED_IMF_LUT_H
9 
10 //-----------------------------------------------------------------------------
11 //
12 // Lookup tables for efficient application
13 // of half --> half functions to pixel data,
14 // and some commonly applied functions.
15 //
16 //-----------------------------------------------------------------------------
17 
18 #include "ImfExport.h"
19 #include "ImfNamespace.h"
20 
21 #include "ImfRgbaFile.h"
22 
23 #include <ImathBox.h>
24 #include <halfFunction.h>
25 
27 
28 //
29 // Lookup table for individual half channels.
30 //
31 
32 class HalfLut
33 {
34  public:
35 
36  //------------
37  // Constructor
38  //------------
39 
40  template <class Function>
41  HalfLut (Function f);
42 
43 
44  //----------------------------------------------------------------------
45  // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
46  //----------------------------------------------------------------------
47 
49  void apply (half *data,
50  int nData,
51  int stride = 1) const;
52 
53 
54  //---------------------------------------------------------------
55  // Apply the table to a frame buffer slice (see ImfFrameBuffer.h)
56  //---------------------------------------------------------------
57 
59  void apply (const Slice &data,
60  const IMATH_NAMESPACE::Box2i &dataWindow) const;
61 
62  private:
63 
64  halfFunction <half> _lut;
65 };
66 
67 
68 //
69 // Lookup table for combined RGBA data.
70 //
71 
72 class RgbaLut
73 {
74  public:
75 
76  //------------
77  // Constructor
78  //------------
79 
80  template <class Function>
81  RgbaLut (Function f, RgbaChannels chn = WRITE_RGB);
82 
83 
84  //----------------------------------------------------------------------
85  // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
86  //----------------------------------------------------------------------
87 
89  void apply (Rgba *data,
90  int nData,
91  int stride = 1) const;
92 
93 
94  //-----------------------------------------------------------------------
95  // Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer())
96  //-----------------------------------------------------------------------
97 
99  void apply (Rgba *base,
100  int xStride,
101  int yStride,
102  const IMATH_NAMESPACE::Box2i &dataWindow) const;
103 
104  private:
105 
106  halfFunction <half> _lut;
107  RgbaChannels _chn;
108 };
109 
110 
111 //
112 // 12bit log rounding reduces data to 20 stops with 200 steps per stop.
113 // That makes 4000 numbers. An extra 96 just come along for the ride.
114 // Zero explicitly remains zero. The first non-zero half will map to 1
115 // in the 0-4095 12log space. A nice power of two number is placed at
116 // the center [2000] and that number is near 0.18.
117 //
118 
119 IMF_EXPORT
121 
122 
123 //
124 // Round to n-bit precision (n should be between 0 and 10).
125 // After rounding, the significand's 10-n least significant
126 // bits will be zero.
127 //
128 
129 struct roundNBit
130 {
131  roundNBit (int n): n(n) {}
132  half operator () (half x) {return x.round(n);}
133  int n;
134 };
135 
136 
137 //
138 // Template definitions
139 //
140 
141 
142 template <class Function>
143 HalfLut::HalfLut (Function f):
144  _lut(f, -HALF_MAX, HALF_MAX, half (0),
145  half::posInf(), half::negInf(), half::qNan())
146 {
147  // empty
148 }
149 
150 
151 template <class Function>
153  _lut(f, -HALF_MAX, HALF_MAX, half (0),
154  half::posInf(), half::negInf(), half::qNan()),
155  _chn(chn)
156 {
157  // empty
158 }
159 
160 
162 
163 #endif
HalfLut(Function f)
Definition: ImfLut.h:143
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
Definition: half.h:266
#define HALF_MAX
Largest positive half.
Definition: half.h:223
IMF_EXPORT half round12log(half x)
RgbaLut(Function f, RgbaChannels chn=WRITE_RGB)
Definition: ImfLut.h:152
half operator()(half x)
Definition: ImfLut.h:132
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
int n
Definition: ImfLut.h:133
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
roundNBit(int n)
Definition: ImfLut.h:131
#define IMF_EXPORT
Definition: ImfExport.h:54
GLint GLenum GLint x
Definition: glcorearb.h:409
IMF_EXPORT void apply(half *data, int nData, int stride=1) const
Definition: ImfLut.h:32
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
Definition: ImfRgba.h:27
WRITE_RGB
Definition: ImfRgba.h:56
Definition: ImfLut.h:72
enum IMF_EXPORT_ENUM RgbaChannels
Definition: ImfRgba.h:43
Definition: format.h:895
IMF_EXPORT void apply(Rgba *data, int nData, int stride=1) const