Coverage Report

Created: 2023-12-08 06:53

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