HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfDeepScanLineInputFile.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 #ifndef INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
37 #define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
38 
39 //-----------------------------------------------------------------------------
40 //
41 // class DeepScanLineInputFile
42 //
43 //-----------------------------------------------------------------------------
44 
45 #include "ImfThreading.h"
46 #include "ImfGenericInputFile.h"
47 #include "ImfNamespace.h"
48 #include "ImfForward.h"
49 #include "ImfExport.h"
51 
53 
54 
56 {
57  public:
58 
59  //------------
60  // Constructor
61  //------------
62 
64  DeepScanLineInputFile (const char fileName[],
65  int numThreads = globalThreadCount());
66 
68  DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
69  int version, /*version field from file*/
70  int numThreads = globalThreadCount());
71 
72 
73  //-----------------------------------------
74  // Destructor -- deallocates internal data
75  // structures, but does not close the file.
76  //-----------------------------------------
77 
79  virtual ~DeepScanLineInputFile ();
80 
81 
82  //------------------------
83  // Access to the file name
84  //------------------------
85 
87  const char * fileName () const;
88 
89 
90  //--------------------------
91  // Access to the file header
92  //--------------------------
93 
95  const Header & header () const;
96 
97 
98  //----------------------------------
99  // Access to the file format version
100  //----------------------------------
101 
102  IMF_EXPORT
103  int version () const;
104 
105 
106  //-----------------------------------------------------------
107  // Set the current frame buffer -- copies the FrameBuffer
108  // object into the InputFile object.
109  //
110  // The current frame buffer is the destination for the pixel
111  // data read from the file. The current frame buffer must be
112  // set at least once before readPixels() is called.
113  // The current frame buffer can be changed after each call
114  // to readPixels().
115  //-----------------------------------------------------------
116 
117  IMF_EXPORT
119 
120 
121  //-----------------------------------
122  // Access to the current frame buffer
123  //-----------------------------------
124 
125  IMF_EXPORT
126  const DeepFrameBuffer & frameBuffer () const;
127 
128 
129  //---------------------------------------------------------------
130  // Check if the file is complete:
131  //
132  // isComplete() returns true if all pixels in the data window are
133  // present in the input file, or false if any pixels are missing.
134  // (Another program may still be busy writing the file, or file
135  // writing may have been aborted prematurely.)
136  //---------------------------------------------------------------
137 
138  IMF_EXPORT
139  bool isComplete () const;
140 
141 
142  //---------------------------------------------------------------
143  // Read pixel data:
144  //
145  // readPixels(s1,s2) reads all scan lines with y coordinates
146  // in the interval [min (s1, s2), max (s1, s2)] from the file,
147  // and stores them in the current frame buffer.
148  //
149  // Both s1 and s2 must be within the interval
150  // [header().dataWindow().min.y, header.dataWindow().max.y]
151  //
152  // The scan lines can be read from the file in random order, and
153  // individual scan lines may be skipped or read multiple times.
154  // For maximum efficiency, the scan lines should be read in the
155  // order in which they were written to the file.
156  //
157  // readPixels(s) calls readPixels(s,s).
158  //
159  // If threading is enabled, readPixels (s1, s2) tries to perform
160  // decopmression of multiple scanlines in parallel.
161  //
162  //---------------------------------------------------------------
163 
164  IMF_EXPORT
165  void readPixels (int scanLine1, int scanLine2);
166  IMF_EXPORT
167  void readPixels (int scanLine);
168 
169 
170 
171  //---------------------------------------------------------------
172  // Extract pixel data from pre-read block
173  //
174  // readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates
175  // in the interval [min (s1, s2), max (s1, s2)] from the data provided and
176  // stores them in the provided frameBuffer.
177  // the data can be obtained from a call to rawPixelData()
178  //
179  //
180  // Both s1 and s2 must be within the data specified
181  //
182  // you must provide a frameBuffer with a samplecountslice, which must have been read
183  // and the data valid - readPixels uses your sample count buffer to compute
184  // offsets to the data it needs
185  //
186  // This call does not block, and is thread safe for clients with an existing
187  // threading model. The InputFile's frameBuffer is not used in this call.
188  //
189  // This call is only provided for clients which have an existing threading model in place
190  // and unpredictable access patterns to the data.
191  // The fastest way to read an entire image is to enable threading,use setFrameBuffer then
192  // readPixels(header().dataWindow().min.y, header.dataWindow().max.y)
193  //
194  //---------------------------------------------------------------
195 
196  IMF_EXPORT
197  void readPixels (const char * rawPixelData,
198  const DeepFrameBuffer & frameBuffer,
199  int scanLine1,
200  int scanLine2) const;
201 
202  //----------------------------------------------
203  // Read a block of raw pixel data from the file,
204  // without uncompressing it (this function is
205  // used to implement OutputFile::copyPixels()).
206  // note: returns the entire payload of the relevant chunk of data, not including part number
207  // including compressed and uncompressed sizes
208  // on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL)
209  // on exit, pixelDataSize is the number of bytes required to read the chunk
210  //
211  //----------------------------------------------
212 
213  IMF_EXPORT
214  void rawPixelData (int firstScanLine,
215  char * pixelData,
216  Int64 &pixelDataSize);
217 
218 
219  //-------------------------------------------------
220  // firstScanLineInChunk() returns the row number of the first row that's stored in the
221  // same chunk as scanline y. Depending on the compression mode, this may not be the same as y
222  //
223  // lastScanLineInChunk() returns the row number of the last row that's stored in the same
224  // chunk as scanline y. Depending on the compression mode, this may not be the same as y.
225  // The last chunk in the file may be smaller than all the others
226  //
227  //------------------------------------------------
228  IMF_EXPORT
229  int firstScanLineInChunk(int y) const;
230  IMF_EXPORT
231  int lastScanLineInChunk (int y) const;
232 
233  //-----------------------------------------------------------
234  // Read pixel sample counts into a slice in the frame buffer.
235  //
236  // readPixelSampleCounts(s1, s2) reads all the counts of
237  // pixel samples with y coordinates in the interval
238  // [min (s1, s2), max (s1, s2)] from the file, and stores
239  // them in the slice naming "sample count".
240  //
241  // Both s1 and s2 must be within the interval
242  // [header().dataWindow().min.y, header.dataWindow().max.y]
243  //
244  // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s).
245  //
246  //-----------------------------------------------------------
247 
248  IMF_EXPORT
249  void readPixelSampleCounts (int scanline1,
250  int scanline2);
251  IMF_EXPORT
252  void readPixelSampleCounts (int scanline);
253 
254 
255  //----------------------------------------------------------
256  // Read pixel sample counts into the provided frameBuffer
257  // using a block read of data read by rawPixelData
258  // for multi-scanline compression schemes, you must decode the entire block
259  // so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y)
260  //
261  // This call does not block, and is thread safe for clients with an existing
262  // threading model. The InputFile's frameBuffer is not used in this call.
263  //
264  // The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then
265  // readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y)
266  //
267  //----------------------------------------------------------
268  IMF_EXPORT
269  void readPixelSampleCounts (const char * rawdata ,
270  const DeepFrameBuffer & frameBuffer,
271  int scanLine1 ,
272  int scanLine2) const;
273 
274  struct Data;
275 
276  private:
277 
278  Data * _data;
279 
280  DeepScanLineInputFile (InputPartData* part);
281 
282  void initialize(const Header& header);
283  void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is);
284  void multiPartInitialize(InputPartData* part);
285 
286  friend class InputFile;
287  friend class MultiPartInputFile;
288  friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &);
289 };
290 
291 
293 
294 #endif
IMF_EXPORT const Header & header() const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
IMF_EXPORT void readPixels(int scanLine1, int scanLine2)
virtual IMF_EXPORT ~DeepScanLineInputFile()
IMF_EXPORT DeepScanLineInputFile(const char fileName[], int numThreads=globalThreadCount())
IMF_EXPORT void readPixelSampleCounts(int scanline1, int scanline2)
IMF_EXPORT int lastScanLineInChunk(int y) const
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER typedef long long unsigned int Int64
Definition: ImathInt64.h:58
IMF_EXPORT void rawPixelData(int firstScanLine, char *pixelData, Int64 &pixelDataSize)
#define IMF_EXPORT
Definition: ImfExport.h:44
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:294
IMF_EXPORT const DeepFrameBuffer & frameBuffer() const
IMF_EXPORT void copyPixels(DeepScanLineInputFile &in)
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
IMF_EXPORT int firstScanLineInChunk(int y) const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
IMF_EXPORT void setFrameBuffer(const DeepFrameBuffer &frameBuffer)
IMF_EXPORT const char * fileName() const
IMF_EXPORT int version() const
GLint y
Definition: glcorearb.h:102
IMF_EXPORT bool isComplete() const