ImfDeepFrameBuffer.h 7.7 KB

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