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