ImfDeepTiledInputPart.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 IMFDEEPTILEDINPUTPART_H_
  35. #define IMFDEEPTILEDINPUTPART_H_
  36. #include "ImfDeepTiledInputFile.h"
  37. #include "ImfNamespace.h"
  38. #include "ImfForward.h"
  39. #include "ImfExport.h"
  40. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  41. class DeepTiledInputPart
  42. {
  43. public:
  44. IMF_EXPORT
  45. DeepTiledInputPart(MultiPartInputFile& multiPartFile, int partNumber);
  46. //------------------------
  47. // Access to the file name
  48. //------------------------
  49. IMF_EXPORT
  50. const char * fileName () const;
  51. //--------------------------
  52. // Access to the file header
  53. //--------------------------
  54. IMF_EXPORT
  55. const Header & header () const;
  56. //----------------------------------
  57. // Access to the file format version
  58. //----------------------------------
  59. IMF_EXPORT
  60. int version () const;
  61. //-----------------------------------------------------------
  62. // Set the current frame buffer -- copies the FrameBuffer
  63. // object into the TiledInputFile object.
  64. //
  65. // The current frame buffer is the destination for the pixel
  66. // data read from the file. The current frame buffer must be
  67. // set at least once before readTile() is called.
  68. // The current frame buffer can be changed after each call
  69. // to readTile().
  70. //-----------------------------------------------------------
  71. IMF_EXPORT
  72. void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
  73. //-----------------------------------
  74. // Access to the current frame buffer
  75. //-----------------------------------
  76. IMF_EXPORT
  77. const DeepFrameBuffer & frameBuffer () const;
  78. //------------------------------------------------------------
  79. // Check if the file is complete:
  80. //
  81. // isComplete() returns true if all pixels in the data window
  82. // (in all levels) are present in the input file, or false if
  83. // any pixels are missing. (Another program may still be busy
  84. // writing the file, or file writing may have been aborted
  85. // prematurely.)
  86. //------------------------------------------------------------
  87. IMF_EXPORT
  88. bool isComplete () const;
  89. //--------------------------------------------------
  90. // Utility functions:
  91. //--------------------------------------------------
  92. //---------------------------------------------------------
  93. // Multiresolution mode and tile size:
  94. // The following functions return the xSize, ySize and mode
  95. // fields of the file header's TileDescriptionAttribute.
  96. //---------------------------------------------------------
  97. IMF_EXPORT
  98. unsigned int tileXSize () const;
  99. IMF_EXPORT
  100. unsigned int tileYSize () const;
  101. IMF_EXPORT
  102. LevelMode levelMode () const;
  103. IMF_EXPORT
  104. LevelRoundingMode levelRoundingMode () const;
  105. //--------------------------------------------------------------------
  106. // Number of levels:
  107. //
  108. // numXLevels() returns the file's number of levels in x direction.
  109. //
  110. // if levelMode() == ONE_LEVEL:
  111. // return value is: 1
  112. //
  113. // if levelMode() == MIPMAP_LEVELS:
  114. // return value is: rfunc (log (max (w, h)) / log (2)) + 1
  115. //
  116. // if levelMode() == RIPMAP_LEVELS:
  117. // return value is: rfunc (log (w) / log (2)) + 1
  118. //
  119. // where
  120. // w is the width of the image's data window, max.x - min.x + 1,
  121. // y is the height of the image's data window, max.y - min.y + 1,
  122. // and rfunc(x) is either floor(x), or ceil(x), depending on
  123. // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
  124. //
  125. // numYLevels() returns the file's number of levels in y direction.
  126. //
  127. // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
  128. // return value is the same as for numXLevels()
  129. //
  130. // if levelMode() == RIPMAP_LEVELS:
  131. // return value is: rfunc (log (h) / log (2)) + 1
  132. //
  133. //
  134. // numLevels() is a convenience function for use with
  135. // MIPMAP_LEVELS files.
  136. //
  137. // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
  138. // return value is the same as for numXLevels()
  139. //
  140. // if levelMode() == RIPMAP_LEVELS:
  141. // an IEX_NAMESPACE::LogicExc exception is thrown
  142. //
  143. // isValidLevel(lx, ly) returns true if the file contains
  144. // a level with level number (lx, ly), false if not.
  145. //
  146. //--------------------------------------------------------------------
  147. IMF_EXPORT
  148. int numLevels () const;
  149. IMF_EXPORT
  150. int numXLevels () const;
  151. IMF_EXPORT
  152. int numYLevels () const;
  153. IMF_EXPORT
  154. bool isValidLevel (int lx, int ly) const;
  155. //----------------------------------------------------------
  156. // Dimensions of a level:
  157. //
  158. // levelWidth(lx) returns the width of a level with level
  159. // number (lx, *), where * is any number.
  160. //
  161. // return value is:
  162. // max (1, rfunc (w / pow (2, lx)))
  163. //
  164. //
  165. // levelHeight(ly) returns the height of a level with level
  166. // number (*, ly), where * is any number.
  167. //
  168. // return value is:
  169. // max (1, rfunc (h / pow (2, ly)))
  170. //
  171. //----------------------------------------------------------
  172. IMF_EXPORT
  173. int levelWidth (int lx) const;
  174. IMF_EXPORT
  175. int levelHeight (int ly) const;
  176. //--------------------------------------------------------------
  177. // Number of tiles:
  178. //
  179. // numXTiles(lx) returns the number of tiles in x direction
  180. // that cover a level with level number (lx, *), where * is
  181. // any number.
  182. //
  183. // return value is:
  184. // (levelWidth(lx) + tileXSize() - 1) / tileXSize()
  185. //
  186. //
  187. // numYTiles(ly) returns the number of tiles in y direction
  188. // that cover a level with level number (*, ly), where * is
  189. // any number.
  190. //
  191. // return value is:
  192. // (levelHeight(ly) + tileXSize() - 1) / tileXSize()
  193. //
  194. //--------------------------------------------------------------
  195. IMF_EXPORT
  196. int numXTiles (int lx = 0) const;
  197. IMF_EXPORT
  198. int numYTiles (int ly = 0) const;
  199. //---------------------------------------------------------------
  200. // Level pixel ranges:
  201. //
  202. // dataWindowForLevel(lx, ly) returns a 2-dimensional region of
  203. // valid pixel coordinates for a level with level number (lx, ly)
  204. //
  205. // return value is a Box2i with min value:
  206. // (dataWindow.min.x, dataWindow.min.y)
  207. //
  208. // and max value:
  209. // (dataWindow.min.x + levelWidth(lx) - 1,
  210. // dataWindow.min.y + levelHeight(ly) - 1)
  211. //
  212. // dataWindowForLevel(level) is a convenience function used
  213. // for ONE_LEVEL and MIPMAP_LEVELS files. It returns
  214. // dataWindowForLevel(level, level).
  215. //
  216. //---------------------------------------------------------------
  217. IMF_EXPORT
  218. IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const;
  219. IMF_EXPORT
  220. IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
  221. //-------------------------------------------------------------------
  222. // Tile pixel ranges:
  223. //
  224. // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
  225. // region of valid pixel coordinates for a tile with tile coordinates
  226. // (dx,dy) and level number (lx, ly).
  227. //
  228. // return value is a Box2i with min value:
  229. // (dataWindow.min.x + dx * tileXSize(),
  230. // dataWindow.min.y + dy * tileYSize())
  231. //
  232. // and max value:
  233. // (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
  234. // dataWindow.min.y + (dy + 1) * tileYSize() - 1)
  235. //
  236. // dataWindowForTile(dx, dy, level) is a convenience function
  237. // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns
  238. // dataWindowForTile(dx, dy, level, level).
  239. //
  240. //-------------------------------------------------------------------
  241. IMF_EXPORT
  242. IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const;
  243. IMF_EXPORT
  244. IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy,
  245. int lx, int ly) const;
  246. //------------------------------------------------------------
  247. // Read pixel data:
  248. //
  249. // readTile(dx, dy, lx, ly) reads the tile with tile
  250. // coordinates (dx, dy), and level number (lx, ly),
  251. // and stores it in the current frame buffer.
  252. //
  253. // dx must lie in the interval [0, numXTiles(lx)-1]
  254. // dy must lie in the interval [0, numYTiles(ly)-1]
  255. //
  256. // lx must lie in the interval [0, numXLevels()-1]
  257. // ly must lie in the inverval [0, numYLevels()-1]
  258. //
  259. // readTile(dx, dy, level) is a convenience function used
  260. // for ONE_LEVEL and MIPMAP_LEVELS files. It calls
  261. // readTile(dx, dy, level, level).
  262. //
  263. // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
  264. // reading multiple tiles at once. If multi-threading is used
  265. // the multiple tiles are read concurrently.
  266. //
  267. // Pixels that are outside the pixel coordinate range for the
  268. // tile's level, are never accessed by readTile().
  269. //
  270. // Attempting to access a tile that is not present in the file
  271. // throws an InputExc exception.
  272. //
  273. //------------------------------------------------------------
  274. IMF_EXPORT
  275. void readTile (int dx, int dy, int l = 0);
  276. IMF_EXPORT
  277. void readTile (int dx, int dy, int lx, int ly);
  278. IMF_EXPORT
  279. void readTiles (int dx1, int dx2, int dy1, int dy2,
  280. int lx, int ly);
  281. IMF_EXPORT
  282. void readTiles (int dx1, int dx2, int dy1, int dy2,
  283. int l = 0);
  284. //--------------------------------------------------
  285. // Read a tile of raw pixel data from the file,
  286. // without uncompressing it (this function is
  287. // used to implement TiledOutputFile::copyPixels()).
  288. //--------------------------------------------------
  289. IMF_EXPORT
  290. void rawTileData (int &dx, int &dy,
  291. int &lx, int &ly,
  292. char *data,
  293. Int64 &dataSize
  294. ) const;
  295. //------------------------------------------------------------------
  296. // Read pixel sample counts into a slice in the frame buffer.
  297. //
  298. // readPixelSampleCount(dx, dy, lx, ly) reads the sample counts
  299. // for tile (dx, dy) in level (lx, ly).
  300. //
  301. // readPixelSampleCount(dx, dy, l) calls
  302. // readPixelSampleCount(dx, dy, lx = l, ly = l)
  303. //
  304. // dx must lie in the interval [0, numXTiles(lx)-1]
  305. // dy must lie in the interval [0, numYTiles(ly)-1]
  306. //
  307. // lx must lie in the interval [0, numXLevels()-1]
  308. // ly must lie in the inverval [0, numYLevels()-1]
  309. //
  310. // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx, ly) reads all
  311. // the sample counts for tiles within range
  312. // [(min(dx1, dx2), min(dy1, dy2))...(max(dx1, dx2), max(dy1, dy2)],
  313. // and on level (lx, ly)
  314. //
  315. // readPixelSampleCounts(dx1, dx2, dy1, dy2, l) calls
  316. // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx = l, ly = l).
  317. //------------------------------------------------------------------
  318. IMF_EXPORT
  319. void readPixelSampleCount (int dx, int dy, int l = 0);
  320. IMF_EXPORT
  321. void readPixelSampleCount (int dx, int dy, int lx, int ly);
  322. IMF_EXPORT
  323. void readPixelSampleCounts (int dx1, int dx2,
  324. int dy1, int dy2,
  325. int lx, int ly);
  326. IMF_EXPORT
  327. void readPixelSampleCounts (int dx1, int dx2,
  328. int dy1, int dy2,
  329. int l = 0);
  330. private:
  331. DeepTiledInputFile* file;
  332. friend void DeepTiledOutputFile::copyPixels(DeepTiledInputPart &);
  333. };
  334. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  335. #endif /* IMFDEEPTILEDINPUTPART_H_ */