ImfScanLineInputFile.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_SCAN_LINE_INPUT_FILE_H
  35. #define INCLUDED_IMF_SCAN_LINE_INPUT_FILE_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // class ScanLineInputFile
  39. //
  40. //-----------------------------------------------------------------------------
  41. #include "ImfHeader.h"
  42. #include "ImfFrameBuffer.h"
  43. #include "ImfThreading.h"
  44. #include "ImfInputStreamMutex.h"
  45. #include "ImfInputPartData.h"
  46. #include "ImfGenericInputFile.h"
  47. #include "ImfExport.h"
  48. #include "ImfNamespace.h"
  49. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  50. class ScanLineInputFile : public GenericInputFile
  51. {
  52. public:
  53. //------------
  54. // Constructor
  55. //------------
  56. IMF_EXPORT
  57. ScanLineInputFile (const Header &header, OPENEXR_IMF_INTERNAL_NAMESPACE::IStream *is,
  58. int numThreads = globalThreadCount());
  59. //-----------------------------------------
  60. // Destructor -- deallocates internal data
  61. // structures, but does not close the file.
  62. //-----------------------------------------
  63. IMF_EXPORT
  64. virtual ~ScanLineInputFile ();
  65. //------------------------
  66. // Access to the file name
  67. //------------------------
  68. IMF_EXPORT
  69. const char * fileName () const;
  70. //--------------------------
  71. // Access to the file header
  72. //--------------------------
  73. IMF_EXPORT
  74. const Header & header () const;
  75. //----------------------------------
  76. // Access to the file format version
  77. //----------------------------------
  78. IMF_EXPORT
  79. int version () const;
  80. //-----------------------------------------------------------
  81. // Set the current frame buffer -- copies the FrameBuffer
  82. // object into the InputFile object.
  83. //
  84. // The current frame buffer is the destination for the pixel
  85. // data read from the file. The current frame buffer must be
  86. // set at least once before readPixels() is called.
  87. // The current frame buffer can be changed after each call
  88. // to readPixels().
  89. //-----------------------------------------------------------
  90. IMF_EXPORT
  91. void setFrameBuffer (const FrameBuffer &frameBuffer);
  92. //-----------------------------------
  93. // Access to the current frame buffer
  94. //-----------------------------------
  95. IMF_EXPORT
  96. const FrameBuffer & frameBuffer () const;
  97. //---------------------------------------------------------------
  98. // Check if the file is complete:
  99. //
  100. // isComplete() returns true if all pixels in the data window are
  101. // present in the input file, or false if any pixels are missing.
  102. // (Another program may still be busy writing the file, or file
  103. // writing may have been aborted prematurely.)
  104. //---------------------------------------------------------------
  105. IMF_EXPORT
  106. bool isComplete () const;
  107. //---------------------------------------------------------------
  108. // Check if SSE optimisation is enabled
  109. //
  110. // Call after setFrameBuffer() to query whether optimised file decoding
  111. // is available - decode times will be faster if returns true
  112. //
  113. // Optimisation depends on the framebuffer channels and channel types
  114. // as well as the file/part channels and channel types, as well as
  115. // whether SSE2 instruction support was detected at compile time
  116. //
  117. // Calling before setFrameBuffer will throw an exception
  118. //
  119. //---------------------------------------------------------------
  120. IMF_EXPORT
  121. bool isOptimizationEnabled () const;
  122. //---------------------------------------------------------------
  123. // Read pixel data:
  124. //
  125. // readPixels(s1,s2) reads all scan lines with y coordinates
  126. // in the interval [min (s1, s2), max (s1, s2)] from the file,
  127. // and stores them in the current frame buffer.
  128. //
  129. // Both s1 and s2 must be within the interval
  130. // [header().dataWindow().min.y, header.dataWindow().max.y]
  131. //
  132. // The scan lines can be read from the file in random order, and
  133. // individual scan lines may be skipped or read multiple times.
  134. // For maximum efficiency, the scan lines should be read in the
  135. // order in which they were written to the file.
  136. //
  137. // readPixels(s) calls readPixels(s,s).
  138. //
  139. // If threading is enabled, readPixels (s1, s2) tries to perform
  140. // decopmression of multiple scanlines in parallel.
  141. //
  142. //---------------------------------------------------------------
  143. IMF_EXPORT
  144. void readPixels (int scanLine1, int scanLine2);
  145. IMF_EXPORT
  146. void readPixels (int scanLine);
  147. //----------------------------------------------
  148. // Read a block of raw pixel data from the file,
  149. // without uncompressing it (this function is
  150. // used to implement OutputFile::copyPixels()).
  151. //----------------------------------------------
  152. IMF_EXPORT
  153. void rawPixelData (int firstScanLine,
  154. const char *&pixelData,
  155. int &pixelDataSize);
  156. //----------------------------------------------
  157. // Read a scanline's worth of raw pixel data
  158. // from the file, without uncompressing it, and
  159. // store in an external buffer, pixelData.
  160. // pixelData should be pre-allocated with space
  161. // for pixelDataSize chars.
  162. //
  163. // This function can be used to separate the
  164. // reading of a raw scan line from the
  165. // decompression of that scan line, for
  166. // example to allow multiple scan lines to be
  167. // decompressed in parallel by an application's
  168. // own threads, where it is not convenient to
  169. // use the threading within the library.
  170. //----------------------------------------------
  171. IMF_EXPORT
  172. void rawPixelDataToBuffer(int scanLine,
  173. char *pixelData,
  174. int &pixelDataSize) const;
  175. struct Data;
  176. private:
  177. Data * _data;
  178. InputStreamMutex* _streamData;
  179. ScanLineInputFile (InputPartData* part);
  180. void initialize(const Header& header);
  181. friend class MultiPartInputFile;
  182. friend class InputFile;
  183. };
  184. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  185. #endif