~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/OpenEXR/IlmImf/ImfLut.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

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
 
//-----------------------------------------------------------------------------
38
 
//
39
 
//      Lookup tables for efficient application
40
 
//      of half --> half functions to pixel data,
41
 
//      and some commonly applied functions.
42
 
//
43
 
//-----------------------------------------------------------------------------
44
 
 
45
 
#include <ImfLut.h>
46
 
#include <math.h>
47
 
#include <assert.h>
48
 
 
49
 
namespace Imf {
50
 
 
51
 
 
52
 
void
53
 
HalfLut::apply (half *data, int nData, int stride) const
54
 
{
55
 
    while (nData)
56
 
    {
57
 
        *data = _lut (*data);
58
 
        data += stride;
59
 
        nData -= 1;
60
 
    }
61
 
}
62
 
 
63
 
 
64
 
void
65
 
HalfLut::apply (const Slice &data, const Imath::Box2i &dataWindow) const
66
 
{
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);
72
 
 
73
 
    char *base = data.base + data.yStride *
74
 
                 (dataWindow.min.y / data.ySampling);
75
 
 
76
 
    for (int y = dataWindow.min.y;
77
 
         y <= dataWindow.max.y;
78
 
         y += data.ySampling)
79
 
    {
80
 
        char *pixel = base + data.xStride *
81
 
                      (dataWindow.min.x / data.xSampling);
82
 
 
83
 
        for (int x = dataWindow.min.x;
84
 
             x <= dataWindow.max.x;
85
 
             x += data.xSampling)
86
 
        {
87
 
            *(half *)pixel = _lut (*(half *)pixel);
88
 
            pixel += data.xStride;
89
 
        }
90
 
 
91
 
        base += data.yStride;
92
 
    }
93
 
}
94
 
 
95
 
 
96
 
void
97
 
RgbaLut::apply (Rgba *data, int nData, int stride) const
98
 
{
99
 
    while (nData)
100
 
    {
101
 
        if (_chn & WRITE_R)
102
 
            data->r = _lut (data->r);
103
 
 
104
 
        if (_chn & WRITE_G)
105
 
            data->g = _lut (data->g);
106
 
 
107
 
        if (_chn & WRITE_B)
108
 
            data->b = _lut (data->b);
109
 
 
110
 
        if (_chn & WRITE_A)
111
 
            data->a = _lut (data->a);
112
 
 
113
 
        data += stride;
114
 
        nData -= 1;
115
 
    }
116
 
}
117
 
 
118
 
 
119
 
void
120
 
RgbaLut::apply (Rgba *base,
121
 
                int xStride, int yStride,
122
 
                const Imath::Box2i &dataWindow) const
123
 
{
124
 
    base += dataWindow.min.y * yStride;
125
 
 
126
 
    for (int y = dataWindow.min.y; y <= dataWindow.max.y; ++y)
127
 
    {
128
 
        Rgba *pixel = base + dataWindow.min.x * xStride;
129
 
 
130
 
        for (int x = dataWindow.min.x; x <= dataWindow.max.x; ++x)
131
 
        {
132
 
            if (_chn & WRITE_R)
133
 
                pixel->r = _lut (pixel->r);
134
 
 
135
 
            if (_chn & WRITE_G)
136
 
                pixel->g = _lut (pixel->g);
137
 
 
138
 
            if (_chn & WRITE_B)
139
 
                pixel->b = _lut (pixel->b);
140
 
 
141
 
            if (_chn & WRITE_A)
142
 
                pixel->a = _lut (pixel->a);
143
 
 
144
 
            pixel += xStride;
145
 
        }
146
 
 
147
 
        base += yStride;
148
 
    }
149
 
}
150
 
 
151
 
 
152
 
half
153
 
round12log (half x)
154
 
{
155
 
    const float middleval = pow (2.0, -2.5);
156
 
    int int12log;
157
 
 
158
 
    if (x <= 0)
159
 
    {
160
 
        return 0;
161
 
    }
162
 
    else
163
 
    {
164
 
        int12log = int (2000.5 + 200.0 * log (x / middleval) / log (2.0));
165
 
 
166
 
        if (int12log > 4095)
167
 
            int12log = 4095;
168
 
 
169
 
        if (int12log < 1)
170
 
            int12log = 1;
171
 
    }
172
 
 
173
 
    return middleval * pow (2.0, (int12log - 2000.0) / 200.0);
174
 
}
175
 
 
176
 
} // namespace Imf
 
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
//-----------------------------------------------------------------------------
 
38
//
 
39
//      Lookup tables for efficient application
 
40
//      of half --> half functions to pixel data,
 
41
//      and some commonly applied functions.
 
42
//
 
43
//-----------------------------------------------------------------------------
 
44
 
 
45
#include <ImfLut.h>
 
46
#include <math.h>
 
47
#include <assert.h>
 
48
 
 
49
namespace Imf {
 
50
 
 
51
 
 
52
void
 
53
HalfLut::apply (half *data, int nData, int stride) const
 
54
{
 
55
    while (nData)
 
56
    {
 
57
        *data = _lut (*data);
 
58
        data += stride;
 
59
        nData -= 1;
 
60
    }
 
61
}
 
62
 
 
63
 
 
64
void
 
65
HalfLut::apply (const Slice &data, const Imath::Box2i &dataWindow) const
 
66
{
 
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);
 
72
 
 
73
    char *base = data.base + data.yStride *
 
74
                 (dataWindow.min.y / data.ySampling);
 
75
 
 
76
    for (int y = dataWindow.min.y;
 
77
         y <= dataWindow.max.y;
 
78
         y += data.ySampling)
 
79
    {
 
80
        char *pixel = base + data.xStride *
 
81
                      (dataWindow.min.x / data.xSampling);
 
82
 
 
83
        for (int x = dataWindow.min.x;
 
84
             x <= dataWindow.max.x;
 
85
             x += data.xSampling)
 
86
        {
 
87
            *(half *)pixel = _lut (*(half *)pixel);
 
88
            pixel += data.xStride;
 
89
        }
 
90
 
 
91
        base += data.yStride;
 
92
    }
 
93
}
 
94
 
 
95
 
 
96
void
 
97
RgbaLut::apply (Rgba *data, int nData, int stride) const
 
98
{
 
99
    while (nData)
 
100
    {
 
101
        if (_chn & WRITE_R)
 
102
            data->r = _lut (data->r);
 
103
 
 
104
        if (_chn & WRITE_G)
 
105
            data->g = _lut (data->g);
 
106
 
 
107
        if (_chn & WRITE_B)
 
108
            data->b = _lut (data->b);
 
109
 
 
110
        if (_chn & WRITE_A)
 
111
            data->a = _lut (data->a);
 
112
 
 
113
        data += stride;
 
114
        nData -= 1;
 
115
    }
 
116
}
 
117
 
 
118
 
 
119
void
 
120
RgbaLut::apply (Rgba *base,
 
121
                int xStride, int yStride,
 
122
                const Imath::Box2i &dataWindow) const
 
123
{
 
124
    base += dataWindow.min.y * yStride;
 
125
 
 
126
    for (int y = dataWindow.min.y; y <= dataWindow.max.y; ++y)
 
127
    {
 
128
        Rgba *pixel = base + dataWindow.min.x * xStride;
 
129
 
 
130
        for (int x = dataWindow.min.x; x <= dataWindow.max.x; ++x)
 
131
        {
 
132
            if (_chn & WRITE_R)
 
133
                pixel->r = _lut (pixel->r);
 
134
 
 
135
            if (_chn & WRITE_G)
 
136
                pixel->g = _lut (pixel->g);
 
137
 
 
138
            if (_chn & WRITE_B)
 
139
                pixel->b = _lut (pixel->b);
 
140
 
 
141
            if (_chn & WRITE_A)
 
142
                pixel->a = _lut (pixel->a);
 
143
 
 
144
            pixel += xStride;
 
145
        }
 
146
 
 
147
        base += yStride;
 
148
    }
 
149
}
 
150
 
 
151
 
 
152
half
 
153
round12log (half x)
 
154
{
 
155
    const float middleval = pow (2.0, -2.5);
 
156
    int int12log;
 
157
 
 
158
    if (x <= 0)
 
159
    {
 
160
        return 0;
 
161
    }
 
162
    else
 
163
    {
 
164
        int12log = int (2000.5 + 200.0 * log (x / middleval) / log (2.0));
 
165
 
 
166
        if (int12log > 4095)
 
167
            int12log = 4095;
 
168
 
 
169
        if (int12log < 1)
 
170
            int12log = 1;
 
171
    }
 
172
 
 
173
    return middleval * pow (2.0, (int12log - 2000.0) / 200.0);
 
174
}
 
175
 
 
176
} // namespace Imf