/src/FreeImage/Source/OpenEXR/IlmImf/ImfFrameBuffer.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 383 lines · 168 code · 94 blank · 121 comment · 6 complexity · e7161be8735ba876e6c822edc4d6338a MD5 · raw file

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