Coverage Report

Created: 2026-02-26 07:48

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