ImfDeepFrameBuffer.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 IMFDEEPFRAMEBUFFER_H_
  35. #define IMFDEEPFRAMEBUFFER_H_
  36. #include "ImfFrameBuffer.h"
  37. #include "ImfNamespace.h"
  38. #include "ImfExport.h"
  39. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  40. //--------------------------------------------------------
  41. // Description of a single deep slice of the frame buffer:
  42. //--------------------------------------------------------
  43. struct DeepSlice : public Slice
  44. {
  45. //---------------------------------------------------------------------
  46. // The stride for each sample in this slice.
  47. //
  48. // Memory layout: The address of sample i in pixel (x, y) is
  49. //
  50. // base + (xp / xSampling) * xStride + (yp / ySampling) * yStride
  51. // + i * sampleStride
  52. //
  53. // where xp and yp are computed as follows:
  54. //
  55. // * If we are reading or writing a scanline-based file:
  56. //
  57. // xp = x
  58. // yp = y
  59. //
  60. // * If we are reading a tile whose upper left coorner is at (xt, yt):
  61. //
  62. // if xTileCoords is true then xp = x - xt, else xp = x
  63. // if yTileCoords is true then yp = y - yt, else yp = y
  64. //
  65. //---------------------------------------------------------------------
  66. int sampleStride;
  67. //------------
  68. // Constructor
  69. //------------
  70. IMF_EXPORT
  71. DeepSlice (PixelType type = HALF,
  72. char * base = 0,
  73. size_t xStride = 0,
  74. size_t yStride = 0,
  75. size_t sampleStride = 0,
  76. int xSampling = 1,
  77. int ySampling = 1,
  78. double fillValue = 0.0,
  79. bool xTileCoords = false,
  80. bool yTileCoords = false);
  81. };
  82. //-----------------
  83. // DeepFrameBuffer.
  84. //-----------------
  85. class DeepFrameBuffer
  86. {
  87. public:
  88. //------------
  89. // Add a slice
  90. //------------
  91. IMF_EXPORT
  92. void insert (const char name[],
  93. const DeepSlice &slice);
  94. IMF_EXPORT
  95. void insert (const std::string &name,
  96. const DeepSlice &slice);
  97. //----------------------------------------------------------------
  98. // Access to existing slices:
  99. //
  100. // [n] Returns a reference to the slice with name n.
  101. // If no slice with name n exists, an IEX_NAMESPACE::ArgExc
  102. // is thrown.
  103. //
  104. // findSlice(n) Returns a pointer to the slice with name n,
  105. // or 0 if no slice with name n exists.
  106. //
  107. //----------------------------------------------------------------
  108. IMF_EXPORT
  109. DeepSlice & operator [] (const char name[]);
  110. IMF_EXPORT
  111. const DeepSlice & operator [] (const char name[]) const;
  112. IMF_EXPORT
  113. DeepSlice & operator [] (const std::string &name);
  114. IMF_EXPORT
  115. const DeepSlice & operator [] (const std::string &name) const;
  116. IMF_EXPORT
  117. DeepSlice * findSlice (const char name[]);
  118. IMF_EXPORT
  119. const DeepSlice * findSlice (const char name[]) const;
  120. IMF_EXPORT
  121. DeepSlice * findSlice (const std::string &name);
  122. IMF_EXPORT
  123. const DeepSlice * findSlice (const std::string &name) const;
  124. //-----------------------------------------
  125. // Iterator-style access to existing slices
  126. //-----------------------------------------
  127. typedef std::map <Name, DeepSlice> SliceMap;
  128. class Iterator;
  129. class ConstIterator;
  130. IMF_EXPORT
  131. Iterator begin ();
  132. IMF_EXPORT
  133. ConstIterator begin () const;
  134. IMF_EXPORT
  135. Iterator end ();
  136. IMF_EXPORT
  137. ConstIterator end () const;
  138. IMF_EXPORT
  139. Iterator find (const char name[]);
  140. IMF_EXPORT
  141. ConstIterator find (const char name[]) const;
  142. IMF_EXPORT
  143. Iterator find (const std::string &name);
  144. IMF_EXPORT
  145. ConstIterator find (const std::string &name) const;
  146. //----------------------------------------------------
  147. // Public function for accessing a sample count slice.
  148. //----------------------------------------------------
  149. IMF_EXPORT
  150. void insertSampleCountSlice(const Slice & slice);
  151. IMF_EXPORT
  152. const Slice & getSampleCountSlice() const;
  153. private:
  154. SliceMap _map;
  155. Slice _sampleCounts;
  156. };
  157. //----------
  158. // Iterators
  159. //----------
  160. class DeepFrameBuffer::Iterator
  161. {
  162. public:
  163. IMF_EXPORT
  164. Iterator ();
  165. IMF_EXPORT
  166. Iterator (const DeepFrameBuffer::SliceMap::iterator &i);
  167. IMF_EXPORT
  168. Iterator & operator ++ ();
  169. IMF_EXPORT
  170. Iterator operator ++ (int);
  171. IMF_EXPORT
  172. const char * name () const;
  173. IMF_EXPORT
  174. DeepSlice & slice () const;
  175. private:
  176. friend class DeepFrameBuffer::ConstIterator;
  177. DeepFrameBuffer::SliceMap::iterator _i;
  178. };
  179. class DeepFrameBuffer::ConstIterator
  180. {
  181. public:
  182. IMF_EXPORT
  183. ConstIterator ();
  184. IMF_EXPORT
  185. ConstIterator (const DeepFrameBuffer::SliceMap::const_iterator &i);
  186. IMF_EXPORT
  187. ConstIterator (const DeepFrameBuffer::Iterator &other);
  188. IMF_EXPORT
  189. ConstIterator & operator ++ ();
  190. IMF_EXPORT
  191. ConstIterator operator ++ (int);
  192. IMF_EXPORT
  193. const char * name () const;
  194. IMF_EXPORT
  195. const DeepSlice & slice () const;
  196. private:
  197. friend bool operator == (const ConstIterator &, const ConstIterator &);
  198. friend bool operator != (const ConstIterator &, const ConstIterator &);
  199. DeepFrameBuffer::SliceMap::const_iterator _i;
  200. };
  201. //-----------------
  202. // Inline Functions
  203. //-----------------
  204. inline
  205. DeepFrameBuffer::Iterator::Iterator (): _i()
  206. {
  207. // empty
  208. }
  209. inline
  210. DeepFrameBuffer::Iterator::Iterator (const DeepFrameBuffer::SliceMap::iterator &i):
  211. _i (i)
  212. {
  213. // empty
  214. }
  215. inline DeepFrameBuffer::Iterator &
  216. DeepFrameBuffer::Iterator::operator ++ ()
  217. {
  218. ++_i;
  219. return *this;
  220. }
  221. inline DeepFrameBuffer::Iterator
  222. DeepFrameBuffer::Iterator::operator ++ (int)
  223. {
  224. Iterator tmp = *this;
  225. ++_i;
  226. return tmp;
  227. }
  228. inline const char *
  229. DeepFrameBuffer::Iterator::name () const
  230. {
  231. return *_i->first;
  232. }
  233. inline DeepSlice &
  234. DeepFrameBuffer::Iterator::slice () const
  235. {
  236. return _i->second;
  237. }
  238. inline
  239. DeepFrameBuffer::ConstIterator::ConstIterator (): _i()
  240. {
  241. // empty
  242. }
  243. inline
  244. DeepFrameBuffer::ConstIterator::ConstIterator
  245. (const DeepFrameBuffer::SliceMap::const_iterator &i): _i (i)
  246. {
  247. // empty
  248. }
  249. inline
  250. DeepFrameBuffer::ConstIterator::ConstIterator (const DeepFrameBuffer::Iterator &other):
  251. _i (other._i)
  252. {
  253. // empty
  254. }
  255. inline DeepFrameBuffer::ConstIterator &
  256. DeepFrameBuffer::ConstIterator::operator ++ ()
  257. {
  258. ++_i;
  259. return *this;
  260. }
  261. inline DeepFrameBuffer::ConstIterator
  262. DeepFrameBuffer::ConstIterator::operator ++ (int)
  263. {
  264. ConstIterator tmp = *this;
  265. ++_i;
  266. return tmp;
  267. }
  268. inline const char *
  269. DeepFrameBuffer::ConstIterator::name () const
  270. {
  271. return *_i->first;
  272. }
  273. inline const DeepSlice &
  274. DeepFrameBuffer::ConstIterator::slice () const
  275. {
  276. return _i->second;
  277. }
  278. inline bool
  279. operator == (const DeepFrameBuffer::ConstIterator &x,
  280. const DeepFrameBuffer::ConstIterator &y)
  281. {
  282. return x._i == y._i;
  283. }
  284. inline bool
  285. operator != (const DeepFrameBuffer::ConstIterator &x,
  286. const DeepFrameBuffer::ConstIterator &y)
  287. {
  288. return !(x == y);
  289. }
  290. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  291. #endif /* IMFDEEPFRAMEBUFFER_H_ */