HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfDeepScanLineOutputFile.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 #ifndef INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
7 #define INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // class DeepScanLineOutputFile
12 //
13 //-----------------------------------------------------------------------------
14 
15 #include "ImfExport.h"
16 #include "ImfForward.h"
17 #include "ImfFrameBuffer.h"
18 #include "ImfGenericOutputFile.h"
19 #include "ImfHeader.h"
20 #include "ImfNamespace.h"
21 #include "ImfThreading.h"
22 
24 
25 struct PreviewRgba;
26 
28 {
29 public:
30  //-----------------------------------------------------------
31  // Constructor -- opens the file and writes the file header.
32  // The file header is also copied into the DeepScanLineOutputFile
33  // object, and can later be accessed via the header() method.
34  // Destroying this DeepScanLineOutputFile object automatically closes
35  // the file.
36  //
37  // numThreads determines the number of threads that will be
38  // used to write the file (see ImfThreading.h).
39  //-----------------------------------------------------------
40 
43  const char fileName[],
44  const Header& header,
45  int numThreads = globalThreadCount ());
46 
47  //------------------------------------------------------------
48  // Constructor -- attaches the new DeepScanLineOutputFile object
49  // to a file that has already been opened, and writes the file header.
50  // The file header is also copied into the DeepScanLineOutputFile
51  // object, and can later be accessed via the header() method.
52  // Destroying this DeepScanLineOutputFile object does not automatically
53  // close the file.
54  //
55  // numThreads determines the number of threads that will be
56  // used to write the file (see ImfThreading.h).
57  //------------------------------------------------------------
58 
62  const Header& header,
63  int numThreads = globalThreadCount ());
64 
65  //-------------------------------------------------
66  // Destructor
67  //
68  // Destroying the DeepScanLineOutputFile object
69  // before writing all scan lines within the data
70  // window results in an incomplete file.
71  //-------------------------------------------------
72 
74  virtual ~DeepScanLineOutputFile ();
75 
76  //------------------------
77  // Access to the file name
78  //------------------------
79 
81  const char* fileName () const;
82 
83  //--------------------------
84  // Access to the file header
85  //--------------------------
86 
88  const Header& header () const;
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
103 
104  //-----------------------------------
105  // Access to the current frame buffer
106  //-----------------------------------
107 
108  IMF_EXPORT
109  const DeepFrameBuffer& frameBuffer () const;
110 
111  //-------------------------------------------------------------------
112  // Write pixel data:
113  //
114  // writePixels(n) retrieves the next n scan lines worth of data from
115  // the current frame buffer, starting with the scan line indicated by
116  // currentScanLine(), and stores the data in the output file, and
117  // progressing in the direction indicated by header.lineOrder().
118  //
119  // To produce a complete and correct file, exactly m scan lines must
120  // be written, where m is equal to
121  // header().dataWindow().max.y - header().dataWindow().min.y + 1.
122  //-------------------------------------------------------------------
123 
124  IMF_EXPORT
125  void writePixels (int numScanLines = 1);
126 
127  //------------------------------------------------------------------
128  // Access to the current scan line:
129  //
130  // currentScanLine() returns the y coordinate of the first scan line
131  // that will be read from the current frame buffer during the next
132  // call to writePixels().
133  //
134  // If header.lineOrder() == INCREASING_Y:
135  //
136  // The current scan line before the first call to writePixels()
137  // is header().dataWindow().min.y. After writing each scan line,
138  // the current scan line is incremented by 1.
139  //
140  // If header.lineOrder() == DECREASING_Y:
141  //
142  // The current scan line before the first call to writePixels()
143  // is header().dataWindow().max.y. After writing each scan line,
144  // the current scan line is decremented by 1.
145  //
146  //------------------------------------------------------------------
147 
148  IMF_EXPORT
149  int currentScanLine () const;
150 
151  //--------------------------------------------------------------
152  // Shortcut to copy all pixels from an InputFile into this file,
153  // without uncompressing and then recompressing the pixel data.
154  // This file's header must be compatible with the InputFile's
155  // header: The two header's "dataWindow", "compression",
156  // "lineOrder" and "channels" attributes must be the same.
157  //--------------------------------------------------------------
158 
159  IMF_EXPORT
161 
162  // --------------------------------------------------------------
163  // Shortcut to copy pixels from a given part of a multipart file
164  // --------------------------------------------------------------
165  IMF_EXPORT
167 
168  //--------------------------------------------------------------
169  // Updating the preview image:
170  //
171  // updatePreviewImage() supplies a new set of pixels for the
172  // preview image attribute in the file's header. If the header
173  // does not contain a preview image, updatePreviewImage() throws
174  // an IEX_NAMESPACE::LogicExc.
175  //
176  // Note: updatePreviewImage() is necessary because images are
177  // often stored in a file incrementally, a few scan lines at a
178  // time, while the image is being generated. Since the preview
179  // image is an attribute in the file's header, it gets stored in
180  // the file as soon as the file is opened, but we may not know
181  // what the preview image should look like until we have written
182  // the last scan line of the main image.
183  //
184  //--------------------------------------------------------------
185 
186  IMF_EXPORT
187  void updatePreviewImage (const PreviewRgba newPixels[]);
188 
189  struct Data;
190 
191 private:
192  //------------------------------------------------------------
193  // Constructor -- attaches the OutputStreamMutex to the
194  // given one from MultiPartOutputFile. Set the previewPosition
195  // and lineOffsetsPosition which have been acquired from
196  // the constructor of MultiPartOutputFile as well.
197  //------------------------------------------------------------
198  DeepScanLineOutputFile (const OutputPartData* part);
199 
200  DeepScanLineOutputFile (const DeepScanLineOutputFile&) = delete;
201  DeepScanLineOutputFile& operator= (const DeepScanLineOutputFile&) = delete;
202  DeepScanLineOutputFile (DeepScanLineOutputFile&&) = delete;
203  DeepScanLineOutputFile& operator= (DeepScanLineOutputFile&&) = delete;
204 
205  void initialize (const Header& header);
206  void initializeLineBuffer ();
207 
208  Data* _data;
209 
210  friend class MultiPartOutputFile;
211 };
212 
214 
215 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
IMF_EXPORT void setFrameBuffer(const DeepFrameBuffer &frameBuffer)
IMF_EXPORT const Header & header() const
IMF_EXPORT DeepScanLineOutputFile(const char fileName[], const Header &header, int numThreads=globalThreadCount())
IMF_EXPORT const char * fileName() const
#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:86
IMF_EXPORT void copyPixels(DeepScanLineInputFile &in)
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
LeafData & operator=(const LeafData &)=delete
IMF_EXPORT void writePixels(int numScanLines=1)
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
virtual IMF_EXPORT ~DeepScanLineOutputFile()
IMF_EXPORT void updatePreviewImage(const PreviewRgba newPixels[])
IMF_EXPORT const DeepFrameBuffer & frameBuffer() const
IMF_EXPORT int currentScanLine() const