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/ImfFrameBuffer.h
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
#ifndef INCLUDED_IMF_FRAME_BUFFER_H
38
#define INCLUDED_IMF_FRAME_BUFFER_H
39
40
//-----------------------------------------------------------------------------
41
//
42
//      class Slice
43
//      class FrameBuffer
44
//
45
//-----------------------------------------------------------------------------
46
47
#include "ImfName.h"
48
#include "ImfPixelType.h"
49
#include "ImfExport.h"
50
#include "ImfNamespace.h"
51
52
#include <map>
53
#include <string>
54
55
56
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
57
58
59
//-------------------------------------------------------
60
// Description of a single slice of the frame buffer:
61
//
62
// Note -- terminology: as part of a file, a component of
63
// an image (e.g. red, green, blue, depth etc.) is called
64
// a "channel".  As part of a frame buffer, an image
65
// component is called a "slice".
66
//-------------------------------------------------------
67
68
struct Slice
69
{
70
    //------------------------------
71
    // Data type; see ImfPixelType.h
72
    //------------------------------
73
74
    PixelType           type;
75
76
77
    //---------------------------------------------------------------------
78
    // Memory layout:  The address of pixel (x, y) is
79
    //
80
    //  base + (xp / xSampling) * xStride + (yp / ySampling) * yStride
81
    //
82
    // where xp and yp are computed as follows:
83
    //
84
    //  * If we are reading or writing a scanline-based file:
85
    //
86
    //      xp = x
87
    //      yp = y
88
    //
89
    //  * If we are reading a tile whose upper left coorner is at (xt, yt):
90
    //
91
    //      if xTileCoords is true then xp = x - xt, else xp = x
92
    //      if yTileCoords is true then yp = y - yt, else yp = y
93
    //
94
    //---------------------------------------------------------------------
95
96
    char *              base;
97
    size_t              xStride;
98
    size_t              yStride;
99
100
101
    //--------------------------------------------
102
    // Subsampling: pixel (x, y) is present in the
103
    // slice only if 
104
    //
105
    //  x % xSampling == 0 && y % ySampling == 0
106
    //
107
    //--------------------------------------------
108
109
    int                 xSampling;
110
    int                 ySampling;
111
112
113
    //----------------------------------------------------------
114
    // Default value, used to fill the slice when a file without
115
    // a channel that corresponds to this slice is read.
116
    //----------------------------------------------------------
117
118
    double              fillValue;
119
    
120
121
    //-------------------------------------------------------
122
    // For tiled files, the xTileCoords and yTileCoords flags
123
    // determine whether pixel addressing is performed using
124
    // absolute coordinates or coordinates relative to a
125
    // tile's upper left corner.  (See the comment on base,
126
    // xStride and yStride, above.)
127
    //
128
    // For scanline-based files these flags have no effect;
129
    // pixel addressing is always done using absolute
130
    // coordinates.
131
    //-------------------------------------------------------
132
133
    bool                xTileCoords;
134
    bool                yTileCoords;
135
136
137
    //------------
138
    // Constructor
139
    //------------
140
141
    IMF_EXPORT
142
    Slice (PixelType type = HALF,
143
           char * base = 0,
144
           size_t xStride = 0,
145
           size_t yStride = 0,
146
           int xSampling = 1,
147
           int ySampling = 1,
148
           double fillValue = 0.0,
149
           bool xTileCoords = false,
150
           bool yTileCoords = false);
151
};
152
153
154
class FrameBuffer
155
{
156
  public:
157
158
    //------------
159
    // Add a slice
160
    //------------
161
162
    IMF_EXPORT
163
    void                        insert (const char name[],
164
                                        const Slice &slice);
165
166
    IMF_EXPORT
167
    void                        insert (const std::string &name,
168
                                        const Slice &slice);
169
170
    //----------------------------------------------------------------
171
    // Access to existing slices:
172
    //
173
    // [n]              Returns a reference to the slice with name n.
174
    //                  If no slice with name n exists, an IEX_NAMESPACE::ArgExc
175
    //                  is thrown.
176
    //
177
    // findSlice(n)     Returns a pointer to the slice with name n,
178
    //                  or 0 if no slice with name n exists.
179
    //
180
    //----------------------------------------------------------------
181
182
    IMF_EXPORT
183
    Slice &                     operator [] (const char name[]);
184
    IMF_EXPORT
185
    const Slice &               operator [] (const char name[]) const;
186
187
    IMF_EXPORT
188
    Slice &                     operator [] (const std::string &name);
189
    IMF_EXPORT
190
    const Slice &               operator [] (const std::string &name) const;
191
192
    IMF_EXPORT
193
    Slice *                     findSlice (const char name[]);
194
    IMF_EXPORT
195
    const Slice *               findSlice (const char name[]) const;
196
197
    IMF_EXPORT
198
    Slice *                     findSlice (const std::string &name);
199
    IMF_EXPORT
200
    const Slice *               findSlice (const std::string &name) const;
201
202
203
    //-----------------------------------------
204
    // Iterator-style access to existing slices
205
    //-----------------------------------------
206
207
    typedef std::map <Name, Slice> SliceMap;
208
209
    class Iterator;
210
    class ConstIterator;
211
212
    IMF_EXPORT
213
    Iterator                    begin ();
214
    IMF_EXPORT
215
    ConstIterator               begin () const;
216
217
    IMF_EXPORT
218
    Iterator                    end ();
219
    IMF_EXPORT
220
    ConstIterator               end () const;
221
222
    IMF_EXPORT
223
    Iterator                    find (const char name[]);
224
    IMF_EXPORT
225
    ConstIterator               find (const char name[]) const;
226
227
    IMF_EXPORT
228
    Iterator                    find (const std::string &name);
229
    IMF_EXPORT
230
    ConstIterator               find (const std::string &name) const;
231
232
  private:
233
234
    SliceMap                    _map;
235
};
236
237
238
//----------
239
// Iterators
240
//----------
241
242
class FrameBuffer::Iterator
243
{
244
  public:
245
246
    IMF_EXPORT
247
    Iterator ();
248
    IMF_EXPORT
249
    Iterator (const FrameBuffer::SliceMap::iterator &i);
250
251
    IMF_EXPORT
252
    Iterator &                  operator ++ ();
253
    IMF_EXPORT
254
    Iterator                    operator ++ (int);
255
256
    IMF_EXPORT
257
    const char *                name () const;
258
    IMF_EXPORT
259
    Slice &                     slice () const;
260
261
  private:
262
263
    friend class FrameBuffer::ConstIterator;
264
265
    FrameBuffer::SliceMap::iterator _i;
266
};
267
268
269
class FrameBuffer::ConstIterator
270
{
271
  public:
272
273
    IMF_EXPORT
274
    ConstIterator ();
275
    IMF_EXPORT
276
    ConstIterator (const FrameBuffer::SliceMap::const_iterator &i);
277
    IMF_EXPORT
278
    ConstIterator (const FrameBuffer::Iterator &other);
279
280
    IMF_EXPORT
281
    ConstIterator &             operator ++ ();
282
    IMF_EXPORT
283
    ConstIterator               operator ++ (int);
284
285
    IMF_EXPORT
286
    const char *                name () const;
287
    IMF_EXPORT
288
    const Slice &               slice () const;
289
290
  private:
291
292
    friend bool operator == (const ConstIterator &, const ConstIterator &);
293
    friend bool operator != (const ConstIterator &, const ConstIterator &);
294
295
    FrameBuffer::SliceMap::const_iterator _i;
296
};
297
298
299
//-----------------
300
// Inline Functions
301
//-----------------
302
303
inline
304
FrameBuffer::Iterator::Iterator (): _i()
305
{
306
    // empty
307
}
308
309
310
inline
311
FrameBuffer::Iterator::Iterator (const FrameBuffer::SliceMap::iterator &i):
312
0
    _i (i)
313
0
{
314
    // empty
315
0
}
316
317
318
inline FrameBuffer::Iterator &
319
FrameBuffer::Iterator::operator ++ ()
320
0
{
321
0
    ++_i;
322
0
    return *this;
323
0
}
324
325
326
inline FrameBuffer::Iterator
327
FrameBuffer::Iterator::operator ++ (int)
328
0
{
329
0
    Iterator tmp = *this;
330
0
    ++_i;
331
0
    return tmp;
332
0
}
333
334
335
inline const char *
336
FrameBuffer::Iterator::name () const
337
0
{
338
0
    return *_i->first;
339
0
}
340
341
342
inline Slice &
343
FrameBuffer::Iterator::slice () const
344
0
{
345
0
    return _i->second;
346
0
}
347
348
349
inline
350
FrameBuffer::ConstIterator::ConstIterator (): _i()
351
{
352
    // empty
353
}
354
355
inline
356
FrameBuffer::ConstIterator::ConstIterator
357
0
    (const FrameBuffer::SliceMap::const_iterator &i): _i (i)
358
0
{
359
    // empty
360
0
}
361
362
363
inline
364
FrameBuffer::ConstIterator::ConstIterator (const FrameBuffer::Iterator &other):
365
0
    _i (other._i)
366
0
{
367
    // empty
368
0
}
369
370
inline FrameBuffer::ConstIterator &
371
FrameBuffer::ConstIterator::operator ++ ()
372
0
{
373
0
    ++_i;
374
0
    return *this;
375
0
}
376
377
378
inline FrameBuffer::ConstIterator
379
FrameBuffer::ConstIterator::operator ++ (int)
380
0
{
381
0
    ConstIterator tmp = *this;
382
0
    ++_i;
383
0
    return tmp;
384
0
}
385
386
387
inline const char *
388
FrameBuffer::ConstIterator::name () const
389
0
{
390
0
    return *_i->first;
391
0
}
392
393
inline const Slice &
394
FrameBuffer::ConstIterator::slice () const
395
0
{
396
0
    return _i->second;
397
0
}
398
399
400
inline bool
401
operator == (const FrameBuffer::ConstIterator &x,
402
             const FrameBuffer::ConstIterator &y)
403
0
{
404
0
    return x._i == y._i;
405
0
}
406
407
408
inline bool
409
operator != (const FrameBuffer::ConstIterator &x,
410
             const FrameBuffer::ConstIterator &y)
411
0
{
412
0
    return !(x == y);
413
0
}
414
415
416
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
417
418
#endif