ImfInputFile.h 9.2 KB

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