ImfDeepFrameBuffer.cpp 5.1 KB

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