1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMF_LUT_H
38
#define INCLUDED_IMF_LUT_H
40
//-----------------------------------------------------------------------------
42
// Lookup tables for efficient application
43
// of half --> half functions to pixel data,
44
// and some commonly applied functions.
46
//-----------------------------------------------------------------------------
48
#include <ImfRgbaFile.h>
49
#include <ImfFrameBuffer.h>
51
#include "halfFunction.h"
56
// Lookup table for individual half channels.
67
template <class Function>
71
//----------------------------------------------------------------------
72
// Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
73
//----------------------------------------------------------------------
75
void apply (half *data,
77
int stride = 1) const;
80
//---------------------------------------------------------------
81
// Apply the table to a frame buffer slice (see ImfFrameBuffer.h)
82
//---------------------------------------------------------------
84
void apply (const Slice &data,
85
const Imath::Box2i &dataWindow) const;
89
halfFunction <half> _lut;
94
// Lookup table for combined RGBA data.
105
template <class Function>
106
RgbaLut (Function f, RgbaChannels chn = WRITE_RGB);
109
//----------------------------------------------------------------------
110
// Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
111
//----------------------------------------------------------------------
113
void apply (Rgba *data,
115
int stride = 1) const;
118
//-----------------------------------------------------------------------
119
// Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer())
120
//-----------------------------------------------------------------------
122
void apply (Rgba *base,
125
const Imath::Box2i &dataWindow) const;
129
halfFunction <half> _lut;
135
// 12bit log rounding reduces data to 20 stops with 200 steps per stop.
136
// That makes 4000 numbers. An extra 96 just come along for the ride.
137
// Zero explicitly remains zero. The first non-zero half will map to 1
138
// in the 0-4095 12log space. A nice power of two number is placed at
139
// the center [2000] and that number is near 0.18.
142
half round12log (half x);
146
// Round to n-bit precision (n should be between 0 and 10).
147
// After rounding, the significand's 10-n least significant
148
// bits will be zero.
153
roundNBit (int n): n(n) {}
154
half operator () (half x) {return x.round(n);}
160
// Template definitions
164
template <class Function>
165
HalfLut::HalfLut (Function f):
166
_lut(f, -HALF_MAX, HALF_MAX, half (0),
167
half::posInf(), half::negInf(), half::qNan())
173
template <class Function>
174
RgbaLut::RgbaLut (Function f, RgbaChannels chn):
175
_lut(f, -HALF_MAX, HALF_MAX, half (0),
176
half::posInf(), half::negInf(), half::qNan()),