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/ImfIO.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
#ifndef INCLUDED_IMF_IO_H
37
#define INCLUDED_IMF_IO_H
38
39
//-----------------------------------------------------------------------------
40
//
41
//  Low-level file input and output for OpenEXR.
42
//
43
//-----------------------------------------------------------------------------
44
45
#include "ImfInt64.h"
46
#include "ImfNamespace.h"
47
#include "ImfExport.h"
48
49
#include <string>
50
51
52
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
53
54
//-----------------------------------------------------------
55
// class IStream -- an abstract base class for input streams.
56
//-----------------------------------------------------------
57
58
class IStream
59
{
60
  public:
61
62
    //-----------
63
    // Destructor
64
    //-----------
65
66
    IMF_EXPORT
67
    virtual ~IStream ();
68
    
69
    
70
    //-------------------------------------------------
71
    // Does this input stream support memory-mapped IO?
72
    //
73
    // Memory-mapped streams can avoid an extra copy;
74
    // memory-mapped read operations return a pointer
75
    // to an internal buffer instead of copying data
76
    // into a buffer supplied by the caller.
77
    //-------------------------------------------------
78
79
    IMF_EXPORT
80
    virtual bool        isMemoryMapped () const;
81
82
83
    //------------------------------------------------------
84
    // Read from the stream:
85
    //
86
    // read(c,n) reads n bytes from the stream, and stores
87
    // them in array c.  If the stream contains less than n
88
    // bytes, or if an I/O error occurs, read(c,n) throws
89
    // an exception.  If read(c,n) reads the last byte from
90
    // the file it returns false, otherwise it returns true.
91
    //------------------------------------------------------
92
93
    virtual bool  read (char c[/*n*/], int n) = 0;
94
    
95
    
96
    //---------------------------------------------------
97
    // Read from a memory-mapped stream:
98
    //
99
    // readMemoryMapped(n) reads n bytes from the stream
100
    // and returns a pointer to the first byte.  The
101
    // returned pointer remains valid until the stream
102
    // is closed.  If there are less than n byte left to
103
    // read in the stream or if the stream is not memory-
104
    // mapped, readMemoryMapped(n) throws an exception.  
105
    //---------------------------------------------------
106
107
    IMF_EXPORT
108
    virtual char *  readMemoryMapped (int n);
109
110
111
    //--------------------------------------------------------
112
    // Get the current reading position, in bytes from the
113
    // beginning of the file.  If the next call to read() will
114
    // read the first byte in the file, tellg() returns 0.
115
    //--------------------------------------------------------
116
117
    virtual Int64 tellg () = 0;
118
119
120
    //-------------------------------------------
121
    // Set the current reading position.
122
    // After calling seekg(i), tellg() returns i.
123
    //-------------------------------------------
124
125
    virtual void  seekg (Int64 pos) = 0;
126
127
128
    //------------------------------------------------------
129
    // Clear error conditions after an operation has failed.
130
    //------------------------------------------------------
131
132
    IMF_EXPORT
133
    virtual void  clear ();
134
135
136
    //------------------------------------------------------
137
    // Get the name of the file associated with this stream.
138
    //------------------------------------------------------
139
140
    IMF_EXPORT
141
    const char *  fileName () const;
142
143
  protected:
144
145
    IMF_EXPORT
146
    IStream (const char fileName[]);
147
148
  private:
149
150
    IStream (const IStream &);      // not implemented
151
    IStream & operator = (const IStream &); // not implemented
152
153
    std::string   _fileName;
154
};
155
156
157
//-----------------------------------------------------------
158
// class OStream -- an abstract base class for output streams
159
//-----------------------------------------------------------
160
161
class OStream
162
{
163
  public:
164
165
    //-----------
166
    // Destructor
167
    //-----------
168
169
    IMF_EXPORT
170
    virtual ~OStream ();
171
  
172
173
    //----------------------------------------------------------
174
    // Write to the stream:
175
    //
176
    // write(c,n) takes n bytes from array c, and stores them
177
    // in the stream.  If an I/O error occurs, write(c,n) throws
178
    // an exception.
179
    //----------------------------------------------------------
180
181
    virtual void  write (const char c[/*n*/], int n) = 0;
182
183
184
    //---------------------------------------------------------
185
    // Get the current writing position, in bytes from the
186
    // beginning of the file.  If the next call to write() will
187
    // start writing at the beginning of the file, tellp()
188
    // returns 0.
189
    //---------------------------------------------------------
190
191
    virtual Int64 tellp () = 0;
192
193
194
    //-------------------------------------------
195
    // Set the current writing position.
196
    // After calling seekp(i), tellp() returns i.
197
    //-------------------------------------------
198
199
    virtual void  seekp (Int64 pos) = 0;
200
201
202
    //------------------------------------------------------
203
    // Get the name of the file associated with this stream.
204
    //------------------------------------------------------
205
206
    IMF_EXPORT
207
    const char *  fileName () const;
208
209
  protected:
210
211
    IMF_EXPORT
212
    OStream (const char fileName[]);
213
214
  private:
215
216
    OStream (const OStream &);      // not implemented
217
    OStream & operator = (const OStream &); // not implemented
218
219
    std::string   _fileName;
220
};
221
222
223
//-----------------------
224
// Helper classes for Xdr
225
//-----------------------
226
227
struct StreamIO
228
{
229
    static void
230
    writeChars (OStream &os, const char c[/*n*/], int n)
231
0
    {
232
0
        os.write (c, n);
233
0
    }
234
235
    static bool
236
    readChars (IStream &is, char c[/*n*/], int n)
237
0
    {
238
0
        return is.read (c, n);
239
0
    }
240
};
241
242
243
struct CharPtrIO
244
{
245
    static void
246
    writeChars (char *&op, const char c[/*n*/], int n)
247
0
    {
248
0
        while (n--)
249
0
            *op++ = *c++;
250
0
    }
251
252
    static bool
253
    readChars (const char *&ip, char c[/*n*/], int n)
254
0
    {
255
0
        while (n--)
256
0
            *c++ = *ip++;
257
258
0
        return true;
259
0
    }
260
};
261
262
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
263
264
#endif