ImfDeepTiledOutputPart.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef IMFDEEPTILEDOUTPUTPART_H_
  6. #define IMFDEEPTILEDOUTPUTPART_H_
  7. #include "ImfForward.h"
  8. #include "ImfTileDescription.h"
  9. #include <ImathBox.h>
  10. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  11. class IMF_EXPORT_TYPE DeepTiledOutputPart
  12. {
  13. public:
  14. IMF_EXPORT
  15. DeepTiledOutputPart(MultiPartOutputFile& multiPartFile, int partNumber);
  16. //------------------------
  17. // Access to the file name
  18. //------------------------
  19. IMF_EXPORT
  20. const char * fileName () const;
  21. //--------------------------
  22. // Access to the file header
  23. //--------------------------
  24. IMF_EXPORT
  25. const Header & header () const;
  26. //-------------------------------------------------------
  27. // Set the current frame buffer -- copies the FrameBuffer
  28. // object into the TiledOutputFile object.
  29. //
  30. // The current frame buffer is the source of the pixel
  31. // data written to the file. The current frame buffer
  32. // must be set at least once before writeTile() is
  33. // called. The current frame buffer can be changed
  34. // after each call to writeTile().
  35. //-------------------------------------------------------
  36. IMF_EXPORT
  37. void setFrameBuffer (const DeepFrameBuffer &frameBuffer);
  38. //-----------------------------------
  39. // Access to the current frame buffer
  40. //-----------------------------------
  41. IMF_EXPORT
  42. const DeepFrameBuffer & frameBuffer () const;
  43. //-------------------
  44. // Utility functions:
  45. //-------------------
  46. //---------------------------------------------------------
  47. // Multiresolution mode and tile size:
  48. // The following functions return the xSize, ySize and mode
  49. // fields of the file header's TileDescriptionAttribute.
  50. //---------------------------------------------------------
  51. IMF_EXPORT
  52. unsigned int tileXSize () const;
  53. IMF_EXPORT
  54. unsigned int tileYSize () const;
  55. IMF_EXPORT
  56. LevelMode levelMode () const;
  57. IMF_EXPORT
  58. LevelRoundingMode levelRoundingMode () const;
  59. //--------------------------------------------------------------------
  60. // Number of levels:
  61. //
  62. // numXLevels() returns the file's number of levels in x direction.
  63. //
  64. // if levelMode() == ONE_LEVEL:
  65. // return value is: 1
  66. //
  67. // if levelMode() == MIPMAP_LEVELS:
  68. // return value is: rfunc (log (max (w, h)) / log (2)) + 1
  69. //
  70. // if levelMode() == RIPMAP_LEVELS:
  71. // return value is: rfunc (log (w) / log (2)) + 1
  72. //
  73. // where
  74. // w is the width of the image's data window, max.x - min.x + 1,
  75. // y is the height of the image's data window, max.y - min.y + 1,
  76. // and rfunc(x) is either floor(x), or ceil(x), depending on
  77. // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
  78. //
  79. // numYLevels() returns the file's number of levels in y direction.
  80. //
  81. // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
  82. // return value is the same as for numXLevels()
  83. //
  84. // if levelMode() == RIPMAP_LEVELS:
  85. // return value is: rfunc (log (h) / log (2)) + 1
  86. //
  87. //
  88. // numLevels() is a convenience function for use with MIPMAP_LEVELS
  89. // files.
  90. //
  91. // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
  92. // return value is the same as for numXLevels()
  93. //
  94. // if levelMode() == RIPMAP_LEVELS:
  95. // an IEX_NAMESPACE::LogicExc exception is thrown
  96. //
  97. // isValidLevel(lx, ly) returns true if the file contains
  98. // a level with level number (lx, ly), false if not.
  99. //
  100. //--------------------------------------------------------------------
  101. IMF_EXPORT
  102. int numLevels () const;
  103. IMF_EXPORT
  104. int numXLevels () const;
  105. IMF_EXPORT
  106. int numYLevels () const;
  107. IMF_EXPORT
  108. bool isValidLevel (int lx, int ly) const;
  109. //---------------------------------------------------------
  110. // Dimensions of a level:
  111. //
  112. // levelWidth(lx) returns the width of a level with level
  113. // number (lx, *), where * is any number.
  114. //
  115. // return value is:
  116. // max (1, rfunc (w / pow (2, lx)))
  117. //
  118. //
  119. // levelHeight(ly) returns the height of a level with level
  120. // number (*, ly), where * is any number.
  121. //
  122. // return value is:
  123. // max (1, rfunc (h / pow (2, ly)))
  124. //
  125. //---------------------------------------------------------
  126. IMF_EXPORT
  127. int levelWidth (int lx) const;
  128. IMF_EXPORT
  129. int levelHeight (int ly) const;
  130. //----------------------------------------------------------
  131. // Number of tiles:
  132. //
  133. // numXTiles(lx) returns the number of tiles in x direction
  134. // that cover a level with level number (lx, *), where * is
  135. // any number.
  136. //
  137. // return value is:
  138. // (levelWidth(lx) + tileXSize() - 1) / tileXSize()
  139. //
  140. //
  141. // numYTiles(ly) returns the number of tiles in y direction
  142. // that cover a level with level number (*, ly), where * is
  143. // any number.
  144. //
  145. // return value is:
  146. // (levelHeight(ly) + tileXSize() - 1) / tileXSize()
  147. //
  148. //----------------------------------------------------------
  149. IMF_EXPORT
  150. int numXTiles (int lx = 0) const;
  151. IMF_EXPORT
  152. int numYTiles (int ly = 0) const;
  153. //---------------------------------------------------------
  154. // Level pixel ranges:
  155. //
  156. // dataWindowForLevel(lx, ly) returns a 2-dimensional
  157. // region of valid pixel coordinates for a level with
  158. // level number (lx, ly)
  159. //
  160. // return value is a Box2i with min value:
  161. // (dataWindow.min.x, dataWindow.min.y)
  162. //
  163. // and max value:
  164. // (dataWindow.min.x + levelWidth(lx) - 1,
  165. // dataWindow.min.y + levelHeight(ly) - 1)
  166. //
  167. // dataWindowForLevel(level) is a convenience function used
  168. // for ONE_LEVEL and MIPMAP_LEVELS files. It returns
  169. // dataWindowForLevel(level, level).
  170. //
  171. //---------------------------------------------------------
  172. IMF_EXPORT
  173. IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const;
  174. IMF_EXPORT
  175. IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
  176. //-------------------------------------------------------------------
  177. // Tile pixel ranges:
  178. //
  179. // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
  180. // region of valid pixel coordinates for a tile with tile coordinates
  181. // (dx,dy) and level number (lx, ly).
  182. //
  183. // return value is a Box2i with min value:
  184. // (dataWindow.min.x + dx * tileXSize(),
  185. // dataWindow.min.y + dy * tileYSize())
  186. //
  187. // and max value:
  188. // (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
  189. // dataWindow.min.y + (dy + 1) * tileYSize() - 1)
  190. //
  191. // dataWindowForTile(dx, dy, level) is a convenience function
  192. // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns
  193. // dataWindowForTile(dx, dy, level, level).
  194. //
  195. //-------------------------------------------------------------------
  196. IMF_EXPORT
  197. IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy,
  198. int l = 0) const;
  199. IMF_EXPORT
  200. IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy,
  201. int lx, int ly) const;
  202. //------------------------------------------------------------------
  203. // Write pixel data:
  204. //
  205. // writeTile(dx, dy, lx, ly) writes the tile with tile
  206. // coordinates (dx, dy), and level number (lx, ly) to
  207. // the file.
  208. //
  209. // dx must lie in the interval [0, numXTiles(lx) - 1]
  210. // dy must lie in the interval [0, numYTiles(ly) - 1]
  211. //
  212. // lx must lie in the interval [0, numXLevels() - 1]
  213. // ly must lie in the interval [0, numYLevels() - 1]
  214. //
  215. // writeTile(dx, dy, level) is a convenience function
  216. // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls
  217. // writeTile(dx, dy, level, level).
  218. //
  219. // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow
  220. // writing multiple tiles at once. If multi-threading is used
  221. // multiple tiles are written concurrently. The tile coordinates,
  222. // dx1, dx2 and dy1, dy2, specify inclusive ranges of tile
  223. // coordinates. It is valid for dx1 < dx2 or dy1 < dy2; the
  224. // tiles are always written in the order specified by the line
  225. // order attribute. Hence, it is not possible to specify an
  226. // "invalid" or empty tile range.
  227. //
  228. // Pixels that are outside the pixel coordinate range for the tile's
  229. // level, are never accessed by writeTile().
  230. //
  231. // Each tile in the file must be written exactly once.
  232. //
  233. // The file's line order attribute determines the order of the tiles
  234. // in the file:
  235. //
  236. // INCREASING_Y In the file, the tiles for each level are stored
  237. // in a contiguous block. The levels are ordered
  238. // like this:
  239. //
  240. // (0, 0) (1, 0) ... (nx-1, 0)
  241. // (0, 1) (1, 1) ... (nx-1, 1)
  242. // ...
  243. // (0,ny-1) (1,ny-1) ... (nx-1,ny-1)
  244. //
  245. // where nx = numXLevels(), and ny = numYLevels().
  246. // In an individual level, (lx, ly), the tiles
  247. // are stored in the following order:
  248. //
  249. // (0, 0) (1, 0) ... (tx-1, 0)
  250. // (0, 1) (1, 1) ... (tx-1, 1)
  251. // ...
  252. // (0,ty-1) (1,ty-1) ... (tx-1,ty-1)
  253. //
  254. // where tx = numXTiles(lx),
  255. // and ty = numYTiles(ly).
  256. //
  257. // DECREASING_Y As for INCREASING_Y, the tiles for each level
  258. // are stored in a contiguous block. The levels
  259. // are ordered the same way as for INCREASING_Y,
  260. // but within an individual level, the tiles
  261. // are stored in this order:
  262. //
  263. // (0,ty-1) (1,ty-1) ... (tx-1,ty-1)
  264. // ...
  265. // (0, 1) (1, 1) ... (tx-1, 1)
  266. // (0, 0) (1, 0) ... (tx-1, 0)
  267. //
  268. //
  269. // RANDOM_Y The order of the calls to writeTile() determines
  270. // the order of the tiles in the file.
  271. //
  272. //------------------------------------------------------------------
  273. IMF_EXPORT
  274. void writeTile (int dx, int dy, int l = 0);
  275. IMF_EXPORT
  276. void writeTile (int dx, int dy, int lx, int ly);
  277. IMF_EXPORT
  278. void writeTiles (int dx1, int dx2, int dy1, int dy2,
  279. int lx, int ly);
  280. IMF_EXPORT
  281. void writeTiles (int dx1, int dx2, int dy1, int dy2,
  282. int l = 0);
  283. //------------------------------------------------------------------
  284. // Shortcut to copy all pixels from a TiledInputFile into this file,
  285. // without uncompressing and then recompressing the pixel data.
  286. // This file's header must be compatible with the TiledInputFile's
  287. // header: The two header's "dataWindow", "compression",
  288. // "lineOrder", "channels", and "tiles" attributes must be the same.
  289. //------------------------------------------------------------------
  290. IMF_EXPORT
  291. void copyPixels (DeepTiledInputFile &in);
  292. IMF_EXPORT
  293. void copyPixels (DeepTiledInputPart &in);
  294. //--------------------------------------------------------------
  295. // Updating the preview image:
  296. //
  297. // updatePreviewImage() supplies a new set of pixels for the
  298. // preview image attribute in the file's header. If the header
  299. // does not contain a preview image, updatePreviewImage() throws
  300. // an IEX_NAMESPACE::LogicExc.
  301. //
  302. // Note: updatePreviewImage() is necessary because images are
  303. // often stored in a file incrementally, a few tiles at a time,
  304. // while the image is being generated. Since the preview image
  305. // is an attribute in the file's header, it gets stored in the
  306. // file as soon as the file is opened, but we may not know what
  307. // the preview image should look like until we have written the
  308. // last tile of the main image.
  309. //
  310. //--------------------------------------------------------------
  311. IMF_EXPORT
  312. void updatePreviewImage (const PreviewRgba newPixels[]);
  313. //-------------------------------------------------------------
  314. // Break a tile -- for testing and debugging only:
  315. //
  316. // breakTile(dx,dy,lx,ly,p,n,c) introduces an error into the
  317. // output file by writing n copies of character c, starting
  318. // p bytes from the beginning of the tile with tile coordinates
  319. // (dx, dy) and level number (lx, ly).
  320. //
  321. // Warning: Calling this function usually results in a broken
  322. // image file. The file or parts of it may not be readable,
  323. // or the file may contain bad data.
  324. //
  325. //-------------------------------------------------------------
  326. IMF_EXPORT
  327. void breakTile (int dx, int dy,
  328. int lx, int ly,
  329. int offset,
  330. int length,
  331. char c);
  332. private:
  333. DeepTiledOutputFile* file;
  334. };
  335. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  336. #endif /* IMFDEEPTILEDOUTPUTPART_H_ */