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
//-----------------------------------------------------------------------------
39
// Lookup tables for efficient application
40
// of half --> half functions to pixel data,
41
// and some commonly applied functions.
43
//-----------------------------------------------------------------------------
53
HalfLut::apply (half *data, int nData, int stride) const
65
HalfLut::apply (const Slice &data, const Imath::Box2i &dataWindow) const
67
assert (data.type == HALF);
68
assert (dataWindow.min.x % data.xSampling == 0);
69
assert (dataWindow.min.y % data.ySampling == 0);
70
assert ((dataWindow.max.x - dataWindow.min.x + 1) % data.xSampling == 0);
71
assert ((dataWindow.max.y - dataWindow.min.y + 1) % data.ySampling == 0);
73
char *base = data.base + data.yStride *
74
(dataWindow.min.y / data.ySampling);
76
for (int y = dataWindow.min.y;
77
y <= dataWindow.max.y;
80
char *pixel = base + data.xStride *
81
(dataWindow.min.x / data.xSampling);
83
for (int x = dataWindow.min.x;
84
x <= dataWindow.max.x;
87
*(half *)pixel = _lut (*(half *)pixel);
88
pixel += data.xStride;
97
RgbaLut::apply (Rgba *data, int nData, int stride) const
102
data->r = _lut (data->r);
105
data->g = _lut (data->g);
108
data->b = _lut (data->b);
111
data->a = _lut (data->a);
120
RgbaLut::apply (Rgba *base,
121
int xStride, int yStride,
122
const Imath::Box2i &dataWindow) const
124
base += dataWindow.min.y * yStride;
126
for (int y = dataWindow.min.y; y <= dataWindow.max.y; ++y)
128
Rgba *pixel = base + dataWindow.min.x * xStride;
130
for (int x = dataWindow.min.x; x <= dataWindow.max.x; ++x)
133
pixel->r = _lut (pixel->r);
136
pixel->g = _lut (pixel->g);
139
pixel->b = _lut (pixel->b);
142
pixel->a = _lut (pixel->a);
155
const float middleval = pow (2.0, -2.5);
164
int12log = int (2000.5 + 200.0 * log (x / middleval) / log (2.0));
173
return middleval * pow (2.0, (int12log - 2000.0) / 200.0);
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
//-----------------------------------------------------------------------------
39
// Lookup tables for efficient application
40
// of half --> half functions to pixel data,
41
// and some commonly applied functions.
43
//-----------------------------------------------------------------------------
53
HalfLut::apply (half *data, int nData, int stride) const
65
HalfLut::apply (const Slice &data, const Imath::Box2i &dataWindow) const
67
assert (data.type == HALF);
68
assert (dataWindow.min.x % data.xSampling == 0);
69
assert (dataWindow.min.y % data.ySampling == 0);
70
assert ((dataWindow.max.x - dataWindow.min.x + 1) % data.xSampling == 0);
71
assert ((dataWindow.max.y - dataWindow.min.y + 1) % data.ySampling == 0);
73
char *base = data.base + data.yStride *
74
(dataWindow.min.y / data.ySampling);
76
for (int y = dataWindow.min.y;
77
y <= dataWindow.max.y;
80
char *pixel = base + data.xStride *
81
(dataWindow.min.x / data.xSampling);
83
for (int x = dataWindow.min.x;
84
x <= dataWindow.max.x;
87
*(half *)pixel = _lut (*(half *)pixel);
88
pixel += data.xStride;
97
RgbaLut::apply (Rgba *data, int nData, int stride) const
102
data->r = _lut (data->r);
105
data->g = _lut (data->g);
108
data->b = _lut (data->b);
111
data->a = _lut (data->a);
120
RgbaLut::apply (Rgba *base,
121
int xStride, int yStride,
122
const Imath::Box2i &dataWindow) const
124
base += dataWindow.min.y * yStride;
126
for (int y = dataWindow.min.y; y <= dataWindow.max.y; ++y)
128
Rgba *pixel = base + dataWindow.min.x * xStride;
130
for (int x = dataWindow.min.x; x <= dataWindow.max.x; ++x)
133
pixel->r = _lut (pixel->r);
136
pixel->g = _lut (pixel->g);
139
pixel->b = _lut (pixel->b);
142
pixel->a = _lut (pixel->a);
155
const float middleval = pow (2.0, -2.5);
164
int12log = int (2000.5 + 200.0 * log (x / middleval) / log (2.0));
173
return middleval * pow (2.0, (int12log - 2000.0) / 200.0);