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 
35 #include "ImfDeepFrameBuffer.h"
36 #include "Iex.h"
37 
38 
39 using namespace std;
40 #include "ImfNamespace.h"
41 
42 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
43 
DeepSlice(PixelType t,char * b,size_t xst,size_t yst,size_t spst,int xsm,int ysm,double fv,bool xtc,bool ytc)44 DeepSlice::DeepSlice (PixelType t,
45                       char *b,
46                       size_t xst,
47                       size_t yst,
48                       size_t spst,
49                       int xsm,
50                       int ysm,
51                       double fv,
52                       bool xtc,
53                       bool ytc)
54 :
55     Slice (t, b, xst, yst, xsm, ysm, fv, xtc, ytc),
56     sampleStride (spst)
57 {
58     // empty
59 }
60 
61 
62 void
insert(const char name[],const DeepSlice & slice)63 DeepFrameBuffer::insert (const char name[], const DeepSlice &slice)
64 {
65     if (name[0] == 0)
66     {
67         THROW (IEX_NAMESPACE::ArgExc,
68                "Frame buffer slice name cannot be an empty string.");
69     }
70 
71     _map[name] = slice;
72 }
73 
74 
75 void
insert(const string & name,const DeepSlice & slice)76 DeepFrameBuffer::insert (const string &name, const DeepSlice &slice)
77 {
78     insert (name.c_str(), slice);
79 }
80 
81 
82 DeepSlice &
operator [](const char name[])83 DeepFrameBuffer::operator [] (const char name[])
84 {
85     SliceMap::iterator i = _map.find (name);
86 
87     if (i == _map.end())
88     {
89         THROW (IEX_NAMESPACE::ArgExc,
90                "Cannot find frame buffer slice \"" << name << "\".");
91     }
92 
93     return i->second;
94 }
95 
96 
97 const DeepSlice &
operator [](const char name[]) const98 DeepFrameBuffer::operator [] (const char name[]) const
99 {
100     SliceMap::const_iterator i = _map.find (name);
101 
102     if (i == _map.end())
103     {
104         THROW (IEX_NAMESPACE::ArgExc,
105                "Cannot find frame buffer slice \"" << name << "\".");
106     }
107 
108     return i->second;
109 }
110 
111 
112 DeepSlice &
operator [](const string & name)113 DeepFrameBuffer::operator [] (const string &name)
114 {
115     return this->operator[] (name.c_str());
116 }
117 
118 
119 const DeepSlice &
operator [](const string & name) const120 DeepFrameBuffer::operator [] (const string &name) const
121 {
122     return this->operator[] (name.c_str());
123 }
124 
125 
126 DeepSlice *
findSlice(const char name[])127 DeepFrameBuffer::findSlice (const char name[])
128 {
129     SliceMap::iterator i = _map.find (name);
130     return (i == _map.end())? 0: &i->second;
131 }
132 
133 
134 const DeepSlice *
findSlice(const char name[]) const135 DeepFrameBuffer::findSlice (const char name[]) const
136 {
137     SliceMap::const_iterator i = _map.find (name);
138     return (i == _map.end())? 0: &i->second;
139 }
140 
141 
142 DeepSlice *
findSlice(const string & name)143 DeepFrameBuffer::findSlice (const string &name)
144 {
145     return findSlice (name.c_str());
146 }
147 
148 
149 const DeepSlice *
findSlice(const string & name) const150 DeepFrameBuffer::findSlice (const string &name) const
151 {
152     return findSlice (name.c_str());
153 }
154 
155 
156 DeepFrameBuffer::Iterator
begin()157 DeepFrameBuffer::begin ()
158 {
159     return _map.begin();
160 }
161 
162 
163 DeepFrameBuffer::ConstIterator
begin() const164 DeepFrameBuffer::begin () const
165 {
166     return _map.begin();
167 }
168 
169 
170 DeepFrameBuffer::Iterator
end()171 DeepFrameBuffer::end ()
172 {
173     return _map.end();
174 }
175 
176 
177 DeepFrameBuffer::ConstIterator
end() const178 DeepFrameBuffer::end () const
179 {
180     return _map.end();
181 }
182 
183 
184 DeepFrameBuffer::Iterator
find(const char name[])185 DeepFrameBuffer::find (const char name[])
186 {
187     return _map.find (name);
188 }
189 
190 
191 DeepFrameBuffer::ConstIterator
find(const char name[]) const192 DeepFrameBuffer::find (const char name[]) const
193 {
194     return _map.find (name);
195 }
196 
197 
198 DeepFrameBuffer::Iterator
find(const string & name)199 DeepFrameBuffer::find (const string &name)
200 {
201     return find (name.c_str());
202 }
203 
204 
205 DeepFrameBuffer::ConstIterator
find(const string & name) const206 DeepFrameBuffer::find (const string &name) const
207 {
208     return find (name.c_str());
209 }
210 
211 
212 void
insertSampleCountSlice(const Slice & slice)213 DeepFrameBuffer::insertSampleCountSlice(const Slice & slice)
214 {
215     if (slice.type != UINT)
216     {
217         throw IEX_NAMESPACE::ArgExc("The type of sample count slice should be UINT.");
218     }
219 
220     _sampleCounts = slice;
221 }
222 
223 
224 const Slice &
getSampleCountSlice() const225 DeepFrameBuffer::getSampleCountSlice() const
226 {
227     return _sampleCounts;
228 }
229 
230 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
231