ImfDeepTiledInputPart.h 12 KB

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