ImfDeepScanLineOutputFile.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2011, 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_DEEP_SCAN_LINE_OUTPUT_FILE_H
  35. #define INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // class DeepScanLineOutputFile
  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. struct PreviewRgba;
  50. class DeepScanLineOutputFile : public GenericOutputFile
  51. {
  52. public:
  53. //-----------------------------------------------------------
  54. // Constructor -- opens the file and writes the file header.
  55. // The file header is also copied into the DeepScanLineOutputFile
  56. // object, and can later be accessed via the header() method.
  57. // Destroying this DeepScanLineOutputFile object automatically closes
  58. // the file.
  59. //
  60. // numThreads determines the number of threads that will be
  61. // used to write the file (see ImfThreading.h).
  62. //-----------------------------------------------------------
  63. IMF_EXPORT
  64. DeepScanLineOutputFile (const char fileName[], const Header &header,
  65. int numThreads = globalThreadCount());
  66. //------------------------------------------------------------
  67. // Constructor -- attaches the new DeepScanLineOutputFile object
  68. // to a file that has already been opened, and writes the file header.
  69. // The file header is also copied into the DeepScanLineOutputFile
  70. // object, and can later be accessed via the header() method.
  71. // Destroying this DeepScanLineOutputFile object does not automatically
  72. // close the file.
  73. //
  74. // numThreads determines the number of threads that will be
  75. // used to write the file (see ImfThreading.h).
  76. //------------------------------------------------------------
  77. IMF_EXPORT
  78. DeepScanLineOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const Header &header,
  79. int numThreads = globalThreadCount());
  80. //-------------------------------------------------
  81. // Destructor
  82. //
  83. // Destroying the DeepScanLineOutputFile object
  84. // before writing all scan lines within the data
  85. // window results in an incomplete file.
  86. //-------------------------------------------------
  87. IMF_EXPORT
  88. virtual ~DeepScanLineOutputFile ();
  89. //------------------------
  90. // Access to the file name
  91. //------------------------
  92. IMF_EXPORT
  93. const char * fileName () const;
  94. //--------------------------
  95. // Access to the file header
  96. //--------------------------
  97. IMF_EXPORT
  98. const Header & header () const;
  99. //-------------------------------------------------------
  100. // Set the current frame buffer -- copies the FrameBuffer
  101. // object into the OutputFile object.
  102. //
  103. // The current frame buffer is the source of the pixel
  104. // data written to the file. The current frame buffer
  105. // must be set at least once before writePixels() is
  106. // called. The current frame buffer can be changed
  107. // after each call to writePixels.
  108. //-------------------------------------------------------
  109. IMF_EXPORT
  110. void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
  111. //-----------------------------------
  112. // Access to the current frame buffer
  113. //-----------------------------------
  114. IMF_EXPORT
  115. const DeepFrameBuffer & frameBuffer () const;
  116. //-------------------------------------------------------------------
  117. // Write pixel data:
  118. //
  119. // writePixels(n) retrieves the next n scan lines worth of data from
  120. // the current frame buffer, starting with the scan line indicated by
  121. // currentScanLine(), and stores the data in the output file, and
  122. // progressing in the direction indicated by header.lineOrder().
  123. //
  124. // To produce a complete and correct file, exactly m scan lines must
  125. // be written, where m is equal to
  126. // header().dataWindow().max.y - header().dataWindow().min.y + 1.
  127. //-------------------------------------------------------------------
  128. IMF_EXPORT
  129. void writePixels (int numScanLines = 1);
  130. //------------------------------------------------------------------
  131. // Access to the current scan line:
  132. //
  133. // currentScanLine() returns the y coordinate of the first scan line
  134. // that will be read from the current frame buffer during the next
  135. // call to writePixels().
  136. //
  137. // If header.lineOrder() == INCREASING_Y:
  138. //
  139. // The current scan line before the first call to writePixels()
  140. // is header().dataWindow().min.y. After writing each scan line,
  141. // the current scan line is incremented by 1.
  142. //
  143. // If header.lineOrder() == DECREASING_Y:
  144. //
  145. // The current scan line before the first call to writePixels()
  146. // is header().dataWindow().max.y. After writing each scan line,
  147. // the current scan line is decremented by 1.
  148. //
  149. //------------------------------------------------------------------
  150. IMF_EXPORT
  151. int currentScanLine () const;
  152. //--------------------------------------------------------------
  153. // Shortcut to copy all pixels from an InputFile into this file,
  154. // without uncompressing and then recompressing the pixel data.
  155. // This file's header must be compatible with the InputFile's
  156. // header: The two header's "dataWindow", "compression",
  157. // "lineOrder" and "channels" attributes must be the same.
  158. //--------------------------------------------------------------
  159. IMF_EXPORT
  160. void copyPixels (DeepScanLineInputFile &in);
  161. // --------------------------------------------------------------
  162. // Shortcut to copy pixels from a given part of a multipart file
  163. // --------------------------------------------------------------
  164. IMF_EXPORT
  165. void copyPixels (DeepScanLineInputPart &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. struct Data;
  186. private:
  187. //------------------------------------------------------------
  188. // Constructor -- attaches the OutputStreamMutex to the
  189. // given one from MultiPartOutputFile. Set the previewPosition
  190. // and lineOffsetsPosition which have been acquired from
  191. // the constructor of MultiPartOutputFile as well.
  192. //------------------------------------------------------------
  193. DeepScanLineOutputFile (const OutputPartData* part);
  194. DeepScanLineOutputFile (const DeepScanLineOutputFile &); // not implemented
  195. DeepScanLineOutputFile & operator = (const DeepScanLineOutputFile &); // not implemented
  196. void initialize (const Header &header);
  197. void initializeLineBuffer();
  198. Data * _data;
  199. friend class MultiPartOutputFile;
  200. };
  201. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  202. #endif