[855] | 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 <string> |
---|
| 50 | #include <fstream> |
---|
| 51 | |
---|
| 52 | namespace Imf { |
---|
| 53 | |
---|
| 54 | class TiledInputFile; |
---|
| 55 | class ScanLineInputFile; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | class InputFile |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | |
---|
| 62 | //----------------------------------------------------------- |
---|
| 63 | // A constructor that opens the file with the specified name. |
---|
| 64 | // Destroying the InputFile object will close the file. |
---|
| 65 | //----------------------------------------------------------- |
---|
| 66 | |
---|
| 67 | InputFile (const char fileName[]); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | //------------------------------------------------------------- |
---|
| 71 | // A constructor that attaches the new InputFile object to a |
---|
| 72 | // file that has already been opened. Destroying the InputFile |
---|
| 73 | // object will not close the file. |
---|
| 74 | //------------------------------------------------------------- |
---|
| 75 | |
---|
| 76 | InputFile (IStream &is); |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | //----------- |
---|
| 80 | // Destructor |
---|
| 81 | //----------- |
---|
| 82 | |
---|
| 83 | virtual ~InputFile (); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | //------------------------ |
---|
| 87 | // Access to the file name |
---|
| 88 | //------------------------ |
---|
| 89 | |
---|
| 90 | const char * fileName () const; |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | //-------------------------- |
---|
| 94 | // Access to the file header |
---|
| 95 | //-------------------------- |
---|
| 96 | |
---|
| 97 | const Header & header () const; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | //---------------------------------- |
---|
| 101 | // Access to the file format version |
---|
| 102 | //---------------------------------- |
---|
| 103 | |
---|
| 104 | int version () const; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | //----------------------------------------------------------- |
---|
| 108 | // Set the current frame buffer -- copies the FrameBuffer |
---|
| 109 | // object into the InputFile object. |
---|
| 110 | // |
---|
| 111 | // The current frame buffer is the destination for the pixel |
---|
| 112 | // data read from the file. The current frame buffer must be |
---|
| 113 | // set at least once before readPixels() is called. |
---|
| 114 | // The current frame buffer can be changed after each call |
---|
| 115 | // to readPixels(). |
---|
| 116 | //----------------------------------------------------------- |
---|
| 117 | |
---|
| 118 | void setFrameBuffer (const FrameBuffer &frameBuffer); |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | //----------------------------------- |
---|
| 122 | // Access to the current frame buffer |
---|
| 123 | //----------------------------------- |
---|
| 124 | |
---|
| 125 | const FrameBuffer & frameBuffer () const; |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | //--------------------------------------------------------------- |
---|
| 129 | // Check if the file is complete: |
---|
| 130 | // |
---|
| 131 | // isComplete() returns true if all pixels in the data window are |
---|
| 132 | // present in the input file, or false if any pixels are missing. |
---|
| 133 | // (Another program may still be busy writing the file, or file |
---|
| 134 | // writing may have been aborted prematurely.) |
---|
| 135 | //--------------------------------------------------------------- |
---|
| 136 | |
---|
| 137 | bool isComplete () const; |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | //--------------------------------------------------------------- |
---|
| 141 | // Read pixel data: |
---|
| 142 | // |
---|
| 143 | // readPixels(s1,s2) reads all scan lines with y coordinates |
---|
| 144 | // in the interval [min (s1, s2), max (s1, s2)] from the file, |
---|
| 145 | // and stores them in the current frame buffer. |
---|
| 146 | // |
---|
| 147 | // Both s1 and s2 must be within the interval |
---|
| 148 | // [header().dataWindow().min.y, header.dataWindow().max.y] |
---|
| 149 | // |
---|
| 150 | // The scan lines can be read from the file in random order, and |
---|
| 151 | // individual scan lines may be skipped or read multiple times. |
---|
| 152 | // For maximum efficiency, the scan lines should be read in the |
---|
| 153 | // order in which they were written to the file. |
---|
| 154 | // |
---|
| 155 | // readPixels(s) calls readPixels(s,s). |
---|
| 156 | // |
---|
| 157 | //--------------------------------------------------------------- |
---|
| 158 | |
---|
| 159 | void readPixels (int scanLine1, int scanLine2); |
---|
| 160 | void readPixels (int scanLine); |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | //---------------------------------------------- |
---|
| 164 | // Read a block of raw pixel data from the file, |
---|
| 165 | // without uncompressing it (this function is |
---|
| 166 | // used to implement OutputFile::copyPixels()). |
---|
| 167 | //---------------------------------------------- |
---|
| 168 | |
---|
| 169 | void rawPixelData (int firstScanLine, |
---|
| 170 | const char *&pixelData, |
---|
| 171 | int &pixelDataSize); |
---|
| 172 | |
---|
| 173 | //-------------------------------------------------- |
---|
| 174 | // Read a tile of raw pixel data from the file, |
---|
| 175 | // without uncompressing it (this function is |
---|
| 176 | // used to implement TiledOutputFile::copyPixels()). |
---|
| 177 | //-------------------------------------------------- |
---|
| 178 | |
---|
| 179 | void rawTileData (int &dx, int &dy, |
---|
| 180 | int &lx, int &ly, |
---|
| 181 | const char *&pixelData, |
---|
| 182 | int &pixelDataSize); |
---|
| 183 | |
---|
| 184 | struct Data; |
---|
| 185 | |
---|
| 186 | private: |
---|
| 187 | |
---|
| 188 | InputFile (const InputFile &); // not implemented |
---|
| 189 | InputFile & operator = (const InputFile &); // not implemented |
---|
| 190 | |
---|
| 191 | void initialize (); |
---|
| 192 | TiledInputFile * tFile (); |
---|
| 193 | |
---|
| 194 | friend void TiledOutputFile::copyPixels (InputFile &); |
---|
| 195 | |
---|
| 196 | Data * _data; |
---|
| 197 | }; |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | } // namespace Imf |
---|
| 201 | |
---|
| 202 | #endif |
---|