Coverage Report

Created: 2025-09-27 07:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opencv/3rdparty/openexr/IlmImf/ImfChannelList.cpp
Line
Count
Source
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
#include "ImfNamespace.h"
51
52
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
53
54
55
Channel::Channel (PixelType t, int xs, int ys, bool pl):
56
0
    type (t),
57
0
    xSampling (xs),
58
0
    ySampling (ys),
59
0
    pLinear (pl)
60
0
{
61
    // empty
62
0
}
63
64
65
bool  
66
Channel::operator == (const Channel &other) const
67
0
{
68
0
    return type == other.type &&
69
0
     xSampling == other.xSampling &&
70
0
     ySampling == other.ySampling &&
71
0
     pLinear == other.pLinear;
72
0
}
73
74
75
void  
76
ChannelList::insert (const char name[], const Channel &channel)
77
0
{
78
0
    if (name[0] == 0)
79
0
  THROW (IEX_NAMESPACE::ArgExc, "Image channel name cannot be an empty string.");
80
81
0
    _map[name] = channel;
82
0
}
83
84
85
void  
86
ChannelList::insert (const string &name, const Channel &channel)
87
0
{
88
0
    insert (name.c_str(), channel);
89
0
}
90
91
92
Channel &
93
ChannelList::operator [] (const char name[])
94
0
{
95
0
    ChannelMap::iterator i = _map.find (name);
96
97
0
    if (i == _map.end())
98
0
  THROW (IEX_NAMESPACE::ArgExc, "Cannot find image channel \"" << name << "\".");
99
100
0
    return i->second;
101
0
}
102
103
104
const Channel &
105
ChannelList::operator [] (const char name[]) const
106
0
{
107
0
    ChannelMap::const_iterator i = _map.find (name);
108
109
0
    if (i == _map.end())
110
0
  THROW (IEX_NAMESPACE::ArgExc, "Cannot find image channel \"" << name << "\".");
111
112
0
    return i->second;
113
0
}
114
115
116
Channel &
117
ChannelList::operator [] (const string &name)
118
0
{
119
0
    return this->operator[] (name.c_str());
120
0
}
121
122
123
const Channel &
124
ChannelList::operator [] (const string &name) const
125
0
{
126
0
    return this->operator[] (name.c_str());
127
0
}
128
129
130
Channel *
131
ChannelList::findChannel (const char name[])
132
0
{
133
0
    ChannelMap::iterator i = _map.find (name);
134
0
    return (i == _map.end())? 0: &i->second;
135
0
}
136
137
138
const Channel *
139
ChannelList::findChannel (const char name[]) const
140
0
{
141
0
    ChannelMap::const_iterator i = _map.find (name);
142
0
    return (i == _map.end())? 0: &i->second;
143
0
}
144
145
146
Channel *
147
ChannelList::findChannel (const string &name)
148
0
{
149
0
    return findChannel (name.c_str());
150
0
}
151
152
153
const Channel *
154
ChannelList::findChannel (const string &name) const
155
0
{
156
0
    return findChannel (name.c_str());
157
0
}
158
159
160
ChannelList::Iterator   
161
ChannelList::begin ()
162
0
{
163
0
    return _map.begin();
164
0
}
165
166
167
ChannelList::ConstIterator  
168
ChannelList::begin () const
169
0
{
170
0
    return _map.begin();
171
0
}
172
173
174
ChannelList::Iterator
175
ChannelList::end ()
176
0
{
177
0
    return _map.end();
178
0
}
179
180
181
ChannelList::ConstIterator  
182
ChannelList::end () const
183
0
{
184
0
    return _map.end();
185
0
}
186
187
188
ChannelList::Iterator
189
ChannelList::find (const char name[])
190
0
{
191
0
    return _map.find (name);
192
0
}
193
194
195
ChannelList::ConstIterator
196
ChannelList::find (const char name[]) const
197
0
{
198
0
    return _map.find (name);
199
0
}
200
201
202
ChannelList::Iterator
203
ChannelList::find (const string &name)
204
0
{
205
0
    return find (name.c_str());
206
0
}
207
208
209
ChannelList::ConstIterator
210
ChannelList::find (const string &name) const
211
0
{
212
0
    return find (name.c_str());
213
0
}
214
215
216
void
217
ChannelList::layers (set <string> &layerNames) const
218
0
{
219
0
    layerNames.clear();
220
221
0
    for (ConstIterator i = begin(); i != end(); ++i)
222
0
    {
223
0
  string layerName = i.name();
224
0
  size_t pos = layerName.rfind ('.');
225
226
0
  if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())
227
0
  {
228
0
      layerName.erase (pos);
229
0
      layerNames.insert (layerName);
230
0
  }
231
0
    }
232
0
}
233
234
235
void
236
ChannelList::channelsInLayer (const string &layerName,
237
            Iterator &first,
238
            Iterator &last)
239
0
{
240
0
    channelsWithPrefix (layerName + '.', first, last);
241
0
}
242
243
244
void
245
ChannelList::channelsInLayer (const string &layerName,
246
            ConstIterator &first,
247
            ConstIterator &last) const
248
0
{
249
0
    channelsWithPrefix (layerName + '.', first, last);
250
0
}
251
252
253
void    
254
ChannelList::channelsWithPrefix (const char prefix[],
255
         Iterator &first,
256
         Iterator &last)
257
0
{
258
0
    first = last = _map.lower_bound (prefix);
259
0
    size_t n = int(strlen (prefix));
260
261
0
    while (last != Iterator (_map.end()) &&
262
0
     strncmp (last.name(), prefix, n) <= 0)
263
0
    {
264
0
  ++last;
265
0
    }
266
0
}
267
268
269
void
270
ChannelList::channelsWithPrefix (const char prefix[],
271
         ConstIterator &first,
272
         ConstIterator &last) const
273
0
{
274
0
    first = last = _map.lower_bound (prefix);
275
0
    size_t n = strlen (prefix);
276
277
0
    while (last != ConstIterator (_map.end()) &&
278
0
     strncmp (last.name(), prefix, n) <= 0)
279
0
    {
280
0
  ++last;
281
0
    }
282
0
}
283
284
285
void    
286
ChannelList::channelsWithPrefix (const string &prefix,
287
         Iterator &first,
288
         Iterator &last)
289
0
{
290
0
    return channelsWithPrefix (prefix.c_str(), first, last);
291
0
}
292
293
294
void
295
ChannelList::channelsWithPrefix (const string &prefix,
296
         ConstIterator &first,
297
         ConstIterator &last) const
298
0
{
299
0
    return channelsWithPrefix (prefix.c_str(), first, last);
300
0
}
301
302
303
bool    
304
ChannelList::operator == (const ChannelList &other) const
305
0
{
306
0
    ConstIterator i = begin();
307
0
    ConstIterator j = other.begin();
308
309
0
    while (i != end() && j != other.end())
310
0
    {
311
0
  if (!(i.channel() == j.channel()))
312
0
      return false;
313
314
0
  ++i;
315
0
  ++j;
316
0
    }
317
318
0
    return i == end() && j == other.end();
319
0
}
320
321
322
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT