ImfInputFile.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_INPUT_FILE_H
  6. #define INCLUDED_IMF_INPUT_FILE_H
  7. //-----------------------------------------------------------------------------
  8. //
  9. // class InputFile -- a scanline-based interface that can be used
  10. // to read both scanline-based and tiled OpenEXR image files.
  11. //
  12. //-----------------------------------------------------------------------------
  13. #include "ImfForward.h"
  14. #include "ImfGenericInputFile.h"
  15. #include "ImfThreading.h"
  16. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  17. class IMF_EXPORT_TYPE InputFile : public GenericInputFile
  18. {
  19. public:
  20. //-----------------------------------------------------------
  21. // A constructor that opens the file with the specified name.
  22. // Destroying the InputFile object will close the file.
  23. //
  24. // numThreads determines the number of threads that will be
  25. // used to read the file (see ImfThreading.h).
  26. //-----------------------------------------------------------
  27. IMF_EXPORT
  28. InputFile (const char fileName[], int numThreads = globalThreadCount());
  29. //-------------------------------------------------------------
  30. // A constructor that attaches the new InputFile object to a
  31. // file that has already been opened. Destroying the InputFile
  32. // object will not close the file.
  33. //
  34. // numThreads determines the number of threads that will be
  35. // used to read the file (see ImfThreading.h).
  36. //-------------------------------------------------------------
  37. IMF_EXPORT
  38. InputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount());
  39. //-----------
  40. // Destructor
  41. //-----------
  42. IMF_EXPORT
  43. virtual ~InputFile ();
  44. //------------------------
  45. // Access to the file name
  46. //------------------------
  47. IMF_EXPORT
  48. const char * fileName () const;
  49. //--------------------------
  50. // Access to the file header
  51. //--------------------------
  52. IMF_EXPORT
  53. const Header & header () const;
  54. //----------------------------------
  55. // Access to the file format version
  56. //----------------------------------
  57. IMF_EXPORT
  58. int version () const;
  59. //-----------------------------------------------------------
  60. // Set the current frame buffer -- copies the FrameBuffer
  61. // object into the InputFile object.
  62. //
  63. // The current frame buffer is the destination for the pixel
  64. // data read from the file. The current frame buffer must be
  65. // set at least once before readPixels() is called.
  66. // The current frame buffer can be changed after each call
  67. // to readPixels().
  68. //-----------------------------------------------------------
  69. IMF_EXPORT
  70. void setFrameBuffer (const FrameBuffer &frameBuffer);
  71. //-----------------------------------
  72. // Access to the current frame buffer
  73. //-----------------------------------
  74. IMF_EXPORT
  75. const FrameBuffer & frameBuffer () const;
  76. //---------------------------------------------------------------
  77. // Check if the file is complete:
  78. //
  79. // isComplete() returns true if all pixels in the data window are
  80. // present in the input file, or false if any pixels are missing.
  81. // (Another program may still be busy writing the file, or file
  82. // writing may have been aborted prematurely.)
  83. //---------------------------------------------------------------
  84. IMF_EXPORT
  85. bool isComplete () const;
  86. //---------------------------------------------------------------
  87. // Check if SSE optimization is enabled
  88. //
  89. // Call after setFrameBuffer() to query whether optimized file decoding
  90. // is available - decode times will be faster if returns true
  91. //
  92. // Optimization depends on:
  93. // the file type (only scanline data is supported),
  94. // the framebuffer channels (RGB/RGBA mono or stereo)
  95. // the framebuffer channel types (all channels half-float format only)
  96. // the file channels (RGB/RGBA mono or stereo)
  97. // the file channel types (all channel half-float format only)
  98. // whether SSE2 instruction support was detected at compile time
  99. //
  100. // Calling isOptimizationEnabled before setFrameBuffer will throw an exception
  101. //
  102. //---------------------------------------------------------------
  103. IMF_EXPORT
  104. bool isOptimizationEnabled () const;
  105. //---------------------------------------------------------------
  106. // Read pixel data:
  107. //
  108. // readPixels(s1,s2) reads all scan lines with y coordinates
  109. // in the interval [min (s1, s2), max (s1, s2)] from the file,
  110. // and stores them in the current frame buffer.
  111. //
  112. // Both s1 and s2 must be within the interval
  113. // [header().dataWindow().min.y, header().dataWindow().max.y]
  114. //
  115. // The scan lines can be read from the file in random order, and
  116. // individual scan lines may be skipped or read multiple times.
  117. // For maximum efficiency, the scan lines should be read in the
  118. // order in which they were written to the file.
  119. //
  120. // readPixels(s) calls readPixels(s,s).
  121. //
  122. //---------------------------------------------------------------
  123. IMF_EXPORT
  124. void readPixels (int scanLine1, int scanLine2);
  125. IMF_EXPORT
  126. void readPixels (int scanLine);
  127. //----------------------------------------------
  128. // Read a block of raw pixel data from the file,
  129. // without uncompressing it (this function is
  130. // used to implement OutputFile::copyPixels()).
  131. //----------------------------------------------
  132. IMF_EXPORT
  133. void rawPixelData (int firstScanLine,
  134. const char *&pixelData,
  135. int &pixelDataSize);
  136. //----------------------------------------------
  137. // Read a scanline's worth of raw pixel data
  138. // from the file, without uncompressing it, and
  139. // store in an external buffer, pixelData.
  140. // pixelData should be pre-allocated with space
  141. // for pixelDataSize chars.
  142. //
  143. // This function can be used to separate the
  144. // reading of a raw scan line from the
  145. // decompression of that scan line, for
  146. // example to allow multiple scan lines to be
  147. // decompressed in parallel by an application's
  148. // own threads, where it is not convenient to
  149. // use the threading within the library.
  150. //----------------------------------------------
  151. IMF_EXPORT
  152. void rawPixelDataToBuffer (int scanLine,
  153. char *pixelData,
  154. int &pixelDataSize) const;
  155. //--------------------------------------------------
  156. // Read a tile of raw pixel data from the file,
  157. // without uncompressing it (this function is
  158. // used to implement TiledOutputFile::copyPixels()).
  159. //--------------------------------------------------
  160. IMF_EXPORT
  161. void rawTileData (int &dx, int &dy,
  162. int &lx, int &ly,
  163. const char *&pixelData,
  164. int &pixelDataSize);
  165. struct IMF_HIDDEN Data;
  166. private:
  167. IMF_HIDDEN InputFile (InputPartData* part);
  168. InputFile (const InputFile &) = delete;
  169. InputFile & operator = (const InputFile &) = delete;
  170. InputFile (InputFile &&) = delete;
  171. InputFile & operator = (InputFile &&) = delete;
  172. IMF_HIDDEN void initialize ();
  173. IMF_HIDDEN void multiPartInitialize(InputPartData* part);
  174. IMF_HIDDEN void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is);
  175. IMF_HIDDEN TiledInputFile * tFile ();
  176. // for copyPixels
  177. friend class TiledOutputFile;
  178. Data * _data;
  179. friend class MultiPartInputFile;
  180. };
  181. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  182. #endif