HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfOutputFile.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 
7 #ifndef INCLUDED_IMF_OUTPUT_FILE_H
8 #define INCLUDED_IMF_OUTPUT_FILE_H
9 
10 //-----------------------------------------------------------------------------
11 //
12 // class OutputFile
13 //
14 //-----------------------------------------------------------------------------
15 
16 #include "ImfForward.h"
17 
18 #include "ImfGenericOutputFile.h"
19 #include "ImfThreading.h"
20 
21 
23 
24 
26 {
27  public:
28 
29  //-----------------------------------------------------------
30  // Constructor -- opens the file and writes the file header.
31  // The file header is also copied into the OutputFile object,
32  // and can later be accessed via the header() method.
33  // Destroying this OutputFile object automatically closes
34  // the file.
35  //
36  // numThreads determines the number of threads that will be
37  // used to write the file (see ImfThreading.h).
38  //-----------------------------------------------------------
39 
41  OutputFile (const char fileName[], const Header &header,
42  int numThreads = globalThreadCount());
43 
44 
45  //------------------------------------------------------------
46  // Constructor -- attaches the new OutputFile object to a file
47  // that has already been opened, and writes the file header.
48  // The file header is also copied into the OutputFile object,
49  // and can later be accessed via the header() method.
50  // Destroying this OutputFile object does not automatically
51  // close the file.
52  //
53  // numThreads determines the number of threads that will be
54  // used to write the file (see ImfThreading.h).
55  //------------------------------------------------------------
56 
59  int numThreads = globalThreadCount());
60 
61 
62  //-------------------------------------------------
63  // Destructor
64  //
65  // Destroying the OutputFile object before writing
66  // all scan lines within the data window results in
67  // an incomplete file.
68  //-------------------------------------------------
69 
71  virtual ~OutputFile ();
72 
73 
74  //------------------------
75  // Access to the file name
76  //------------------------
77 
79  const char * fileName () const;
80 
81 
82  //--------------------------
83  // Access to the file header
84  //--------------------------
85 
87  const Header & header () const;
88 
89 
90  //-------------------------------------------------------
91  // Set the current frame buffer -- copies the FrameBuffer
92  // object into the OutputFile object.
93  //
94  // The current frame buffer is the source of the pixel
95  // data written to the file. The current frame buffer
96  // must be set at least once before writePixels() is
97  // called. The current frame buffer can be changed
98  // after each call to writePixels.
99  //-------------------------------------------------------
100 
101  IMF_EXPORT
102  void setFrameBuffer (const FrameBuffer &frameBuffer);
103 
104 
105  //-----------------------------------
106  // Access to the current frame buffer
107  //-----------------------------------
108 
109  IMF_EXPORT
110  const FrameBuffer & frameBuffer () const;
111 
112 
113  //-------------------------------------------------------------------
114  // Write pixel data:
115  //
116  // writePixels(n) retrieves the next n scan lines worth of data from
117  // the current frame buffer, starting with the scan line indicated by
118  // currentScanLine(), and stores the data in the output file, and
119  // progressing in the direction indicated by header.lineOrder().
120  //
121  // To produce a complete and correct file, exactly m scan lines must
122  // be written, where m is equal to
123  // header().dataWindow().max.y - header().dataWindow().min.y + 1.
124  //-------------------------------------------------------------------
125 
126  IMF_EXPORT
127  void writePixels (int numScanLines = 1);
128 
129 
130  //------------------------------------------------------------------
131  // Access to the current scan line:
132  //
133  // currentScanLine() returns the y coordinate of the first scan line
134  // that will be read from the current frame buffer during the next
135  // call to writePixels().
136  //
137  // If header.lineOrder() == INCREASING_Y:
138  //
139  // The current scan line before the first call to writePixels()
140  // is header().dataWindow().min.y. After writing each scan line,
141  // the current scan line is incremented by 1.
142  //
143  // If header.lineOrder() == DECREASING_Y:
144  //
145  // The current scan line before the first call to writePixels()
146  // is header().dataWindow().max.y. After writing each scan line,
147  // the current scan line is decremented by 1.
148  //
149  //------------------------------------------------------------------
150 
151  IMF_EXPORT
152  int currentScanLine () const;
153 
154 
155  //--------------------------------------------------------------
156  // Shortcut to copy all pixels from an InputFile into this file,
157  // without uncompressing and then recompressing the pixel data.
158  // This file's header must be compatible with the InputFile's
159  // header: The two header's "dataWindow", "compression",
160  // "lineOrder" and "channels" attributes must be the same.
161  //--------------------------------------------------------------
162 
163  IMF_EXPORT
164  void copyPixels (InputFile &in);
165 
166  //-------------------------------------------------------------
167  // Shortcut to copy all pixels from an InputPart into this file
168  // - equivalent to copyPixel(InputFile &in) but for multipart files
169  //---------------------------------------------------------------
170 
171  IMF_EXPORT
172  void copyPixels (InputPart &in);
173 
174 
175 
176  //--------------------------------------------------------------
177  // Updating the preview image:
178  //
179  // updatePreviewImage() supplies a new set of pixels for the
180  // preview image attribute in the file's header. If the header
181  // does not contain a preview image, updatePreviewImage() throws
182  // an IEX_NAMESPACE::LogicExc.
183  //
184  // Note: updatePreviewImage() is necessary because images are
185  // often stored in a file incrementally, a few scan lines at a
186  // time, while the image is being generated. Since the preview
187  // image is an attribute in the file's header, it gets stored in
188  // the file as soon as the file is opened, but we may not know
189  // what the preview image should look like until we have written
190  // the last scan line of the main image.
191  //
192  //--------------------------------------------------------------
193 
194  IMF_EXPORT
195  void updatePreviewImage (const PreviewRgba newPixels[]);
196 
197 
198  //---------------------------------------------------------
199  // Break a scan line -- for testing and debugging only:
200  //
201  // breakScanLine(y,p,n,c) introduces an error into the
202  // output file by writing n copies of character c, starting
203  // p bytes from the beginning of the pixel data block that
204  // contains scan line y.
205  //
206  // Warning: Calling this function usually results in a
207  // broken image file. The file or parts of it may not
208  // be readable, or the file may contain bad data.
209  //
210  //---------------------------------------------------------
211 
212  IMF_EXPORT
213  void breakScanLine (int y, int offset, int length, char c);
214 
215 
216  struct IMF_HIDDEN Data;
217 
218  private:
219 
220  //------------------------------------------------------------
221  // Constructor -- attaches the OutputStreamMutex to the
222  // given one from MultiPartOutputFile. Set the previewPosition
223  // and lineOffsetsPosition which have been acquired from
224  // the constructor of MultiPartOutputFile as well.
225  //------------------------------------------------------------
226  IMF_HIDDEN OutputFile (const OutputPartData* part);
227 
228  OutputFile (const OutputFile &) = delete;
229  OutputFile & operator = (const OutputFile &) = delete;
230  OutputFile (OutputFile &&) = delete;
231  OutputFile & operator = (OutputFile &&) = delete;
232 
233  void initialize (const Header &header);
234 
235  Data * _data;
236 
237 
238  friend class MultiPartOutputFile;
239 
240 };
241 
242 
244 
245 
246 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GLint y
Definition: glcorearb.h:103
#define IMF_HIDDEN
Definition: ImfExport.h:55
GLintptr offset
Definition: glcorearb.h:665
#define IMF_EXPORT
Definition: ImfExport.h:54
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
class IMF_EXPORT_TYPE OStream
Definition: ImfForward.h:88
class IMF_EXPORT_TYPE OutputFile
Definition: ImfForward.h:34
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57