/GiaoTrinh/DoHoa/SuperBible4/examples/src/shared/openexr-1.4.0-vsnet2003/include/OpenEXR/ImfChannelList.h

https://github.com/mymoon89/SPKT_TRANTHITHUY · C Header · 392 lines · 164 code · 92 blank · 136 comment · 8 complexity · 9a7f5d57a31115c8d5d8e89457d8d5f0 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_CHANNEL_LIST_H
  35. #define INCLUDED_IMF_CHANNEL_LIST_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // class Channel
  39. // class ChannelList
  40. //
  41. //-----------------------------------------------------------------------------
  42. #include <ImfName.h>
  43. #include <ImfPixelType.h>
  44. #include <map>
  45. #include <set>
  46. #include <string>
  47. namespace Imf {
  48. struct Channel
  49. {
  50. //------------------------------
  51. // Data type; see ImfPixelType.h
  52. //------------------------------
  53. PixelType type;
  54. //--------------------------------------------
  55. // Subsampling: pixel (x, y) is present in the
  56. // channel only if
  57. //
  58. // x % xSampling == 0 && y % ySampling == 0
  59. //
  60. //--------------------------------------------
  61. int xSampling;
  62. int ySampling;
  63. //------------
  64. // Constructor
  65. //------------
  66. Channel (PixelType type = HALF,
  67. int xSampling = 1,
  68. int ySampling = 1);
  69. //------------
  70. // Operator ==
  71. //------------
  72. bool operator == (const Channel &other) const;
  73. };
  74. class ChannelList
  75. {
  76. public:
  77. //--------------
  78. // Add a channel
  79. //--------------
  80. void insert (const char name[],
  81. const Channel &channel);
  82. //------------------------------------------------------------------
  83. // Access to existing channels:
  84. //
  85. // [n] Returns a reference to the channel with name n.
  86. // If no channel with name n exists, an Iex::ArgExc
  87. // is thrown.
  88. //
  89. // findChannel(n) Returns a pointer to the channel with name n,
  90. // or 0 if no channel with name n exists.
  91. //
  92. //------------------------------------------------------------------
  93. Channel & operator [] (const char name[]);
  94. const Channel & operator [] (const char name[]) const;
  95. Channel * findChannel (const char name[]);
  96. const Channel * findChannel (const char name[]) const;
  97. //-------------------------------------------
  98. // Iterator-style access to existing channels
  99. //-------------------------------------------
  100. typedef std::map <Name, Channel> ChannelMap;
  101. class Iterator;
  102. class ConstIterator;
  103. Iterator begin ();
  104. ConstIterator begin () const;
  105. Iterator end ();
  106. ConstIterator end () const;
  107. Iterator find (const char name[]);
  108. ConstIterator find (const char name[]) const;
  109. //-----------------------------------------------------------------
  110. // Support for image layers:
  111. //
  112. // In an image file with many channels it is sometimes useful to
  113. // group the channels into "layers", that is, into sets of channels
  114. // that logically belong together. Grouping channels into layers
  115. // is done using a naming convention: channel C in layer L is
  116. // called "L.C".
  117. //
  118. // For example, a computer graphic image may contain separate
  119. // R, G and B channels for light that originated at each of
  120. // several different virtual light sources. The channels in
  121. // this image might be called "light1.R", "light1.G", "light1.B",
  122. // "light2.R", "light2.G", "light2.B", etc.
  123. //
  124. // Note that this naming convention allows layers to be nested;
  125. // for example, "light1.specular.R" identifies the "R" channel
  126. // in the "specular" sub-layer of layer "light1".
  127. //
  128. // Channel names that don't contain a "." or that contain a
  129. // "." only at the beginning or at the end are not considered
  130. // to be part of any layer.
  131. //
  132. // layers(lns) sorts the channels in this ChannelList
  133. // into layers and stores the names of
  134. // all layers, sorted alphabetically,
  135. // into string set lns.
  136. //
  137. // channelsInLayer(ln,f,l) stores a pair of iterators in f and l
  138. // such that the loop
  139. //
  140. // for (ConstIterator i = f; i != l; ++i)
  141. // ...
  142. //
  143. // iterates over all channels in layer ln.
  144. // channelsInLayer (ln, l, p) calls
  145. // channelsWithPrefix (ln + ".", l, p).
  146. //
  147. //-----------------------------------------------------------------
  148. void layers (std::set <std::string> &layerNames) const;
  149. void channelsInLayer (const std::string &layerName,
  150. Iterator &first,
  151. Iterator &last);
  152. void channelsInLayer (const std::string &layerName,
  153. ConstIterator &first,
  154. ConstIterator &last) const;
  155. //-------------------------------------------------------------------
  156. // Find all channels whose name begins with a given prefix:
  157. //
  158. // channelsWithPrefix(p,f,l) stores a pair of iterators in f and l
  159. // such that the following loop iterates over all channels whose name
  160. // begins with string p:
  161. //
  162. // for (ConstIterator i = f; i != l; ++i)
  163. // ...
  164. //
  165. //-------------------------------------------------------------------
  166. void channelsWithPrefix (const char prefix[],
  167. Iterator &first,
  168. Iterator &last);
  169. void channelsWithPrefix (const char prefix[],
  170. ConstIterator &first,
  171. ConstIterator &last) const;
  172. //------------
  173. // Operator ==
  174. //------------
  175. bool operator == (const ChannelList &other) const;
  176. private:
  177. ChannelMap _map;
  178. };
  179. //----------
  180. // Iterators
  181. //----------
  182. class ChannelList::Iterator
  183. {
  184. public:
  185. Iterator ();
  186. Iterator (const ChannelList::ChannelMap::iterator &i);
  187. Iterator & operator ++ ();
  188. Iterator operator ++ (int);
  189. const char * name () const;
  190. Channel & channel () const;
  191. private:
  192. friend class ChannelList::ConstIterator;
  193. ChannelList::ChannelMap::iterator _i;
  194. };
  195. class ChannelList::ConstIterator
  196. {
  197. public:
  198. ConstIterator ();
  199. ConstIterator (const ChannelList::ChannelMap::const_iterator &i);
  200. ConstIterator (const ChannelList::Iterator &other);
  201. ConstIterator & operator ++ ();
  202. ConstIterator operator ++ (int);
  203. const char * name () const;
  204. const Channel & channel () const;
  205. private:
  206. friend bool operator == (const ConstIterator &, const ConstIterator &);
  207. friend bool operator != (const ConstIterator &, const ConstIterator &);
  208. ChannelList::ChannelMap::const_iterator _i;
  209. };
  210. //-----------------
  211. // Inline Functions
  212. //-----------------
  213. inline
  214. ChannelList::Iterator::Iterator (): _i()
  215. {
  216. // empty
  217. }
  218. inline
  219. ChannelList::Iterator::Iterator (const ChannelList::ChannelMap::iterator &i):
  220. _i (i)
  221. {
  222. // empty
  223. }
  224. inline ChannelList::Iterator &
  225. ChannelList::Iterator::operator ++ ()
  226. {
  227. ++_i;
  228. return *this;
  229. }
  230. inline ChannelList::Iterator
  231. ChannelList::Iterator::operator ++ (int)
  232. {
  233. Iterator tmp = *this;
  234. ++_i;
  235. return tmp;
  236. }
  237. inline const char *
  238. ChannelList::Iterator::name () const
  239. {
  240. return *_i->first;
  241. }
  242. inline Channel &
  243. ChannelList::Iterator::channel () const
  244. {
  245. return _i->second;
  246. }
  247. inline
  248. ChannelList::ConstIterator::ConstIterator (): _i()
  249. {
  250. // empty
  251. }
  252. inline
  253. ChannelList::ConstIterator::ConstIterator
  254. (const ChannelList::ChannelMap::const_iterator &i): _i (i)
  255. {
  256. // empty
  257. }
  258. inline
  259. ChannelList::ConstIterator::ConstIterator (const ChannelList::Iterator &other):
  260. _i (other._i)
  261. {
  262. // empty
  263. }
  264. inline ChannelList::ConstIterator &
  265. ChannelList::ConstIterator::operator ++ ()
  266. {
  267. ++_i;
  268. return *this;
  269. }
  270. inline ChannelList::ConstIterator
  271. ChannelList::ConstIterator::operator ++ (int)
  272. {
  273. ConstIterator tmp = *this;
  274. ++_i;
  275. return tmp;
  276. }
  277. inline const char *
  278. ChannelList::ConstIterator::name () const
  279. {
  280. return *_i->first;
  281. }
  282. inline const Channel &
  283. ChannelList::ConstIterator::channel () const
  284. {
  285. return _i->second;
  286. }
  287. inline bool
  288. operator == (const ChannelList::ConstIterator &x,
  289. const ChannelList::ConstIterator &y)
  290. {
  291. return x._i == y._i;
  292. }
  293. inline bool
  294. operator != (const ChannelList::ConstIterator &x,
  295. const ChannelList::ConstIterator &y)
  296. {
  297. return !(x == y);
  298. }
  299. } // namespace Imf
  300. #endif