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