Coverage Report

Created: 2025-07-16 07:53

/src/openexr/src/lib/OpenEXR/ImfDeepFrameBuffer.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 IMFDEEPFRAMEBUFFER_H_
7
#define IMFDEEPFRAMEBUFFER_H_
8
9
#include "ImfForward.h"
10
11
#include "ImfFrameBuffer.h"
12
13
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
14
15
//--------------------------------------------------------
16
// Description of a single deep slice of the frame buffer:
17
//--------------------------------------------------------
18
19
struct IMF_EXPORT_TYPE DeepSlice : public Slice
20
{
21
    //---------------------------------------------------------------------
22
    // The stride for each sample in this slice.
23
    //
24
    // Memory layout:  The address of sample i in pixel (x, y) is
25
    //
26
    //  base + (xp / xSampling) * xStride + (yp / ySampling) * yStride
27
    //       + i * sampleStride
28
    //
29
    // where xp and yp are computed as follows:
30
    //
31
    //  * If we are reading or writing a scanline-based file:
32
    //
33
    //      xp = x
34
    //      yp = y
35
    //
36
    //  * If we are reading a tile whose upper left coorner is at (xt, yt):
37
    //
38
    //      if xTileCoords is true then xp = x - xt, else xp = x
39
    //      if yTileCoords is true then yp = y - yt, else yp = y
40
    //
41
    //---------------------------------------------------------------------
42
43
    int sampleStride;
44
45
    //------------
46
    // Constructor
47
    //------------
48
    IMF_EXPORT
49
    DeepSlice (
50
        PixelType type         = HALF,
51
        char*     base         = 0,
52
        size_t    xStride      = 0,
53
        size_t    yStride      = 0,
54
        size_t    sampleStride = 0,
55
        int       xSampling    = 1,
56
        int       ySampling    = 1,
57
        double    fillValue    = 0.0,
58
        bool      xTileCoords  = false,
59
        bool      yTileCoords  = false);
60
};
61
62
//-----------------
63
// DeepFrameBuffer.
64
//-----------------
65
66
class IMF_EXPORT_TYPE DeepFrameBuffer
67
{
68
public:
69
    //------------
70
    // Add a slice
71
    //------------
72
73
    IMF_EXPORT
74
    void insert (const char name[], const DeepSlice& slice);
75
76
    IMF_EXPORT
77
    void insert (const std::string& name, const DeepSlice& slice);
78
79
    //----------------------------------------------------------------
80
    // Access to existing slices:
81
    //
82
    // [n]              Returns a reference to the slice with name n.
83
    //                  If no slice with name n exists, an IEX_NAMESPACE::ArgExc
84
    //                  is thrown.
85
    //
86
    // findSlice(n)     Returns a pointer to the slice with name n,
87
    //                  or 0 if no slice with name n exists.
88
    //
89
    //----------------------------------------------------------------
90
91
    IMF_EXPORT
92
    DeepSlice& operator[] (const char name[]);
93
    IMF_EXPORT
94
    const DeepSlice& operator[] (const char name[]) const;
95
96
    IMF_EXPORT
97
    DeepSlice& operator[] (const std::string& name);
98
    IMF_EXPORT
99
    const DeepSlice& operator[] (const std::string& name) const;
100
101
    IMF_EXPORT
102
    DeepSlice* findSlice (const char name[]);
103
    IMF_EXPORT
104
    const DeepSlice* findSlice (const char name[]) const;
105
106
    IMF_EXPORT
107
    DeepSlice* findSlice (const std::string& name);
108
    IMF_EXPORT
109
    const DeepSlice* findSlice (const std::string& name) const;
110
111
    //-----------------------------------------
112
    // Iterator-style access to existing slices
113
    //-----------------------------------------
114
115
    typedef std::map<Name, DeepSlice> SliceMap;
116
117
    class Iterator;
118
    class ConstIterator;
119
120
    IMF_EXPORT
121
    Iterator begin ();
122
    IMF_EXPORT
123
    ConstIterator begin () const;
124
125
    IMF_EXPORT
126
    Iterator end ();
127
    IMF_EXPORT
128
    ConstIterator end () const;
129
130
    IMF_EXPORT
131
    Iterator find (const char name[]);
132
    IMF_EXPORT
133
    ConstIterator find (const char name[]) const;
134
135
    IMF_EXPORT
136
    Iterator find (const std::string& name);
137
    IMF_EXPORT
138
    ConstIterator find (const std::string& name) const;
139
140
    //----------------------------------------------------
141
    // Public function for accessing a sample count slice.
142
    //----------------------------------------------------
143
144
    IMF_EXPORT
145
    void insertSampleCountSlice (const Slice& slice);
146
    IMF_EXPORT
147
    const Slice& getSampleCountSlice () const;
148
149
private:
150
    SliceMap _map;
151
    Slice    _sampleCounts;
152
};
153
154
//----------
155
// Iterators
156
//----------
157
158
class IMF_EXPORT_TYPE DeepFrameBuffer::Iterator
159
{
160
public:
161
    IMF_EXPORT
162
    Iterator ();
163
    IMF_EXPORT
164
    Iterator (const DeepFrameBuffer::SliceMap::iterator& i);
165
166
    IMF_EXPORT
167
    Iterator& operator++ ();
168
    IMF_EXPORT
169
    Iterator operator++ (int);
170
171
    IMF_EXPORT
172
    const char* name () const;
173
    IMF_EXPORT
174
    DeepSlice& slice () const;
175
176
private:
177
    friend class DeepFrameBuffer::ConstIterator;
178
179
    DeepFrameBuffer::SliceMap::iterator _i;
180
};
181
182
class IMF_EXPORT_TYPE DeepFrameBuffer::ConstIterator
183
{
184
public:
185
    IMF_EXPORT
186
    ConstIterator ();
187
    IMF_EXPORT
188
    ConstIterator (const DeepFrameBuffer::SliceMap::const_iterator& i);
189
    IMF_EXPORT
190
    ConstIterator (const DeepFrameBuffer::Iterator& other);
191
192
    IMF_EXPORT
193
    ConstIterator& operator++ ();
194
    IMF_EXPORT
195
    ConstIterator operator++ (int);
196
197
    IMF_EXPORT
198
    const char* name () const;
199
    IMF_EXPORT
200
    const DeepSlice& slice () const;
201
202
private:
203
    friend bool operator== (const ConstIterator&, const ConstIterator&);
204
    friend bool operator!= (const ConstIterator&, const ConstIterator&);
205
206
    DeepFrameBuffer::SliceMap::const_iterator _i;
207
};
208
209
//-----------------
210
// Inline Functions
211
//-----------------
212
213
inline DeepFrameBuffer::Iterator::Iterator () : _i ()
214
{
215
    // empty
216
}
217
218
inline DeepFrameBuffer::Iterator::Iterator (
219
    const DeepFrameBuffer::SliceMap::iterator& i)
220
0
    : _i (i)
221
0
{
222
    // empty
223
0
}
224
225
inline DeepFrameBuffer::Iterator&
226
DeepFrameBuffer::Iterator::operator++ ()
227
0
{
228
0
    ++_i;
229
0
    return *this;
230
0
}
231
232
inline DeepFrameBuffer::Iterator
233
DeepFrameBuffer::Iterator::operator++ (int)
234
0
{
235
0
    Iterator tmp = *this;
236
0
    ++_i;
237
0
    return tmp;
238
0
}
239
240
inline const char*
241
DeepFrameBuffer::Iterator::name () const
242
0
{
243
0
    return *_i->first;
244
0
}
245
246
inline DeepSlice&
247
DeepFrameBuffer::Iterator::slice () const
248
0
{
249
0
    return _i->second;
250
0
}
251
252
inline DeepFrameBuffer::ConstIterator::ConstIterator () : _i ()
253
{
254
    // empty
255
}
256
257
inline DeepFrameBuffer::ConstIterator::ConstIterator (
258
    const DeepFrameBuffer::SliceMap::const_iterator& i)
259
7.12k
    : _i (i)
260
7.12k
{
261
    // empty
262
7.12k
}
263
264
inline DeepFrameBuffer::ConstIterator::ConstIterator (
265
    const DeepFrameBuffer::Iterator& other)
266
    : _i (other._i)
267
{
268
    // empty
269
}
270
271
inline DeepFrameBuffer::ConstIterator&
272
DeepFrameBuffer::ConstIterator::operator++ ()
273
5.08k
{
274
5.08k
    ++_i;
275
5.08k
    return *this;
276
5.08k
}
277
278
inline DeepFrameBuffer::ConstIterator
279
DeepFrameBuffer::ConstIterator::operator++ (int)
280
0
{
281
0
    ConstIterator tmp = *this;
282
0
    ++_i;
283
0
    return tmp;
284
0
}
285
286
inline const char*
287
DeepFrameBuffer::ConstIterator::name () const
288
5.08k
{
289
5.08k
    return *_i->first;
290
5.08k
}
291
292
inline const DeepSlice&
293
DeepFrameBuffer::ConstIterator::slice () const
294
7.26k
{
295
7.26k
    return _i->second;
296
7.26k
}
297
298
inline bool
299
operator== (
300
    const DeepFrameBuffer::ConstIterator& x,
301
    const DeepFrameBuffer::ConstIterator& y)
302
6.10k
{
303
6.10k
    return x._i == y._i;
304
6.10k
}
305
306
inline bool
307
operator!= (
308
    const DeepFrameBuffer::ConstIterator& x,
309
    const DeepFrameBuffer::ConstIterator& y)
310
6.10k
{
311
6.10k
    return !(x == y);
312
6.10k
}
313
314
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
315
316
#endif /* IMFDEEPFRAMEBUFFER_H_ */