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