Coverage Report

Created: 2026-09-14 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openexr/src/lib/OpenEXR/ImfFrameBuffer.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 Slice
9
//      class FrameBuffer
10
//
11
//-----------------------------------------------------------------------------
12
13
#include "Iex.h"
14
#include <ImfFrameBuffer.h>
15
16
using namespace std;
17
18
#include "ImfNamespace.h"
19
20
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
21
22
Slice::Slice (
23
    PixelType t,
24
    char*     b,
25
    size_t    xst,
26
    size_t    yst,
27
    int       xsm,
28
    int       ysm,
29
    double    fv,
30
    bool      xtc,
31
    bool      ytc)
32
39.8k
    : type (t)
33
39.8k
    , base (b)
34
39.8k
    , xStride (xst)
35
39.8k
    , yStride (yst)
36
39.8k
    , xSampling (xsm)
37
39.8k
    , ySampling (ysm)
38
39.8k
    , fillValue (fv)
39
39.8k
    , xTileCoords (xtc)
40
39.8k
    , yTileCoords (ytc)
41
39.8k
{
42
    // empty
43
39.8k
}
44
45
Slice
46
Slice::Make (
47
    PixelType                   type,
48
    const void*                 ptr,
49
    const IMATH_NAMESPACE::V2i& origin,
50
    int64_t                     w,
51
    int64_t                     h,
52
    size_t                      xStride,
53
    size_t                      yStride,
54
    int                         xSampling,
55
    int                         ySampling,
56
    double                      fillValue,
57
    bool                        xTileCoords,
58
    bool                        yTileCoords)
59
0
{
60
0
    intptr_t base = reinterpret_cast<intptr_t> (const_cast<void*> (ptr));
61
0
    if (xStride == 0)
62
0
    {
63
0
        switch (type)
64
0
        {
65
0
            case UINT: xStride = sizeof (uint32_t); break;
66
0
            case HALF: xStride = sizeof (uint16_t); break;
67
0
            case FLOAT: xStride = sizeof (float); break;
68
0
            case NUM_PIXELTYPES:
69
0
                THROW (IEX_NAMESPACE::ArgExc, "Invalid pixel type.");
70
0
        }
71
0
    }
72
0
    if (yStride == 0) yStride = static_cast<size_t> (w / xSampling) * xStride;
73
74
    // data window is an int, so force promote to higher type to avoid
75
    // overflow for off y (degenerate size checks should be in
76
    // ImfHeader::sanityCheck, but offset can be large-ish)
77
0
    int64_t offx =
78
0
        (static_cast<int64_t> (origin.x) / static_cast<int64_t> (xSampling));
79
0
    offx *= static_cast<int64_t> (xStride);
80
81
0
    int64_t offy =
82
0
        (static_cast<int64_t> (origin.y) / static_cast<int64_t> (ySampling));
83
0
    offy *= static_cast<int64_t> (yStride);
84
85
0
    return Slice (
86
0
        type,
87
0
        reinterpret_cast<char*> (base - offx - offy),
88
0
        xStride,
89
0
        yStride,
90
0
        xSampling,
91
0
        ySampling,
92
0
        fillValue,
93
0
        xTileCoords,
94
0
        yTileCoords);
95
0
}
96
97
Slice
98
Slice::Make (
99
    PixelType                     type,
100
    const void*                   ptr,
101
    const IMATH_NAMESPACE::Box2i& dataWindow,
102
    size_t                        xStride,
103
    size_t                        yStride,
104
    int                           xSampling,
105
    int                           ySampling,
106
    double                        fillValue,
107
    bool                          xTileCoords,
108
    bool                          yTileCoords)
109
0
{
110
0
    return Make (
111
0
        type,
112
0
        ptr,
113
0
        dataWindow.min,
114
0
        static_cast<int64_t> (dataWindow.max.x) -
115
0
            static_cast<int64_t> (dataWindow.min.x) + 1,
116
0
        static_cast<int64_t> (dataWindow.max.y) -
117
0
            static_cast<int64_t> (dataWindow.min.y) + 1,
118
0
        xStride,
119
0
        yStride,
120
0
        xSampling,
121
0
        ySampling,
122
0
        fillValue,
123
0
        xTileCoords,
124
0
        yTileCoords);
125
0
}
126
127
void
128
FrameBuffer::insert (const char name[], const Slice& slice)
129
14.5k
{
130
14.5k
    if (name[0] == 0)
131
4
    {
132
4
        THROW (
133
4
            IEX_NAMESPACE::ArgExc,
134
4
            "Frame buffer slice name cannot be an empty string.");
135
4
    }
136
137
14.5k
    _map[name] = slice;
138
14.5k
}
139
140
void
141
FrameBuffer::insert (const string& name, const Slice& slice)
142
13.6k
{
143
13.6k
    insert (name.c_str (), slice);
144
13.6k
}
145
146
Slice&
147
FrameBuffer::operator[] (const char name[])
148
0
{
149
0
    SliceMap::iterator i = _map.find (name);
150
151
0
    if (i == _map.end ())
152
0
    {
153
0
        THROW (
154
0
            IEX_NAMESPACE::ArgExc,
155
0
            "Cannot find frame buffer slice \"" << name << "\".");
156
0
    }
157
158
0
    return i->second;
159
0
}
160
161
const Slice&
162
FrameBuffer::operator[] (const char name[]) const
163
0
{
164
0
    SliceMap::const_iterator i = _map.find (name);
165
166
0
    if (i == _map.end ())
167
0
    {
168
0
        THROW (
169
0
            IEX_NAMESPACE::ArgExc,
170
0
            "Cannot find frame buffer slice \"" << name << "\".");
171
0
    }
172
173
0
    return i->second;
174
0
}
175
176
Slice&
177
FrameBuffer::operator[] (const string& name)
178
0
{
179
0
    return this->operator[] (name.c_str ());
180
0
}
181
182
const Slice&
183
FrameBuffer::operator[] (const string& name) const
184
0
{
185
0
    return this->operator[] (name.c_str ());
186
0
}
187
188
Slice*
189
FrameBuffer::findSlice (const char name[])
190
0
{
191
0
    SliceMap::iterator i = _map.find (name);
192
0
    return (i == _map.end ()) ? 0 : &i->second;
193
0
}
194
195
const Slice*
196
FrameBuffer::findSlice (const char name[]) const
197
25.2k
{
198
25.2k
    SliceMap::const_iterator i = _map.find (name);
199
25.2k
    return (i == _map.end ()) ? 0 : &i->second;
200
25.2k
}
201
202
Slice*
203
FrameBuffer::findSlice (const string& name)
204
0
{
205
0
    return findSlice (name.c_str ());
206
0
}
207
208
const Slice*
209
FrameBuffer::findSlice (const string& name) const
210
1.24k
{
211
1.24k
    return findSlice (name.c_str ());
212
1.24k
}
213
214
FrameBuffer::Iterator
215
FrameBuffer::begin ()
216
377k
{
217
377k
    return _map.begin ();
218
377k
}
219
220
FrameBuffer::ConstIterator
221
FrameBuffer::begin () const
222
309k
{
223
309k
    return _map.begin ();
224
309k
}
225
226
FrameBuffer::Iterator
227
FrameBuffer::end ()
228
1.26M
{
229
1.26M
    return _map.end ();
230
1.26M
}
231
232
FrameBuffer::ConstIterator
233
FrameBuffer::end () const
234
331k
{
235
331k
    return _map.end ();
236
331k
}
237
238
FrameBuffer::Iterator
239
FrameBuffer::find (const char name[])
240
305k
{
241
305k
    return _map.find (name);
242
305k
}
243
244
FrameBuffer::ConstIterator
245
FrameBuffer::find (const char name[]) const
246
0
{
247
0
    return _map.find (name);
248
0
}
249
250
FrameBuffer::Iterator
251
FrameBuffer::find (const string& name)
252
0
{
253
0
    return find (name.c_str ());
254
0
}
255
256
FrameBuffer::ConstIterator
257
FrameBuffer::find (const string& name) const
258
0
{
259
0
    return find (name.c_str ());
260
0
}
261
262
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT