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

« back to all changes in this revision

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

  • Committer: Stefano Rivera
  • Date: 2010-07-24 15:35:51 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: stefanor@ubuntu.com-20100724153551-6s3fth1653huk31a
Tags: upstream-3.13.1
ImportĀ upstreamĀ versionĀ 3.31.1

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
 
//      class Channel
40
 
//      class ChannelList
41
 
//
42
 
//-----------------------------------------------------------------------------
43
 
 
44
 
#include <ImfChannelList.h>
45
 
#include <Iex.h>
46
 
 
47
 
 
48
 
using std::string;
49
 
using std::set;
50
 
 
51
 
namespace Imf {
52
 
 
53
 
 
54
 
Channel::Channel (PixelType t, int xs, int ys, bool pl):
55
 
    type (t),
56
 
    xSampling (xs),
57
 
    ySampling (ys),
58
 
    pLinear (pl)
59
 
{
60
 
    // empty
61
 
}
62
 
 
63
 
 
64
 
bool    
65
 
Channel::operator == (const Channel &other) const
66
 
{
67
 
    return type == other.type &&
68
 
           xSampling == other.xSampling &&
69
 
           ySampling == other.ySampling &&
70
 
           pLinear == other.pLinear;
71
 
}
72
 
 
73
 
 
74
 
void    
75
 
ChannelList::insert (const char name[], const Channel &channel)
76
 
{
77
 
    if (name[0] == 0)
78
 
        THROW (Iex::ArgExc, "Image channel name cannot be an empty string.");
79
 
 
80
 
    _map[name] = channel;
81
 
}
82
 
 
83
 
 
84
 
Channel &
85
 
ChannelList::operator [] (const char name[])
86
 
{
87
 
    ChannelMap::iterator i = _map.find (name);
88
 
 
89
 
    if (i == _map.end())
90
 
        THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
91
 
 
92
 
    return i->second;
93
 
}
94
 
 
95
 
 
96
 
const Channel &
97
 
ChannelList::operator [] (const char name[]) const
98
 
{
99
 
    ChannelMap::const_iterator i = _map.find (name);
100
 
 
101
 
    if (i == _map.end())
102
 
        THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
103
 
 
104
 
    return i->second;
105
 
}
106
 
 
107
 
 
108
 
Channel *
109
 
ChannelList::findChannel (const char name[])
110
 
{
111
 
    ChannelMap::iterator i = _map.find (name);
112
 
    return (i == _map.end())? 0: &i->second;
113
 
}
114
 
 
115
 
 
116
 
const Channel *
117
 
ChannelList::findChannel (const char name[]) const
118
 
{
119
 
    ChannelMap::const_iterator i = _map.find (name);
120
 
    return (i == _map.end())? 0: &i->second;
121
 
}
122
 
 
123
 
 
124
 
ChannelList::Iterator           
125
 
ChannelList::begin ()
126
 
{
127
 
    return _map.begin();
128
 
}
129
 
 
130
 
 
131
 
ChannelList::ConstIterator      
132
 
ChannelList::begin () const
133
 
{
134
 
    return _map.begin();
135
 
}
136
 
 
137
 
 
138
 
ChannelList::Iterator
139
 
ChannelList::end ()
140
 
{
141
 
    return _map.end();
142
 
}
143
 
 
144
 
 
145
 
ChannelList::ConstIterator      
146
 
ChannelList::end () const
147
 
{
148
 
    return _map.end();
149
 
}
150
 
 
151
 
 
152
 
ChannelList::Iterator
153
 
ChannelList::find (const char name[])
154
 
{
155
 
    return _map.find (name);
156
 
}
157
 
 
158
 
 
159
 
ChannelList::ConstIterator
160
 
ChannelList::find (const char name[]) const
161
 
{
162
 
    return _map.find (name);
163
 
}
164
 
 
165
 
 
166
 
void
167
 
ChannelList::layers (set <string> &layerNames) const
168
 
{
169
 
    layerNames.clear();
170
 
 
171
 
    for (ConstIterator i = begin(); i != end(); ++i)
172
 
    {
173
 
        string layerName = i.name();
174
 
        size_t pos = layerName.rfind ('.');
175
 
 
176
 
        if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())
177
 
        {
178
 
            layerName.erase (pos);
179
 
            layerNames.insert (layerName);
180
 
        }
181
 
    }
182
 
}
183
 
 
184
 
 
185
 
void
186
 
ChannelList::channelsInLayer (const string &layerName,
187
 
                              Iterator &first,
188
 
                              Iterator &last)
189
 
{
190
 
    channelsWithPrefix ((layerName + '.').c_str(), first, last);
191
 
}
192
 
 
193
 
 
194
 
void
195
 
ChannelList::channelsInLayer (const string &layerName,
196
 
                              ConstIterator &first,
197
 
                              ConstIterator &last) const
198
 
{
199
 
    channelsWithPrefix ((layerName + '.').c_str(), first, last);
200
 
}
201
 
 
202
 
 
203
 
void            
204
 
ChannelList::channelsWithPrefix (const char prefix[],
205
 
                                 Iterator &first,
206
 
                                 Iterator &last)
207
 
{
208
 
    first = last = _map.lower_bound (prefix);
209
 
    int n = strlen (prefix);
210
 
 
211
 
    while (last != Iterator (_map.end()) &&
212
 
           strncmp (last.name(), prefix, n) <= 0)
213
 
    {
214
 
        ++last;
215
 
    }
216
 
}
217
 
 
218
 
 
219
 
void
220
 
ChannelList::channelsWithPrefix (const char prefix[],
221
 
                                 ConstIterator &first,
222
 
                                 ConstIterator &last) const
223
 
{
224
 
    first = last = _map.lower_bound (prefix);
225
 
    int n = strlen (prefix);
226
 
 
227
 
    while (last != ConstIterator (_map.end()) &&
228
 
           strncmp (last.name(), prefix, n) <= 0)
229
 
    {
230
 
        ++last;
231
 
    }
232
 
}
233
 
 
234
 
 
235
 
bool            
236
 
ChannelList::operator == (const ChannelList &other) const
237
 
{
238
 
    ConstIterator i = begin();
239
 
    ConstIterator j = other.begin();
240
 
 
241
 
    while (i != end() && j != other.end())
242
 
    {
243
 
        if (!(i.channel() == j.channel()))
244
 
            return false;
245
 
 
246
 
        ++i;
247
 
        ++j;
248
 
    }
249
 
 
250
 
    return i == end() && j == other.end();
251
 
}
252
 
 
253
 
 
254
 
} // 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
//      class Channel
 
40
//      class ChannelList
 
41
//
 
42
//-----------------------------------------------------------------------------
 
43
 
 
44
#include <ImfChannelList.h>
 
45
#include <Iex.h>
 
46
 
 
47
 
 
48
using std::string;
 
49
using std::set;
 
50
 
 
51
namespace Imf {
 
52
 
 
53
 
 
54
Channel::Channel (PixelType t, int xs, int ys, bool pl):
 
55
    type (t),
 
56
    xSampling (xs),
 
57
    ySampling (ys),
 
58
    pLinear (pl)
 
59
{
 
60
    // empty
 
61
}
 
62
 
 
63
 
 
64
bool    
 
65
Channel::operator == (const Channel &other) const
 
66
{
 
67
    return type == other.type &&
 
68
           xSampling == other.xSampling &&
 
69
           ySampling == other.ySampling &&
 
70
           pLinear == other.pLinear;
 
71
}
 
72
 
 
73
 
 
74
void    
 
75
ChannelList::insert (const char name[], const Channel &channel)
 
76
{
 
77
    if (name[0] == 0)
 
78
        THROW (Iex::ArgExc, "Image channel name cannot be an empty string.");
 
79
 
 
80
    _map[name] = channel;
 
81
}
 
82
 
 
83
 
 
84
Channel &
 
85
ChannelList::operator [] (const char name[])
 
86
{
 
87
    ChannelMap::iterator i = _map.find (name);
 
88
 
 
89
    if (i == _map.end())
 
90
        THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
 
91
 
 
92
    return i->second;
 
93
}
 
94
 
 
95
 
 
96
const Channel &
 
97
ChannelList::operator [] (const char name[]) const
 
98
{
 
99
    ChannelMap::const_iterator i = _map.find (name);
 
100
 
 
101
    if (i == _map.end())
 
102
        THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");
 
103
 
 
104
    return i->second;
 
105
}
 
106
 
 
107
 
 
108
Channel *
 
109
ChannelList::findChannel (const char name[])
 
110
{
 
111
    ChannelMap::iterator i = _map.find (name);
 
112
    return (i == _map.end())? 0: &i->second;
 
113
}
 
114
 
 
115
 
 
116
const Channel *
 
117
ChannelList::findChannel (const char name[]) const
 
118
{
 
119
    ChannelMap::const_iterator i = _map.find (name);
 
120
    return (i == _map.end())? 0: &i->second;
 
121
}
 
122
 
 
123
 
 
124
ChannelList::Iterator           
 
125
ChannelList::begin ()
 
126
{
 
127
    return _map.begin();
 
128
}
 
129
 
 
130
 
 
131
ChannelList::ConstIterator      
 
132
ChannelList::begin () const
 
133
{
 
134
    return _map.begin();
 
135
}
 
136
 
 
137
 
 
138
ChannelList::Iterator
 
139
ChannelList::end ()
 
140
{
 
141
    return _map.end();
 
142
}
 
143
 
 
144
 
 
145
ChannelList::ConstIterator      
 
146
ChannelList::end () const
 
147
{
 
148
    return _map.end();
 
149
}
 
150
 
 
151
 
 
152
ChannelList::Iterator
 
153
ChannelList::find (const char name[])
 
154
{
 
155
    return _map.find (name);
 
156
}
 
157
 
 
158
 
 
159
ChannelList::ConstIterator
 
160
ChannelList::find (const char name[]) const
 
161
{
 
162
    return _map.find (name);
 
163
}
 
164
 
 
165
 
 
166
void
 
167
ChannelList::layers (set <string> &layerNames) const
 
168
{
 
169
    layerNames.clear();
 
170
 
 
171
    for (ConstIterator i = begin(); i != end(); ++i)
 
172
    {
 
173
        string layerName = i.name();
 
174
        size_t pos = layerName.rfind ('.');
 
175
 
 
176
        if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())
 
177
        {
 
178
            layerName.erase (pos);
 
179
            layerNames.insert (layerName);
 
180
        }
 
181
    }
 
182
}
 
183
 
 
184
 
 
185
void
 
186
ChannelList::channelsInLayer (const string &layerName,
 
187
                              Iterator &first,
 
188
                              Iterator &last)
 
189
{
 
190
    channelsWithPrefix ((layerName + '.').c_str(), first, last);
 
191
}
 
192
 
 
193
 
 
194
void
 
195
ChannelList::channelsInLayer (const string &layerName,
 
196
                              ConstIterator &first,
 
197
                              ConstIterator &last) const
 
198
{
 
199
    channelsWithPrefix ((layerName + '.').c_str(), first, last);
 
200
}
 
201
 
 
202
 
 
203
void            
 
204
ChannelList::channelsWithPrefix (const char prefix[],
 
205
                                 Iterator &first,
 
206
                                 Iterator &last)
 
207
{
 
208
    first = last = _map.lower_bound (prefix);
 
209
    int n = strlen (prefix);
 
210
 
 
211
    while (last != Iterator (_map.end()) &&
 
212
           strncmp (last.name(), prefix, n) <= 0)
 
213
    {
 
214
        ++last;
 
215
    }
 
216
}
 
217
 
 
218
 
 
219
void
 
220
ChannelList::channelsWithPrefix (const char prefix[],
 
221
                                 ConstIterator &first,
 
222
                                 ConstIterator &last) const
 
223
{
 
224
    first = last = _map.lower_bound (prefix);
 
225
    int n = strlen (prefix);
 
226
 
 
227
    while (last != ConstIterator (_map.end()) &&
 
228
           strncmp (last.name(), prefix, n) <= 0)
 
229
    {
 
230
        ++last;
 
231
    }
 
232
}
 
233
 
 
234
 
 
235
bool            
 
236
ChannelList::operator == (const ChannelList &other) const
 
237
{
 
238
    ConstIterator i = begin();
 
239
    ConstIterator j = other.begin();
 
240
 
 
241
    while (i != end() && j != other.end())
 
242
    {
 
243
        if (!(i.channel() == j.channel()))
 
244
            return false;
 
245
 
 
246
        ++i;
 
247
        ++j;
 
248
    }
 
249
 
 
250
    return i == end() && j == other.end();
 
251
}
 
252
 
 
253
 
 
254
} // namespace Imf