ImfDeepScanLineOutputFile.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
  6. #define INCLUDED_IMF_DEEP_SCAN_LINE_OUTPUT_FILE_H
  7. //-----------------------------------------------------------------------------
  8. //
  9. // class DeepScanLineOutputFile
  10. //
  11. //-----------------------------------------------------------------------------
  12. #include "ImfHeader.h"
  13. #include "ImfFrameBuffer.h"
  14. #include "ImfThreading.h"
  15. #include "ImfGenericOutputFile.h"
  16. #include "ImfNamespace.h"
  17. #include "ImfForward.h"
  18. #include "ImfExport.h"
  19. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  20. struct PreviewRgba;
  21. class DeepScanLineOutputFile : public GenericOutputFile
  22. {
  23. public:
  24. //-----------------------------------------------------------
  25. // Constructor -- opens the file and writes the file header.
  26. // The file header is also copied into the DeepScanLineOutputFile
  27. // object, and can later be accessed via the header() method.
  28. // Destroying this DeepScanLineOutputFile object automatically closes
  29. // the file.
  30. //
  31. // numThreads determines the number of threads that will be
  32. // used to write the file (see ImfThreading.h).
  33. //-----------------------------------------------------------
  34. IMF_EXPORT
  35. DeepScanLineOutputFile (const char fileName[], const Header &header,
  36. int numThreads = globalThreadCount());
  37. //------------------------------------------------------------
  38. // Constructor -- attaches the new DeepScanLineOutputFile object
  39. // to a file that has already been opened, and writes the file header.
  40. // The file header is also copied into the DeepScanLineOutputFile
  41. // object, and can later be accessed via the header() method.
  42. // Destroying this DeepScanLineOutputFile object does not automatically
  43. // close the file.
  44. //
  45. // numThreads determines the number of threads that will be
  46. // used to write the file (see ImfThreading.h).
  47. //------------------------------------------------------------
  48. IMF_EXPORT
  49. DeepScanLineOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, const Header &header,
  50. int numThreads = globalThreadCount());
  51. //-------------------------------------------------
  52. // Destructor
  53. //
  54. // Destroying the DeepScanLineOutputFile object
  55. // before writing all scan lines within the data
  56. // window results in an incomplete file.
  57. //-------------------------------------------------
  58. IMF_EXPORT
  59. virtual ~DeepScanLineOutputFile ();
  60. //------------------------
  61. // Access to the file name
  62. //------------------------
  63. IMF_EXPORT
  64. const char * fileName () const;
  65. //--------------------------
  66. // Access to the file header
  67. //--------------------------
  68. IMF_EXPORT
  69. const Header & header () const;
  70. //-------------------------------------------------------
  71. // Set the current frame buffer -- copies the FrameBuffer
  72. // object into the OutputFile object.
  73. //
  74. // The current frame buffer is the source of the pixel
  75. // data written to the file. The current frame buffer
  76. // must be set at least once before writePixels() is
  77. // called. The current frame buffer can be changed
  78. // after each call to writePixels.
  79. //-------------------------------------------------------
  80. IMF_EXPORT
  81. void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
  82. //-----------------------------------
  83. // Access to the current frame buffer
  84. //-----------------------------------
  85. IMF_EXPORT
  86. const DeepFrameBuffer & frameBuffer () const;
  87. //-------------------------------------------------------------------
  88. // Write pixel data:
  89. //
  90. // writePixels(n) retrieves the next n scan lines worth of data from
  91. // the current frame buffer, starting with the scan line indicated by
  92. // currentScanLine(), and stores the data in the output file, and
  93. // progressing in the direction indicated by header.lineOrder().
  94. //
  95. // To produce a complete and correct file, exactly m scan lines must
  96. // be written, where m is equal to
  97. // header().dataWindow().max.y - header().dataWindow().min.y + 1.
  98. //-------------------------------------------------------------------
  99. IMF_EXPORT
  100. void writePixels (int numScanLines = 1);
  101. //------------------------------------------------------------------
  102. // Access to the current scan line:
  103. //
  104. // currentScanLine() returns the y coordinate of the first scan line
  105. // that will be read from the current frame buffer during the next
  106. // call to writePixels().
  107. //
  108. // If header.lineOrder() == INCREASING_Y:
  109. //
  110. // The current scan line before the first call to writePixels()
  111. // is header().dataWindow().min.y. After writing each scan line,
  112. // the current scan line is incremented by 1.
  113. //
  114. // If header.lineOrder() == DECREASING_Y:
  115. //
  116. // The current scan line before the first call to writePixels()
  117. // is header().dataWindow().max.y. After writing each scan line,
  118. // the current scan line is decremented by 1.
  119. //
  120. //------------------------------------------------------------------
  121. IMF_EXPORT
  122. int currentScanLine () const;
  123. //--------------------------------------------------------------
  124. // Shortcut to copy all pixels from an InputFile into this file,
  125. // without uncompressing and then recompressing the pixel data.
  126. // This file's header must be compatible with the InputFile's
  127. // header: The two header's "dataWindow", "compression",
  128. // "lineOrder" and "channels" attributes must be the same.
  129. //--------------------------------------------------------------
  130. IMF_EXPORT
  131. void copyPixels (DeepScanLineInputFile &in);
  132. // --------------------------------------------------------------
  133. // Shortcut to copy pixels from a given part of a multipart file
  134. // --------------------------------------------------------------
  135. IMF_EXPORT
  136. void copyPixels (DeepScanLineInputPart &in);
  137. //--------------------------------------------------------------
  138. // Updating the preview image:
  139. //
  140. // updatePreviewImage() supplies a new set of pixels for the
  141. // preview image attribute in the file's header. If the header
  142. // does not contain a preview image, updatePreviewImage() throws
  143. // an IEX_NAMESPACE::LogicExc.
  144. //
  145. // Note: updatePreviewImage() is necessary because images are
  146. // often stored in a file incrementally, a few scan lines at a
  147. // time, while the image is being generated. Since the preview
  148. // image is an attribute in the file's header, it gets stored in
  149. // the file as soon as the file is opened, but we may not know
  150. // what the preview image should look like until we have written
  151. // the last scan line of the main image.
  152. //
  153. //--------------------------------------------------------------
  154. IMF_EXPORT
  155. void updatePreviewImage (const PreviewRgba newPixels[]);
  156. struct Data;
  157. private:
  158. //------------------------------------------------------------
  159. // Constructor -- attaches the OutputStreamMutex to the
  160. // given one from MultiPartOutputFile. Set the previewPosition
  161. // and lineOffsetsPosition which have been acquired from
  162. // the constructor of MultiPartOutputFile as well.
  163. //------------------------------------------------------------
  164. DeepScanLineOutputFile (const OutputPartData* part);
  165. DeepScanLineOutputFile (const DeepScanLineOutputFile &) = delete;
  166. DeepScanLineOutputFile & operator = (const DeepScanLineOutputFile &) = delete;
  167. DeepScanLineOutputFile (DeepScanLineOutputFile &&) = delete;
  168. DeepScanLineOutputFile & operator = (DeepScanLineOutputFile &&) = delete;
  169. void initialize (const Header &header);
  170. void initializeLineBuffer();
  171. Data * _data;
  172. friend class MultiPartOutputFile;
  173. };
  174. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  175. #endif