1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004, 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_SCAN_LINE_INPUT_FILE_H
37 #define INCLUDED_IMF_SCAN_LINE_INPUT_FILE_H
38 
39 //-----------------------------------------------------------------------------
40 //
41 //	class ScanLineInputFile
42 //
43 //-----------------------------------------------------------------------------
44 
45 #include "ImfHeader.h"
46 #include "ImfFrameBuffer.h"
47 #include "ImfThreading.h"
48 #include "ImfInputStreamMutex.h"
49 #include "ImfInputPartData.h"
50 #include "ImfGenericInputFile.h"
51 #include "ImfExport.h"
52 #include "ImfNamespace.h"
53 
54 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
55 
56 
57 class IMF_EXPORT ScanLineInputFile : public GenericInputFile
58 {
59   public:
60 
61     //------------
62     // Constructor
63     //------------
64 
65     ScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
66                        int numThreads = globalThreadCount());
67 
68 
69     //-----------------------------------------
70     // Destructor -- deallocates internal data
71     // structures, but does not close the file.
72     //-----------------------------------------
73 
74     virtual ~ScanLineInputFile ();
75 
76 
77     //------------------------
78     // Access to the file name
79     //------------------------
80 
81     const char *	fileName () const;
82 
83 
84     //--------------------------
85     // Access to the file header
86     //--------------------------
87 
88     const Header &	header () const;
89 
90 
91     //----------------------------------
92     // Access to the file format version
93     //----------------------------------
94 
95     int			version () const;
96 
97 
98     //-----------------------------------------------------------
99     // Set the current frame buffer -- copies the FrameBuffer
100     // object into the InputFile object.
101     //
102     // The current frame buffer is the destination for the pixel
103     // data read from the file.  The current frame buffer must be
104     // set at least once before readPixels() is called.
105     // The current frame buffer can be changed after each call
106     // to readPixels().
107     //-----------------------------------------------------------
108 
109     void		setFrameBuffer (const FrameBuffer &frameBuffer);
110 
111 
112     //-----------------------------------
113     // Access to the current frame buffer
114     //-----------------------------------
115 
116     const FrameBuffer &	frameBuffer () const;
117 
118 
119     //---------------------------------------------------------------
120     // Check if the file is complete:
121     //
122     // isComplete() returns true if all pixels in the data window are
123     // present in the input file, or false if any pixels are missing.
124     // (Another program may still be busy writing the file, or file
125     // writing may have been aborted prematurely.)
126     //---------------------------------------------------------------
127 
128     bool		isComplete () const;
129 
130 
131 
132     //---------------------------------------------------------------
133     // Check if SSE optimisation is enabled
134     //
135     // Call after setFrameBuffer() to query whether optimised file decoding
136     // is available - decode times will be faster if returns true
137     //
138     // Optimisation depends on the framebuffer channels and channel types
139     // as well as the file/part channels and channel types, as well as
140     // whether SSE2 instruction support was detected at compile time
141     //
142     // Calling before setFrameBuffer will throw an exception
143     //
144     //---------------------------------------------------------------
145 
146     bool                isOptimizationEnabled () const;
147 
148 
149 
150 
151     //---------------------------------------------------------------
152     // Read pixel data:
153     //
154     // readPixels(s1,s2) reads all scan lines with y coordinates
155     // in the interval [min (s1, s2), max (s1, s2)] from the file,
156     // and stores them in the current frame buffer.
157     //
158     // Both s1 and s2 must be within the interval
159     // [header().dataWindow().min.y, header.dataWindow().max.y]
160     //
161     // The scan lines can be read from the file in random order, and
162     // individual scan lines may be skipped or read multiple times.
163     // For maximum efficiency, the scan lines should be read in the
164     // order in which they were written to the file.
165     //
166     // readPixels(s) calls readPixels(s,s).
167     //
168     // If threading is enabled, readPixels (s1, s2) tries to perform
169     // decopmression of multiple scanlines in parallel.
170     //
171     //---------------------------------------------------------------
172 
173     void		readPixels (int scanLine1, int scanLine2);
174     void		readPixels (int scanLine);
175 
176 
177     //----------------------------------------------
178     // Read a block of raw pixel data from the file,
179     // without uncompressing it (this function is
180     // used to implement OutputFile::copyPixels()).
181     //----------------------------------------------
182 
183     void		rawPixelData (int firstScanLine,
184 				      const char *&pixelData,
185 				      int &pixelDataSize);
186 
187     struct Data;
188 
189   private:
190 
191     Data *		_data;
192 
193     InputStreamMutex*   _streamData;
194 
195     ScanLineInputFile   (InputPartData* part);
196 
197     void                initialize(const Header& header);
198 
199     friend class MultiPartInputFile;
200     friend class InputFile;
201 };
202 
203 
204 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
205 
206 
207 
208 
209 
210 #endif
211