ImfDeepScanLineInputFile.h 11 KB

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