ImfFrameBuffer.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. //-----------------------------------------------------------------------------
  35. //
  36. // class Slice
  37. // class FrameBuffer
  38. //
  39. //-----------------------------------------------------------------------------
  40. #include <ImfFrameBuffer.h>
  41. #include "Iex.h"
  42. using namespace std;
  43. #include "ImfNamespace.h"
  44. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
  45. Slice::Slice (PixelType t,
  46. char *b,
  47. size_t xst,
  48. size_t yst,
  49. int xsm,
  50. int ysm,
  51. double fv,
  52. bool xtc,
  53. bool ytc)
  54. :
  55. type (t),
  56. base (b),
  57. xStride (xst),
  58. yStride (yst),
  59. xSampling (xsm),
  60. ySampling (ysm),
  61. fillValue (fv),
  62. xTileCoords (xtc),
  63. yTileCoords (ytc)
  64. {
  65. // empty
  66. }
  67. void
  68. FrameBuffer::insert (const char name[], const Slice &slice)
  69. {
  70. if (name[0] == 0)
  71. {
  72. THROW (IEX_NAMESPACE::ArgExc,
  73. "Frame buffer slice name cannot be an empty string.");
  74. }
  75. _map[name] = slice;
  76. }
  77. void
  78. FrameBuffer::insert (const string &name, const Slice &slice)
  79. {
  80. insert (name.c_str(), slice);
  81. }
  82. Slice &
  83. FrameBuffer::operator [] (const char name[])
  84. {
  85. SliceMap::iterator i = _map.find (name);
  86. if (i == _map.end())
  87. {
  88. THROW (IEX_NAMESPACE::ArgExc,
  89. "Cannot find frame buffer slice \"" << name << "\".");
  90. }
  91. return i->second;
  92. }
  93. const Slice &
  94. FrameBuffer::operator [] (const char name[]) const
  95. {
  96. SliceMap::const_iterator i = _map.find (name);
  97. if (i == _map.end())
  98. {
  99. THROW (IEX_NAMESPACE::ArgExc,
  100. "Cannot find frame buffer slice \"" << name << "\".");
  101. }
  102. return i->second;
  103. }
  104. Slice &
  105. FrameBuffer::operator [] (const string &name)
  106. {
  107. return this->operator[] (name.c_str());
  108. }
  109. const Slice &
  110. FrameBuffer::operator [] (const string &name) const
  111. {
  112. return this->operator[] (name.c_str());
  113. }
  114. Slice *
  115. FrameBuffer::findSlice (const char name[])
  116. {
  117. SliceMap::iterator i = _map.find (name);
  118. return (i == _map.end())? 0: &i->second;
  119. }
  120. const Slice *
  121. FrameBuffer::findSlice (const char name[]) const
  122. {
  123. SliceMap::const_iterator i = _map.find (name);
  124. return (i == _map.end())? 0: &i->second;
  125. }
  126. Slice *
  127. FrameBuffer::findSlice (const string &name)
  128. {
  129. return findSlice (name.c_str());
  130. }
  131. const Slice *
  132. FrameBuffer::findSlice (const string &name) const
  133. {
  134. return findSlice (name.c_str());
  135. }
  136. FrameBuffer::Iterator
  137. FrameBuffer::begin ()
  138. {
  139. return _map.begin();
  140. }
  141. FrameBuffer::ConstIterator
  142. FrameBuffer::begin () const
  143. {
  144. return _map.begin();
  145. }
  146. FrameBuffer::Iterator
  147. FrameBuffer::end ()
  148. {
  149. return _map.end();
  150. }
  151. FrameBuffer::ConstIterator
  152. FrameBuffer::end () const
  153. {
  154. return _map.end();
  155. }
  156. FrameBuffer::Iterator
  157. FrameBuffer::find (const char name[])
  158. {
  159. return _map.find (name);
  160. }
  161. FrameBuffer::ConstIterator
  162. FrameBuffer::find (const char name[]) const
  163. {
  164. return _map.find (name);
  165. }
  166. FrameBuffer::Iterator
  167. FrameBuffer::find (const string &name)
  168. {
  169. return find (name.c_str());
  170. }
  171. FrameBuffer::ConstIterator
  172. FrameBuffer::find (const string &name) const
  173. {
  174. return find (name.c_str());
  175. }
  176. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT