/src/FreeImage/Source/OpenEXR/IlmImf/ImfOutputFile.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 241 lines · 34 code · 53 blank · 154 comment · 0 complexity · 718629cebaec7b04057c6de1e9921e60 MD5 · raw file

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