ImfDeepScanLineInputFile.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
  6. #define INCLUDED_IMF_DEEP_SCAN_LINE_INPUT_FILE_H
  7. //-----------------------------------------------------------------------------
  8. //
  9. // class DeepScanLineInputFile
  10. //
  11. //-----------------------------------------------------------------------------
  12. #include "ImfForward.h"
  13. #include "ImfThreading.h"
  14. #include "ImfGenericInputFile.h"
  15. #include "ImfDeepScanLineOutputFile.h"
  16. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  17. class IMF_EXPORT_TYPE DeepScanLineInputFile : public GenericInputFile
  18. {
  19. public:
  20. //------------
  21. // Constructor
  22. //------------
  23. IMF_EXPORT
  24. DeepScanLineInputFile (const char fileName[],
  25. int numThreads = globalThreadCount());
  26. IMF_EXPORT
  27. DeepScanLineInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
  28. int numThreads = globalThreadCount());
  29. IMF_EXPORT
  30. DeepScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
  31. int version, /*version field from file*/
  32. int numThreads = globalThreadCount());
  33. DeepScanLineInputFile (const DeepScanLineInputFile& other) = delete;
  34. DeepScanLineInputFile& operator = (const DeepScanLineInputFile& other) = delete;
  35. DeepScanLineInputFile (DeepScanLineInputFile&& other) = delete;
  36. DeepScanLineInputFile& operator = (DeepScanLineInputFile&& other) = delete;
  37. //-----------------------------------------
  38. // Destructor -- deallocates internal data
  39. // structures, but does not close the file.
  40. //-----------------------------------------
  41. IMF_EXPORT
  42. virtual ~DeepScanLineInputFile ();
  43. //------------------------
  44. // Access to the file name
  45. //------------------------
  46. IMF_EXPORT
  47. const char * fileName () const;
  48. //--------------------------
  49. // Access to the file header
  50. //--------------------------
  51. IMF_EXPORT
  52. const Header & header () const;
  53. //----------------------------------
  54. // Access to the file format version
  55. //----------------------------------
  56. IMF_EXPORT
  57. int version () const;
  58. //-----------------------------------------------------------
  59. // Set the current frame buffer -- copies the FrameBuffer
  60. // object into the InputFile object.
  61. //
  62. // The current frame buffer is the destination for the pixel
  63. // data read from the file. The current frame buffer must be
  64. // set at least once before readPixels() is called.
  65. // The current frame buffer can be changed after each call
  66. // to readPixels().
  67. //-----------------------------------------------------------
  68. IMF_EXPORT
  69. void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
  70. //-----------------------------------
  71. // Access to the current frame buffer
  72. //-----------------------------------
  73. IMF_EXPORT
  74. const DeepFrameBuffer & frameBuffer () const;
  75. //---------------------------------------------------------------
  76. // Check if the file is complete:
  77. //
  78. // isComplete() returns true if all pixels in the data window are
  79. // present in the input file, or false if any pixels are missing.
  80. // (Another program may still be busy writing the file, or file
  81. // writing may have been aborted prematurely.)
  82. //---------------------------------------------------------------
  83. IMF_EXPORT
  84. bool isComplete () const;
  85. //---------------------------------------------------------------
  86. // Read pixel data:
  87. //
  88. // readPixels(s1,s2) reads all scan lines with y coordinates
  89. // in the interval [min (s1, s2), max (s1, s2)] from the file,
  90. // and stores them in the current frame buffer.
  91. //
  92. // Both s1 and s2 must be within the interval
  93. // [header().dataWindow().min.y, header.dataWindow().max.y]
  94. //
  95. // The scan lines can be read from the file in random order, and
  96. // individual scan lines may be skipped or read multiple times.
  97. // For maximum efficiency, the scan lines should be read in the
  98. // order in which they were written to the file.
  99. //
  100. // readPixels(s) calls readPixels(s,s).
  101. //
  102. // If threading is enabled, readPixels (s1, s2) tries to perform
  103. // decopmression of multiple scanlines in parallel.
  104. //
  105. //---------------------------------------------------------------
  106. IMF_EXPORT
  107. void readPixels (int scanLine1, int scanLine2);
  108. IMF_EXPORT
  109. void readPixels (int scanLine);
  110. //---------------------------------------------------------------
  111. // Extract pixel data from pre-read block
  112. //
  113. // readPixels(rawPixelData,frameBuffer,s1,s2) reads all scan lines with y coordinates
  114. // in the interval [min (s1, s2), max (s1, s2)] from the data provided and
  115. // stores them in the provided frameBuffer.
  116. // the data can be obtained from a call to rawPixelData()
  117. //
  118. //
  119. // Both s1 and s2 must be within the data specified
  120. //
  121. // you must provide a frameBuffer with a samplecountslice, which must have been read
  122. // and the data valid - readPixels uses your sample count buffer to compute
  123. // offsets to the data it needs
  124. //
  125. // This call does not block, and is thread safe for clients with an existing
  126. // threading model. The InputFile's frameBuffer is not used in this call.
  127. //
  128. // This call is only provided for clients which have an existing threading model in place
  129. // and unpredictable access patterns to the data.
  130. // The fastest way to read an entire image is to enable threading,use setFrameBuffer then
  131. // readPixels(header().dataWindow().min.y, header.dataWindow().max.y)
  132. //
  133. //---------------------------------------------------------------
  134. IMF_EXPORT
  135. void readPixels (const char * rawPixelData,
  136. const DeepFrameBuffer & frameBuffer,
  137. int scanLine1,
  138. int scanLine2) const;
  139. //----------------------------------------------
  140. // Read a block of raw pixel data from the file,
  141. // without uncompressing it (this function is
  142. // used to implement OutputFile::copyPixels()).
  143. // note: returns the entire payload of the relevant chunk of data, not including part number
  144. // including compressed and uncompressed sizes
  145. // on entry, if pixelDataSize is insufficiently large, no bytes are read (pixelData can safely be NULL)
  146. // on exit, pixelDataSize is the number of bytes required to read the chunk
  147. //
  148. //----------------------------------------------
  149. IMF_EXPORT
  150. void rawPixelData (int firstScanLine,
  151. char * pixelData,
  152. uint64_t &pixelDataSize);
  153. //-------------------------------------------------
  154. // firstScanLineInChunk() returns the row number of the first row that's stored in the
  155. // same chunk as scanline y. Depending on the compression mode, this may not be the same as y
  156. //
  157. // lastScanLineInChunk() returns the row number of the last row that's stored in the same
  158. // chunk as scanline y. Depending on the compression mode, this may not be the same as y.
  159. // The last chunk in the file may be smaller than all the others
  160. //
  161. //------------------------------------------------
  162. IMF_EXPORT
  163. int firstScanLineInChunk(int y) const;
  164. IMF_EXPORT
  165. int lastScanLineInChunk (int y) const;
  166. //-----------------------------------------------------------
  167. // Read pixel sample counts into a slice in the frame buffer.
  168. //
  169. // readPixelSampleCounts(s1, s2) reads all the counts of
  170. // pixel samples with y coordinates in the interval
  171. // [min (s1, s2), max (s1, s2)] from the file, and stores
  172. // them in the slice naming "sample count".
  173. //
  174. // Both s1 and s2 must be within the interval
  175. // [header().dataWindow().min.y, header.dataWindow().max.y]
  176. //
  177. // readPixelSampleCounts(s) calls readPixelSampleCounts(s,s).
  178. //
  179. //-----------------------------------------------------------
  180. IMF_EXPORT
  181. void readPixelSampleCounts (int scanline1,
  182. int scanline2);
  183. IMF_EXPORT
  184. void readPixelSampleCounts (int scanline);
  185. //----------------------------------------------------------
  186. // Read pixel sample counts into the provided frameBuffer
  187. // using a block read of data read by rawPixelData
  188. // for multi-scanline compression schemes, you must decode the entire block
  189. // so scanline1=firstScanLineInChunk(y) and scanline2=lastScanLineInChunk(y)
  190. //
  191. // This call does not block, and is thread safe for clients with an existing
  192. // threading model. The InputFile's frameBuffer is not used in this call.
  193. //
  194. // The fastest way to read an entire image is to enable threading in OpenEXR, use setFrameBuffer then
  195. // readPixelSampleCounts(header().dataWindow().min.y, header.dataWindow().max.y)
  196. //
  197. //----------------------------------------------------------
  198. IMF_EXPORT
  199. void readPixelSampleCounts (const char * rawdata ,
  200. const DeepFrameBuffer & frameBuffer,
  201. int scanLine1 ,
  202. int scanLine2) const;
  203. struct IMF_HIDDEN Data;
  204. private:
  205. Data * _data;
  206. DeepScanLineInputFile (InputPartData* part);
  207. void initialize(const Header& header);
  208. void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is);
  209. void multiPartInitialize(InputPartData* part);
  210. friend class InputFile;
  211. friend class MultiPartInputFile;
  212. friend void DeepScanLineOutputFile::copyPixels(DeepScanLineInputFile &);
  213. };
  214. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  215. #endif