ImfOutputFile.h 9.8 KB

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