~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/3rdparty/openexr/IlmImf/ImfLut.h

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
53
namespace Imf {
 
54
 
 
55
//
 
56
// Lookup table for individual half channels.
 
57
//
 
58
 
 
59
class HalfLut
 
60
{
 
61
  public:
 
62
 
 
63
    //------------
 
64
    // Constructor
 
65
    //------------
 
66
 
 
67
    template <class Function>
 
68
    HalfLut (Function f);
 
69
 
 
70
 
 
71
    //----------------------------------------------------------------------
 
72
    // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
 
73
    //----------------------------------------------------------------------
 
74
 
 
75
    void apply (half *data,
 
76
        int nData,
 
77
        int stride = 1) const;
 
78
 
 
79
 
 
80
    //---------------------------------------------------------------
 
81
    // Apply the table to a frame buffer slice (see ImfFrameBuffer.h)
 
82
    //---------------------------------------------------------------
 
83
 
 
84
    void apply (const Slice &data,
 
85
        const Imath::Box2i &dataWindow) const;
 
86
 
 
87
  private:
 
88
 
 
89
    halfFunction <half> _lut;
 
90
};
 
91
 
 
92
 
 
93
//
 
94
// Lookup table for combined RGBA data.
 
95
//
 
96
 
 
97
class RgbaLut
 
98
{
 
99
  public:
 
100
 
 
101
    //------------
 
102
    // Constructor
 
103
    //------------
 
104
 
 
105
    template <class Function>
 
106
    RgbaLut (Function f, RgbaChannels chn = WRITE_RGB);
 
107
 
 
108
 
 
109
    //----------------------------------------------------------------------
 
110
    // Apply the table to data[0], data[stride] ... data[(nData-1) * stride]
 
111
    //----------------------------------------------------------------------
 
112
 
 
113
    void apply (Rgba *data,
 
114
        int nData,
 
115
        int stride = 1) const;
 
116
 
 
117
 
 
118
    //-----------------------------------------------------------------------
 
119
    // Apply the table to a frame buffer (see RgbaOutpuFile.setFrameBuffer())
 
120
    //-----------------------------------------------------------------------
 
121
 
 
122
    void apply (Rgba *base,
 
123
        int xStride,
 
124
        int yStride,
 
125
        const Imath::Box2i &dataWindow) const;
 
126
 
 
127
  private:
 
128
 
 
129
    halfFunction <half> _lut;
 
130
    RgbaChannels        _chn;
 
131
};
 
132
 
 
133
 
 
134
//
 
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.
 
140
//
 
141
 
 
142
half round12log (half x);
 
143
 
 
144
 
 
145
//
 
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.
 
149
//
 
150
 
 
151
struct roundNBit
 
152
{
 
153
    roundNBit (int n): n(n) {}
 
154
    half operator () (half x) {return x.round(n);}
 
155
    int n;
 
156
};
 
157
 
 
158
 
 
159
//
 
160
// Template definitions
 
161
//
 
162
 
 
163
 
 
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())
 
168
{
 
169
    // empty
 
170
}
 
171
 
 
172
 
 
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()),
 
177
    _chn(chn)
 
178
{
 
179
    // empty
 
180
}
 
181
 
 
182
 
 
183
} // namespace Imf
 
184
 
 
185
#endif