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

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 433 lines · 180 code · 103 blank · 150 comment · 8 complexity · ca63b0bf63f985bf76a1e453cf835f46 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. // Hint to lossy compression methods that indicates whether
  65. // human perception of the quantity represented by this channel
  66. // is closer to linear or closer to logarithmic. Compression
  67. // methods may optimize image quality by adjusting pixel data
  68. // quantization acording to this hint.
  69. // For example, perception of red, green, blue and luminance is
  70. // approximately logarithmic; the difference between 0.1 and 0.2
  71. // is perceived to be roughly the same as the difference between
  72. // 1.0 and 2.0. Perception of chroma coordinates tends to be
  73. // closer to linear than logarithmic; the difference between 0.1
  74. // and 0.2 is perceived to be roughly the same as the difference
  75. // between 1.0 and 1.1.
  76. //--------------------------------------------------------------
  77. bool pLinear;
  78. //------------
  79. // Constructor
  80. //------------
  81. Channel (PixelType type = HALF,
  82. int xSampling = 1,
  83. int ySampling = 1,
  84. bool pLinear = false);
  85. //------------
  86. // Operator ==
  87. //------------
  88. bool operator == (const Channel &other) const;
  89. };
  90. class ChannelList
  91. {
  92. public:
  93. //--------------
  94. // Add a channel
  95. //--------------
  96. void insert (const char name[],
  97. const Channel &channel);
  98. void insert (const std::string &name,
  99. const Channel &channel);
  100. //------------------------------------------------------------------
  101. // Access to existing channels:
  102. //
  103. // [n] Returns a reference to the channel with name n.
  104. // If no channel with name n exists, an Iex::ArgExc
  105. // is thrown.
  106. //
  107. // findChannel(n) Returns a pointer to the channel with name n,
  108. // or 0 if no channel with name n exists.
  109. //
  110. //------------------------------------------------------------------
  111. Channel & operator [] (const char name[]);
  112. const Channel & operator [] (const char name[]) const;
  113. Channel & operator [] (const std::string &name);
  114. const Channel & operator [] (const std::string &name) const;
  115. Channel * findChannel (const char name[]);
  116. const Channel * findChannel (const char name[]) const;
  117. Channel * findChannel (const std::string &name);
  118. const Channel * findChannel (const std::string &name) const;
  119. //-------------------------------------------
  120. // Iterator-style access to existing channels
  121. //-------------------------------------------
  122. typedef std::map <Name, Channel> ChannelMap;
  123. class Iterator;
  124. class ConstIterator;
  125. Iterator begin ();
  126. ConstIterator begin () const;
  127. Iterator end ();
  128. ConstIterator end () const;
  129. Iterator find (const char name[]);
  130. ConstIterator find (const char name[]) const;
  131. Iterator find (const std::string &name);
  132. ConstIterator find (const std::string &name) const;
  133. //-----------------------------------------------------------------
  134. // Support for image layers:
  135. //
  136. // In an image file with many channels it is sometimes useful to
  137. // group the channels into "layers", that is, into sets of channels
  138. // that logically belong together. Grouping channels into layers
  139. // is done using a naming convention: channel C in layer L is
  140. // called "L.C".
  141. //
  142. // For example, a computer graphic image may contain separate
  143. // R, G and B channels for light that originated at each of
  144. // several different virtual light sources. The channels in
  145. // this image might be called "light1.R", "light1.G", "light1.B",
  146. // "light2.R", "light2.G", "light2.B", etc.
  147. //
  148. // Note that this naming convention allows layers to be nested;
  149. // for example, "light1.specular.R" identifies the "R" channel
  150. // in the "specular" sub-layer of layer "light1".
  151. //
  152. // Channel names that don't contain a "." or that contain a
  153. // "." only at the beginning or at the end are not considered
  154. // to be part of any layer.
  155. //
  156. // layers(lns) sorts the channels in this ChannelList
  157. // into layers and stores the names of
  158. // all layers, sorted alphabetically,
  159. // into string set lns.
  160. //
  161. // channelsInLayer(ln,f,l) stores a pair of iterators in f and l
  162. // such that the loop
  163. //
  164. // for (ConstIterator i = f; i != l; ++i)
  165. // ...
  166. //
  167. // iterates over all channels in layer ln.
  168. // channelsInLayer (ln, l, p) calls
  169. // channelsWithPrefix (ln + ".", l, p).
  170. //
  171. //-----------------------------------------------------------------
  172. void layers (std::set <std::string> &layerNames) const;
  173. void channelsInLayer (const std::string &layerName,
  174. Iterator &first,
  175. Iterator &last);
  176. void channelsInLayer (const std::string &layerName,
  177. ConstIterator &first,
  178. ConstIterator &last) const;
  179. //-------------------------------------------------------------------
  180. // Find all channels whose name begins with a given prefix:
  181. //
  182. // channelsWithPrefix(p,f,l) stores a pair of iterators in f and l
  183. // such that the following loop iterates over all channels whose name
  184. // begins with string p:
  185. //
  186. // for (ConstIterator i = f; i != l; ++i)
  187. // ...
  188. //
  189. //-------------------------------------------------------------------
  190. void channelsWithPrefix (const char prefix[],
  191. Iterator &first,
  192. Iterator &last);
  193. void channelsWithPrefix (const char prefix[],
  194. ConstIterator &first,
  195. ConstIterator &last) const;
  196. void channelsWithPrefix (const std::string &prefix,
  197. Iterator &first,
  198. Iterator &last);
  199. void channelsWithPrefix (const std::string &prefix,
  200. ConstIterator &first,
  201. ConstIterator &last) const;
  202. //------------
  203. // Operator ==
  204. //------------
  205. bool operator == (const ChannelList &other) const;
  206. private:
  207. ChannelMap _map;
  208. };
  209. //----------
  210. // Iterators
  211. //----------
  212. class ChannelList::Iterator
  213. {
  214. public:
  215. Iterator ();
  216. Iterator (const ChannelList::ChannelMap::iterator &i);
  217. Iterator & operator ++ ();
  218. Iterator operator ++ (int);
  219. const char * name () const;
  220. Channel & channel () const;
  221. private:
  222. friend class ChannelList::ConstIterator;
  223. ChannelList::ChannelMap::iterator _i;
  224. };
  225. class ChannelList::ConstIterator
  226. {
  227. public:
  228. ConstIterator ();
  229. ConstIterator (const ChannelList::ChannelMap::const_iterator &i);
  230. ConstIterator (const ChannelList::Iterator &other);
  231. ConstIterator & operator ++ ();
  232. ConstIterator operator ++ (int);
  233. const char * name () const;
  234. const Channel & channel () const;
  235. private:
  236. friend bool operator == (const ConstIterator &, const ConstIterator &);
  237. friend bool operator != (const ConstIterator &, const ConstIterator &);
  238. ChannelList::ChannelMap::const_iterator _i;
  239. };
  240. //-----------------
  241. // Inline Functions
  242. //-----------------
  243. inline
  244. ChannelList::Iterator::Iterator (): _i()
  245. {
  246. // empty
  247. }
  248. inline
  249. ChannelList::Iterator::Iterator (const ChannelList::ChannelMap::iterator &i):
  250. _i (i)
  251. {
  252. // empty
  253. }
  254. inline ChannelList::Iterator &
  255. ChannelList::Iterator::operator ++ ()
  256. {
  257. ++_i;
  258. return *this;
  259. }
  260. inline ChannelList::Iterator
  261. ChannelList::Iterator::operator ++ (int)
  262. {
  263. Iterator tmp = *this;
  264. ++_i;
  265. return tmp;
  266. }
  267. inline const char *
  268. ChannelList::Iterator::name () const
  269. {
  270. return *_i->first;
  271. }
  272. inline Channel &
  273. ChannelList::Iterator::channel () const
  274. {
  275. return _i->second;
  276. }
  277. inline
  278. ChannelList::ConstIterator::ConstIterator (): _i()
  279. {
  280. // empty
  281. }
  282. inline
  283. ChannelList::ConstIterator::ConstIterator
  284. (const ChannelList::ChannelMap::const_iterator &i): _i (i)
  285. {
  286. // empty
  287. }
  288. inline
  289. ChannelList::ConstIterator::ConstIterator (const ChannelList::Iterator &other):
  290. _i (other._i)
  291. {
  292. // empty
  293. }
  294. inline ChannelList::ConstIterator &
  295. ChannelList::ConstIterator::operator ++ ()
  296. {
  297. ++_i;
  298. return *this;
  299. }
  300. inline ChannelList::ConstIterator
  301. ChannelList::ConstIterator::operator ++ (int)
  302. {
  303. ConstIterator tmp = *this;
  304. ++_i;
  305. return tmp;
  306. }
  307. inline const char *
  308. ChannelList::ConstIterator::name () const
  309. {
  310. return *_i->first;
  311. }
  312. inline const Channel &
  313. ChannelList::ConstIterator::channel () const
  314. {
  315. return _i->second;
  316. }
  317. inline bool
  318. operator == (const ChannelList::ConstIterator &x,
  319. const ChannelList::ConstIterator &y)
  320. {
  321. return x._i == y._i;
  322. }
  323. inline bool
  324. operator != (const ChannelList::ConstIterator &x,
  325. const ChannelList::ConstIterator &y)
  326. {
  327. return !(x == y);
  328. }
  329. } // namespace Imf
  330. #endif