/usr/local/include/OpenEXR/ImfChannelList.h
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // SPDX-License-Identifier: BSD-3-Clause |
3 | | // Copyright (c) Contributors to the OpenEXR Project. |
4 | | // |
5 | | |
6 | | #ifndef INCLUDED_IMF_CHANNEL_LIST_H |
7 | | #define INCLUDED_IMF_CHANNEL_LIST_H |
8 | | |
9 | | //----------------------------------------------------------------------------- |
10 | | // |
11 | | // class Channel |
12 | | // class ChannelList |
13 | | // |
14 | | //----------------------------------------------------------------------------- |
15 | | |
16 | | #include "ImfForward.h" |
17 | | |
18 | | #include "ImfName.h" |
19 | | #include "ImfPixelType.h" |
20 | | |
21 | | #include <map> |
22 | | #include <set> |
23 | | #include <string> |
24 | | |
25 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
26 | | |
27 | | struct IMF_EXPORT_TYPE Channel |
28 | | { |
29 | | //------------------------------ |
30 | | // Data type; see ImfPixelType.h |
31 | | //------------------------------ |
32 | | |
33 | | PixelType type; |
34 | | |
35 | | //-------------------------------------------- |
36 | | // Subsampling: pixel (x, y) is present in the |
37 | | // channel only if |
38 | | // |
39 | | // x % xSampling == 0 && y % ySampling == 0 |
40 | | // |
41 | | //-------------------------------------------- |
42 | | |
43 | | int xSampling; |
44 | | int ySampling; |
45 | | |
46 | | //-------------------------------------------------------------- |
47 | | // Hint to lossy compression methods that indicates whether |
48 | | // human perception of the quantity represented by this channel |
49 | | // is closer to linear or closer to logarithmic. Compression |
50 | | // methods may optimize image quality by adjusting pixel data |
51 | | // quantization according to this hint. |
52 | | // For example, perception of red, green, blue and luminance is |
53 | | // approximately logarithmic; the difference between 0.1 and 0.2 |
54 | | // is perceived to be roughly the same as the difference between |
55 | | // 1.0 and 2.0. Perception of chroma coordinates tends to be |
56 | | // closer to linear than logarithmic; the difference between 0.1 |
57 | | // and 0.2 is perceived to be roughly the same as the difference |
58 | | // between 1.0 and 1.1. |
59 | | //-------------------------------------------------------------- |
60 | | |
61 | | bool pLinear; |
62 | | |
63 | | //------------ |
64 | | // Constructor |
65 | | //------------ |
66 | | |
67 | | IMF_EXPORT |
68 | | Channel ( |
69 | | PixelType type = HALF, |
70 | | int xSampling = 1, |
71 | | int ySampling = 1, |
72 | | bool pLinear = false); |
73 | | |
74 | | //------------ |
75 | | // Operator == |
76 | | //------------ |
77 | | |
78 | | IMF_EXPORT |
79 | | bool operator== (const Channel& other) const; |
80 | | }; |
81 | | |
82 | | class IMF_EXPORT_TYPE ChannelList |
83 | | { |
84 | | public: |
85 | | //-------------- |
86 | | // Add a channel |
87 | | //-------------- |
88 | | |
89 | | IMF_EXPORT |
90 | | void insert (const char name[], const Channel& channel); |
91 | | |
92 | | IMF_EXPORT |
93 | | void insert (const std::string& name, const Channel& channel); |
94 | | |
95 | | //------------------------------------------------------------------ |
96 | | // Access to existing channels: |
97 | | // |
98 | | // [n] Returns a reference to the channel with name n. |
99 | | // If no channel with name n exists, an IEX_NAMESPACE::ArgExc |
100 | | // is thrown. |
101 | | // |
102 | | // findChannel(n) Returns a pointer to the channel with name n, |
103 | | // or 0 if no channel with name n exists. |
104 | | // |
105 | | //------------------------------------------------------------------ |
106 | | |
107 | | IMF_EXPORT |
108 | | Channel& operator[] (const char name[]); |
109 | | IMF_EXPORT |
110 | | const Channel& operator[] (const char name[]) const; |
111 | | |
112 | | IMF_EXPORT |
113 | | Channel& operator[] (const std::string& name); |
114 | | IMF_EXPORT |
115 | | const Channel& operator[] (const std::string& name) const; |
116 | | |
117 | | IMF_EXPORT |
118 | | Channel* findChannel (const char name[]); |
119 | | IMF_EXPORT |
120 | | const Channel* findChannel (const char name[]) const; |
121 | | |
122 | | IMF_EXPORT |
123 | | Channel* findChannel (const std::string& name); |
124 | | IMF_EXPORT |
125 | | const Channel* findChannel (const std::string& name) const; |
126 | | |
127 | | //------------------------------------------- |
128 | | // Iterator-style access to existing channels |
129 | | //------------------------------------------- |
130 | | |
131 | | typedef std::map<Name, Channel> ChannelMap; |
132 | | |
133 | | class Iterator; |
134 | | class ConstIterator; |
135 | | |
136 | | IMF_EXPORT |
137 | | Iterator begin (); |
138 | | IMF_EXPORT |
139 | | ConstIterator begin () const; |
140 | | |
141 | | IMF_EXPORT |
142 | | Iterator end (); |
143 | | IMF_EXPORT |
144 | | ConstIterator end () const; |
145 | | |
146 | | IMF_EXPORT |
147 | | Iterator find (const char name[]); |
148 | | IMF_EXPORT |
149 | | ConstIterator find (const char name[]) const; |
150 | | |
151 | | IMF_EXPORT |
152 | | Iterator find (const std::string& name); |
153 | | IMF_EXPORT |
154 | | ConstIterator find (const std::string& name) const; |
155 | | |
156 | | //----------------------------------------------------------------- |
157 | | // Support for image layers: |
158 | | // |
159 | | // In an image file with many channels it is sometimes useful to |
160 | | // group the channels into "layers", that is, into sets of channels |
161 | | // that logically belong together. Grouping channels into layers |
162 | | // is done using a naming convention: channel C in layer L is |
163 | | // called "L.C". |
164 | | // |
165 | | // For example, a computer graphic image may contain separate |
166 | | // R, G and B channels for light that originated at each of |
167 | | // several different virtual light sources. The channels in |
168 | | // this image might be called "light1.R", "light1.G", "light1.B", |
169 | | // "light2.R", "light2.G", "light2.B", etc. |
170 | | // |
171 | | // Note that this naming convention allows layers to be nested; |
172 | | // for example, "light1.specular.R" identifies the "R" channel |
173 | | // in the "specular" sub-layer of layer "light1". |
174 | | // |
175 | | // Channel names that don't contain a "." or that contain a |
176 | | // "." only at the beginning or at the end are not considered |
177 | | // to be part of any layer. |
178 | | // |
179 | | // layers(lns) sorts the channels in this ChannelList |
180 | | // into layers and stores the names of |
181 | | // all layers, sorted alphabetically, |
182 | | // into string set lns. |
183 | | // |
184 | | // channelsInLayer(ln,f,l) stores a pair of iterators in f and l |
185 | | // such that the loop |
186 | | // |
187 | | // for (ConstIterator i = f; i != l; ++i) |
188 | | // ... |
189 | | // |
190 | | // iterates over all channels in layer ln. |
191 | | // channelsInLayer (ln, l, p) calls |
192 | | // channelsWithPrefix (ln + ".", l, p). |
193 | | // |
194 | | //----------------------------------------------------------------- |
195 | | |
196 | | IMF_EXPORT |
197 | | void layers (std::set<std::string>& layerNames) const; |
198 | | |
199 | | IMF_EXPORT |
200 | | void channelsInLayer ( |
201 | | const std::string& layerName, Iterator& first, Iterator& last); |
202 | | |
203 | | IMF_EXPORT |
204 | | void channelsInLayer ( |
205 | | const std::string& layerName, |
206 | | ConstIterator& first, |
207 | | ConstIterator& last) const; |
208 | | |
209 | | //------------------------------------------------------------------- |
210 | | // Find all channels whose name begins with a given prefix: |
211 | | // |
212 | | // channelsWithPrefix(p,f,l) stores a pair of iterators in f and l |
213 | | // such that the following loop iterates over all channels whose name |
214 | | // begins with string p: |
215 | | // |
216 | | // for (ConstIterator i = f; i != l; ++i) |
217 | | // ... |
218 | | // |
219 | | //------------------------------------------------------------------- |
220 | | |
221 | | IMF_EXPORT |
222 | | void |
223 | | channelsWithPrefix (const char prefix[], Iterator& first, Iterator& last); |
224 | | |
225 | | IMF_EXPORT |
226 | | void channelsWithPrefix ( |
227 | | const char prefix[], ConstIterator& first, ConstIterator& last) const; |
228 | | |
229 | | IMF_EXPORT |
230 | | void channelsWithPrefix ( |
231 | | const std::string& prefix, Iterator& first, Iterator& last); |
232 | | |
233 | | IMF_EXPORT |
234 | | void channelsWithPrefix ( |
235 | | const std::string& prefix, |
236 | | ConstIterator& first, |
237 | | ConstIterator& last) const; |
238 | | |
239 | | //------------ |
240 | | // Operator == |
241 | | //------------ |
242 | | |
243 | | IMF_EXPORT |
244 | | bool operator== (const ChannelList& other) const; |
245 | | |
246 | | private: |
247 | | ChannelMap _map; |
248 | | }; |
249 | | |
250 | | //---------- |
251 | | // Iterators |
252 | | //---------- |
253 | | |
254 | | class IMF_EXPORT_TYPE ChannelList::Iterator |
255 | | { |
256 | | public: |
257 | | IMF_EXPORT |
258 | | Iterator (); |
259 | | IMF_EXPORT |
260 | | Iterator (const ChannelList::ChannelMap::iterator& i); |
261 | | |
262 | | IMF_EXPORT |
263 | | Iterator& operator++ (); |
264 | | IMF_EXPORT |
265 | | Iterator operator++ (int); |
266 | | |
267 | | IMF_EXPORT |
268 | | const char* name () const; |
269 | | IMF_EXPORT |
270 | | Channel& channel () const; |
271 | | |
272 | | private: |
273 | | friend class ChannelList::ConstIterator; |
274 | | |
275 | | ChannelList::ChannelMap::iterator _i; |
276 | | }; |
277 | | |
278 | | class IMF_EXPORT_TYPE ChannelList::ConstIterator |
279 | | { |
280 | | public: |
281 | | IMF_EXPORT |
282 | | ConstIterator (); |
283 | | IMF_EXPORT |
284 | | ConstIterator (const ChannelList::ChannelMap::const_iterator& i); |
285 | | IMF_EXPORT |
286 | | ConstIterator (const ChannelList::Iterator& other); |
287 | | |
288 | | IMF_EXPORT |
289 | | ConstIterator& operator++ (); |
290 | | IMF_EXPORT |
291 | | ConstIterator operator++ (int); |
292 | | |
293 | | IMF_EXPORT |
294 | | const char* name () const; |
295 | | IMF_EXPORT |
296 | | const Channel& channel () const; |
297 | | |
298 | | private: |
299 | | friend bool operator== (const ConstIterator&, const ConstIterator&); |
300 | | friend bool operator!= (const ConstIterator&, const ConstIterator&); |
301 | | |
302 | | ChannelList::ChannelMap::const_iterator _i; |
303 | | }; |
304 | | |
305 | | //----------------- |
306 | | // Inline Functions |
307 | | //----------------- |
308 | | |
309 | | inline ChannelList::Iterator::Iterator () : _i () |
310 | | { |
311 | | // empty |
312 | | } |
313 | | |
314 | | inline ChannelList::Iterator::Iterator ( |
315 | | const ChannelList::ChannelMap::iterator& i) |
316 | | : _i (i) |
317 | | { |
318 | | // empty |
319 | | } |
320 | | |
321 | | inline ChannelList::Iterator& |
322 | | ChannelList::Iterator::operator++ () |
323 | | { |
324 | | ++_i; |
325 | | return *this; |
326 | | } |
327 | | |
328 | | inline ChannelList::Iterator |
329 | | ChannelList::Iterator::operator++ (int) |
330 | 0 | { |
331 | 0 | Iterator tmp = *this; |
332 | 0 | ++_i; |
333 | 0 | return tmp; |
334 | 0 | } |
335 | | |
336 | | inline const char* |
337 | | ChannelList::Iterator::name () const |
338 | | { |
339 | | return *_i->first; |
340 | | } |
341 | | |
342 | | inline Channel& |
343 | | ChannelList::Iterator::channel () const |
344 | 0 | { |
345 | 0 | return _i->second; |
346 | 0 | } |
347 | | |
348 | | inline ChannelList::ConstIterator::ConstIterator () : _i () |
349 | | { |
350 | | // empty |
351 | | } |
352 | | |
353 | | inline ChannelList::ConstIterator::ConstIterator ( |
354 | | const ChannelList::ChannelMap::const_iterator& i) |
355 | | : _i (i) |
356 | | { |
357 | | // empty |
358 | | } |
359 | | |
360 | | inline ChannelList::ConstIterator::ConstIterator ( |
361 | | const ChannelList::Iterator& other) |
362 | | : _i (other._i) |
363 | | { |
364 | | // empty |
365 | | } |
366 | | |
367 | | inline ChannelList::ConstIterator& |
368 | | ChannelList::ConstIterator::operator++ () |
369 | | { |
370 | | ++_i; |
371 | | return *this; |
372 | | } |
373 | | |
374 | | inline ChannelList::ConstIterator |
375 | | ChannelList::ConstIterator::operator++ (int) |
376 | 0 | { |
377 | 0 | ConstIterator tmp = *this; |
378 | 0 | ++_i; |
379 | 0 | return tmp; |
380 | 0 | } |
381 | | |
382 | | inline const char* |
383 | | ChannelList::ConstIterator::name () const |
384 | | { |
385 | | return *_i->first; |
386 | | } |
387 | | |
388 | | inline const Channel& |
389 | | ChannelList::ConstIterator::channel () const |
390 | | { |
391 | | return _i->second; |
392 | | } |
393 | | |
394 | | inline bool |
395 | | operator== ( |
396 | | const ChannelList::ConstIterator& x, const ChannelList::ConstIterator& y) |
397 | | { |
398 | | return x._i == y._i; |
399 | | } |
400 | | |
401 | | inline bool |
402 | | operator!= ( |
403 | | const ChannelList::ConstIterator& x, const ChannelList::ConstIterator& y) |
404 | | { |
405 | | return !(x == y); |
406 | | } |
407 | | |
408 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
409 | | |
410 | | #endif |