ImfDeepTiledOutputPart.h 15 KB

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