| 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_INPUT_FILE_H |
| 37 | #define INCLUDED_IMF_INPUT_FILE_H |
| 38 | |
| 39 | //----------------------------------------------------------------------------- |
| 40 | // |
| 41 | // class InputFile -- a scanline-based interface that can be used |
| 42 | // to read both scanline-based and tiled OpenEXR image files. |
| 43 | // |
| 44 | //----------------------------------------------------------------------------- |
| 45 | |
| 46 | #include "ImfHeader.h" |
| 47 | #include "ImfFrameBuffer.h" |
| 48 | #include "ImfTiledOutputFile.h" |
| 49 | #include "ImfThreading.h" |
| 50 | #include "ImfGenericInputFile.h" |
| 51 | #include "ImfNamespace.h" |
| 52 | #include "ImfForward.h" |
| 53 | #include "ImfExport.h" |
| 54 | |
| 55 | #include <fstream> |
| 56 | |
| 57 | |
| 58 | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
| 59 | |
| 60 | |
| 61 | class InputFile : public GenericInputFile |
| 62 | { |
| 63 | public: |
| 64 | |
| 65 | //----------------------------------------------------------- |
| 66 | // A constructor that opens the file with the specified name. |
| 67 | // Destroying the InputFile object will close the file. |
| 68 | // |
| 69 | // numThreads determines the number of threads that will be |
| 70 | // used to read the file (see ImfThreading.h). |
| 71 | //----------------------------------------------------------- |
| 72 | |
| 73 | IMF_EXPORT |
| 74 | InputFile (const char fileName[], int numThreads = globalThreadCount()); |
| 75 | |
| 76 | |
| 77 | //------------------------------------------------------------- |
| 78 | // A constructor that attaches the new InputFile object to a |
| 79 | // file that has already been opened. Destroying the InputFile |
| 80 | // object will not close the file. |
| 81 | // |
| 82 | // numThreads determines the number of threads that will be |
| 83 | // used to read the file (see ImfThreading.h). |
| 84 | //------------------------------------------------------------- |
| 85 | |
| 86 | IMF_EXPORT |
| 87 | InputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount()); |
| 88 | |
| 89 | |
| 90 | //----------- |
| 91 | // Destructor |
| 92 | //----------- |
| 93 | |
| 94 | IMF_EXPORT |
| 95 | virtual ~InputFile (); |
| 96 | |
| 97 | |
| 98 | //------------------------ |
| 99 | // Access to the file name |
| 100 | //------------------------ |
| 101 | |
| 102 | IMF_EXPORT |
| 103 | const char * fileName () const; |
| 104 | |
| 105 | |
| 106 | //-------------------------- |
| 107 | // Access to the file header |
| 108 | //-------------------------- |
| 109 | |
| 110 | IMF_EXPORT |
| 111 | const Header & () const; |
| 112 | |
| 113 | |
| 114 | //---------------------------------- |
| 115 | // Access to the file format version |
| 116 | //---------------------------------- |
| 117 | |
| 118 | IMF_EXPORT |
| 119 | int version () const; |
| 120 | |
| 121 | |
| 122 | //----------------------------------------------------------- |
| 123 | // Set the current frame buffer -- copies the FrameBuffer |
| 124 | // object into the InputFile object. |
| 125 | // |
| 126 | // The current frame buffer is the destination for the pixel |
| 127 | // data read from the file. The current frame buffer must be |
| 128 | // set at least once before readPixels() is called. |
| 129 | // The current frame buffer can be changed after each call |
| 130 | // to readPixels(). |
| 131 | //----------------------------------------------------------- |
| 132 | |
| 133 | IMF_EXPORT |
| 134 | void setFrameBuffer (const FrameBuffer &frameBuffer); |
| 135 | |
| 136 | |
| 137 | //----------------------------------- |
| 138 | // Access to the current frame buffer |
| 139 | //----------------------------------- |
| 140 | |
| 141 | IMF_EXPORT |
| 142 | const FrameBuffer & frameBuffer () const; |
| 143 | |
| 144 | |
| 145 | //--------------------------------------------------------------- |
| 146 | // Check if the file is complete: |
| 147 | // |
| 148 | // isComplete() returns true if all pixels in the data window are |
| 149 | // present in the input file, or false if any pixels are missing. |
| 150 | // (Another program may still be busy writing the file, or file |
| 151 | // writing may have been aborted prematurely.) |
| 152 | //--------------------------------------------------------------- |
| 153 | |
| 154 | IMF_EXPORT |
| 155 | bool isComplete () const; |
| 156 | |
| 157 | |
| 158 | //--------------------------------------------------------------- |
| 159 | // Check if SSE optimization is enabled |
| 160 | // |
| 161 | // Call after setFrameBuffer() to query whether optimized file decoding |
| 162 | // is available - decode times will be faster if returns true |
| 163 | // |
| 164 | // Optimization depends on: |
| 165 | // the file type (only scanline data is supported), |
| 166 | // the framebuffer channels (RGB/RGBA mono or stereo) |
| 167 | // the framebuffer channel types (all channels half-float format only) |
| 168 | // the file channels (RGB/RGBA mono or stereo) |
| 169 | // the file channel types (all channel half-float format only) |
| 170 | // whether SSE2 instruction support was detected at compile time |
| 171 | // |
| 172 | // Calling isOptimizationEnabled before setFrameBuffer will throw an exception |
| 173 | // |
| 174 | //--------------------------------------------------------------- |
| 175 | |
| 176 | IMF_EXPORT |
| 177 | bool isOptimizationEnabled () const; |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | //--------------------------------------------------------------- |
| 183 | // Read pixel data: |
| 184 | // |
| 185 | // readPixels(s1,s2) reads all scan lines with y coordinates |
| 186 | // in the interval [min (s1, s2), max (s1, s2)] from the file, |
| 187 | // and stores them in the current frame buffer. |
| 188 | // |
| 189 | // Both s1 and s2 must be within the interval |
| 190 | // [header().dataWindow().min.y, header().dataWindow().max.y] |
| 191 | // |
| 192 | // The scan lines can be read from the file in random order, and |
| 193 | // individual scan lines may be skipped or read multiple times. |
| 194 | // For maximum efficiency, the scan lines should be read in the |
| 195 | // order in which they were written to the file. |
| 196 | // |
| 197 | // readPixels(s) calls readPixels(s,s). |
| 198 | // |
| 199 | //--------------------------------------------------------------- |
| 200 | |
| 201 | IMF_EXPORT |
| 202 | void readPixels (int scanLine1, int scanLine2); |
| 203 | IMF_EXPORT |
| 204 | void readPixels (int scanLine); |
| 205 | |
| 206 | |
| 207 | //---------------------------------------------- |
| 208 | // Read a block of raw pixel data from the file, |
| 209 | // without uncompressing it (this function is |
| 210 | // used to implement OutputFile::copyPixels()). |
| 211 | //---------------------------------------------- |
| 212 | |
| 213 | IMF_EXPORT |
| 214 | void rawPixelData (int firstScanLine, |
| 215 | const char *&pixelData, |
| 216 | int &pixelDataSize); |
| 217 | |
| 218 | |
| 219 | //---------------------------------------------- |
| 220 | // Read a scanline's worth of raw pixel data |
| 221 | // from the file, without uncompressing it, and |
| 222 | // store in an external buffer, pixelData. |
| 223 | // pixelData should be pre-allocated with space |
| 224 | // for pixelDataSize chars. |
| 225 | // |
| 226 | // This function can be used to separate the |
| 227 | // reading of a raw scan line from the |
| 228 | // decompression of that scan line, for |
| 229 | // example to allow multiple scan lines to be |
| 230 | // decompressed in parallel by an application's |
| 231 | // own threads, where it is not convenient to |
| 232 | // use the threading within the library. |
| 233 | //---------------------------------------------- |
| 234 | |
| 235 | IMF_EXPORT |
| 236 | void rawPixelDataToBuffer (int scanLine, |
| 237 | char *pixelData, |
| 238 | int &pixelDataSize) const; |
| 239 | |
| 240 | |
| 241 | |
| 242 | //-------------------------------------------------- |
| 243 | // Read a tile of raw pixel data from the file, |
| 244 | // without uncompressing it (this function is |
| 245 | // used to implement TiledOutputFile::copyPixels()). |
| 246 | //-------------------------------------------------- |
| 247 | |
| 248 | IMF_EXPORT |
| 249 | void rawTileData (int &dx, int &dy, |
| 250 | int &lx, int &ly, |
| 251 | const char *&pixelData, |
| 252 | int &pixelDataSize); |
| 253 | |
| 254 | struct Data; |
| 255 | |
| 256 | private: |
| 257 | |
| 258 | InputFile (InputPartData* part); |
| 259 | |
| 260 | InputFile (const InputFile &) = delete; |
| 261 | InputFile & operator = (const InputFile &) = delete; |
| 262 | InputFile (InputFile &&) = delete; |
| 263 | InputFile & operator = (InputFile &&) = delete; |
| 264 | |
| 265 | void initialize (); |
| 266 | void multiPartInitialize(InputPartData* part); |
| 267 | void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is); |
| 268 | TiledInputFile * tFile (); |
| 269 | |
| 270 | friend void TiledOutputFile::copyPixels (InputFile &); |
| 271 | |
| 272 | Data * _data; |
| 273 | |
| 274 | |
| 275 | friend class MultiPartInputFile; |
| 276 | }; |
| 277 | |
| 278 | |
| 279 | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
| 280 | |
| 281 | #endif |
| 282 | |