[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 | |
---|
| 37 | #ifndef INCLUDED_IMF_OUTPUT_FILE_H |
---|
| 38 | #define INCLUDED_IMF_OUTPUT_FILE_H |
---|
| 39 | |
---|
| 40 | //----------------------------------------------------------------------------- |
---|
| 41 | // |
---|
| 42 | // class OutputFile |
---|
| 43 | // |
---|
| 44 | //----------------------------------------------------------------------------- |
---|
| 45 | |
---|
| 46 | #include <ImfHeader.h> |
---|
| 47 | #include <ImfFrameBuffer.h> |
---|
| 48 | |
---|
| 49 | namespace Imf { |
---|
| 50 | |
---|
| 51 | class InputFile; |
---|
| 52 | struct PreviewRgba; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | class OutputFile |
---|
| 56 | { |
---|
| 57 | public: |
---|
| 58 | |
---|
| 59 | //----------------------------------------------------------- |
---|
| 60 | // Constructor -- opens the file and writes the file header. |
---|
| 61 | // The file header is also copied into the OutputFile object, |
---|
| 62 | // and can later be accessed via the header() method. |
---|
| 63 | // Destroying this OutputFile object automatically closes |
---|
| 64 | // the file. |
---|
| 65 | //----------------------------------------------------------- |
---|
| 66 | |
---|
| 67 | OutputFile (const char fileName[], const Header &header); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | //------------------------------------------------------------ |
---|
| 71 | // Constructor -- attaches the new OutputFile object to a file |
---|
| 72 | // that has already been opened, and writes the file header. |
---|
| 73 | // The file header is also copied into the OutputFile object, |
---|
| 74 | // and can later be accessed via the header() method. |
---|
| 75 | // Destroying this OutputFile object does not automatically |
---|
| 76 | // close the file. |
---|
| 77 | //------------------------------------------------------------ |
---|
| 78 | |
---|
| 79 | OutputFile (OStream &os, const Header &header); |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | //------------------------------------------------- |
---|
| 83 | // Destructor |
---|
| 84 | // |
---|
| 85 | // Destroying the OutputFile object before writing |
---|
| 86 | // all scan lines within the data window results in |
---|
| 87 | // an incomplete file. |
---|
| 88 | //------------------------------------------------- |
---|
| 89 | |
---|
| 90 | virtual ~OutputFile (); |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | //------------------------ |
---|
| 94 | // Access to the file name |
---|
| 95 | //------------------------ |
---|
| 96 | |
---|
| 97 | const char * fileName () const; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | //-------------------------- |
---|
| 101 | // Access to the file header |
---|
| 102 | //-------------------------- |
---|
| 103 | |
---|
| 104 | const Header & header () const; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | //------------------------------------------------------- |
---|
| 108 | // Set the current frame buffer -- copies the FrameBuffer |
---|
| 109 | // object into the OutputFile object. |
---|
| 110 | // |
---|
| 111 | // The current frame buffer is the source of the pixel |
---|
| 112 | // data written to the file. The current frame buffer |
---|
| 113 | // must be set at least once before writePixels() is |
---|
| 114 | // called. The current frame buffer can be changed |
---|
| 115 | // after each call to writePixels. |
---|
| 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 | // Write pixel data: |
---|
| 130 | // |
---|
| 131 | // writePixels(n) retrieves the next n scan lines worth of data from |
---|
| 132 | // the current frame buffer, starting with the scan line indicated by |
---|
| 133 | // currentScanLine(), and stores the data in the output file, and |
---|
| 134 | // progressing in the direction indicated by header.lineOrder(). |
---|
| 135 | // |
---|
| 136 | // To produce a complete and correct file, exactly m scan lines must |
---|
| 137 | // be written, where m is equal to |
---|
| 138 | // header().dataWindow().max.y - header().dataWindow().min.y + 1. |
---|
| 139 | //------------------------------------------------------------------- |
---|
| 140 | |
---|
| 141 | void writePixels (int numScanLines = 1); |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | //------------------------------------------------------------------ |
---|
| 145 | // Access to the current scan line: |
---|
| 146 | // |
---|
| 147 | // currentScanLine() returns the y coordinate of the first scan line |
---|
| 148 | // that will be read from the current frame buffer during the next |
---|
| 149 | // call to writePixels(). |
---|
| 150 | // |
---|
| 151 | // If header.lineOrder() == INCREASING_Y: |
---|
| 152 | // |
---|
| 153 | // The current scan line before the first call to writePixels() |
---|
| 154 | // is header().dataWindow().min.y. After writing each scan line, |
---|
| 155 | // the current scan line is incremented by 1. |
---|
| 156 | // |
---|
| 157 | // If header.lineOrder() == DECREASING_Y: |
---|
| 158 | // |
---|
| 159 | // The current scan line before the first call to writePixels() |
---|
| 160 | // is header().dataWindow().max.y. After writing each scan line, |
---|
| 161 | // the current scan line is decremented by 1. |
---|
| 162 | // |
---|
| 163 | //------------------------------------------------------------------ |
---|
| 164 | |
---|
| 165 | int currentScanLine () const; |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | //-------------------------------------------------------------- |
---|
| 169 | // Shortcut to copy all pixels from an InputFile into this file, |
---|
| 170 | // without uncompressing and then recompressing the pixel data. |
---|
| 171 | // This file's header must be compatible with the InputFile's |
---|
| 172 | // header: The two header's "dataWindow", "compression", |
---|
| 173 | // "lineOrder" and "channels" attributes must be the same. |
---|
| 174 | //-------------------------------------------------------------- |
---|
| 175 | |
---|
| 176 | void copyPixels (InputFile &in); |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | //-------------------------------------------------------------- |
---|
| 180 | // Updating the preview image: |
---|
| 181 | // |
---|
| 182 | // updatePreviewImage() supplies a new set of pixels for the |
---|
| 183 | // preview image attribute in the file's header. If the header |
---|
| 184 | // does not contain a preview image, updatePreviewImage() throws |
---|
| 185 | // an Iex::LogicExc. |
---|
| 186 | // |
---|
| 187 | // Note: updatePreviewImage() is necessary because images are |
---|
| 188 | // often stored in a file incrementally, a few scan lines at a |
---|
| 189 | // time, while the image is being generated. Since the preview |
---|
| 190 | // image is an attribute in the file's header, it gets stored in |
---|
| 191 | // the file as soon as the file is opened, but we may not know |
---|
| 192 | // what the preview image should look like until we have written |
---|
| 193 | // the last scan line of the main image. |
---|
| 194 | // |
---|
| 195 | //-------------------------------------------------------------- |
---|
| 196 | |
---|
| 197 | void updatePreviewImage (const PreviewRgba newPixels[]); |
---|
| 198 | |
---|
| 199 | struct Data; |
---|
| 200 | |
---|
| 201 | private: |
---|
| 202 | |
---|
| 203 | OutputFile (const OutputFile &); // not implemented |
---|
| 204 | OutputFile & operator = (const OutputFile &); // not implemented |
---|
| 205 | |
---|
| 206 | void initialize (const Header &header); |
---|
| 207 | |
---|
| 208 | Data * _data; |
---|
| 209 | }; |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | } // namespace Imf |
---|
| 213 | |
---|
| 214 | #endif |
---|