ImfOutputFile.h 8.2 KB

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