/src/freeimage-svn/FreeImage/trunk/Source/OpenEXR/IlmImf/ImfFrameBuffer.cpp
Line  | Count  | Source  | 
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  |  |  | 
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  | 0  |     type (t),  | 
65  | 0  |     base (b),  | 
66  | 0  |     xStride (xst),  | 
67  | 0  |     yStride (yst),  | 
68  | 0  |     xSampling (xsm),  | 
69  | 0  |     ySampling (ysm),  | 
70  | 0  |     fillValue (fv),  | 
71  | 0  |     xTileCoords (xtc),  | 
72  | 0  |     yTileCoords (ytc)  | 
73  | 0  | { | 
74  |  |     // empty  | 
75  | 0  | }  | 
76  |  |  | 
77  |  |  | 
78  |  | void  | 
79  |  | FrameBuffer::insert (const char name[], const Slice &slice)  | 
80  | 0  | { | 
81  | 0  |     if (name[0] == 0)  | 
82  | 0  |     { | 
83  | 0  |         THROW (IEX_NAMESPACE::ArgExc,  | 
84  | 0  |                "Frame buffer slice name cannot be an empty string.");  | 
85  | 0  |     }  | 
86  |  |  | 
87  | 0  |     _map[name] = slice;  | 
88  | 0  | }  | 
89  |  |  | 
90  |  |  | 
91  |  | void  | 
92  |  | FrameBuffer::insert (const string &name, const Slice &slice)  | 
93  | 0  | { | 
94  | 0  |     insert (name.c_str(), slice);  | 
95  | 0  | }  | 
96  |  |  | 
97  |  |  | 
98  |  | Slice &  | 
99  |  | FrameBuffer::operator [] (const char name[])  | 
100  | 0  | { | 
101  | 0  |     SliceMap::iterator i = _map.find (name);  | 
102  |  | 
  | 
103  | 0  |     if (i == _map.end())  | 
104  | 0  |     { | 
105  | 0  |         THROW (IEX_NAMESPACE::ArgExc,  | 
106  | 0  |                "Cannot find frame buffer slice \"" << name << "\".");  | 
107  | 0  |     }  | 
108  |  |  | 
109  | 0  |     return i->second;  | 
110  | 0  | }  | 
111  |  |  | 
112  |  |  | 
113  |  | const Slice &  | 
114  |  | FrameBuffer::operator [] (const char name[]) const  | 
115  | 0  | { | 
116  | 0  |     SliceMap::const_iterator i = _map.find (name);  | 
117  |  | 
  | 
118  | 0  |     if (i == _map.end())  | 
119  | 0  |     { | 
120  | 0  |         THROW (IEX_NAMESPACE::ArgExc,  | 
121  | 0  |                "Cannot find frame buffer slice \"" << name << "\".");  | 
122  | 0  |     }  | 
123  |  |  | 
124  | 0  |     return i->second;  | 
125  | 0  | }  | 
126  |  |  | 
127  |  |  | 
128  |  | Slice &  | 
129  |  | FrameBuffer::operator [] (const string &name)  | 
130  | 0  | { | 
131  | 0  |     return this->operator[] (name.c_str());  | 
132  | 0  | }  | 
133  |  |  | 
134  |  |  | 
135  |  | const Slice &  | 
136  |  | FrameBuffer::operator [] (const string &name) const  | 
137  | 0  | { | 
138  | 0  |     return this->operator[] (name.c_str());  | 
139  | 0  | }  | 
140  |  |  | 
141  |  |  | 
142  |  | Slice *  | 
143  |  | FrameBuffer::findSlice (const char name[])  | 
144  | 0  | { | 
145  | 0  |     SliceMap::iterator i = _map.find (name);  | 
146  | 0  |     return (i == _map.end())? 0: &i->second;  | 
147  | 0  | }  | 
148  |  |  | 
149  |  |  | 
150  |  | const Slice *  | 
151  |  | FrameBuffer::findSlice (const char name[]) const  | 
152  | 0  | { | 
153  | 0  |     SliceMap::const_iterator i = _map.find (name);  | 
154  | 0  |     return (i == _map.end())? 0: &i->second;  | 
155  | 0  | }  | 
156  |  |  | 
157  |  |  | 
158  |  | Slice *  | 
159  |  | FrameBuffer::findSlice (const string &name)  | 
160  | 0  | { | 
161  | 0  |     return findSlice (name.c_str());  | 
162  | 0  | }  | 
163  |  |  | 
164  |  |  | 
165  |  | const Slice *  | 
166  |  | FrameBuffer::findSlice (const string &name) const  | 
167  | 0  | { | 
168  | 0  |     return findSlice (name.c_str());  | 
169  | 0  | }  | 
170  |  |  | 
171  |  |  | 
172  |  | FrameBuffer::Iterator  | 
173  |  | FrameBuffer::begin ()  | 
174  | 0  | { | 
175  | 0  |     return _map.begin();  | 
176  | 0  | }  | 
177  |  |  | 
178  |  |  | 
179  |  | FrameBuffer::ConstIterator  | 
180  |  | FrameBuffer::begin () const  | 
181  | 0  | { | 
182  | 0  |     return _map.begin();  | 
183  | 0  | }  | 
184  |  |  | 
185  |  |  | 
186  |  | FrameBuffer::Iterator  | 
187  |  | FrameBuffer::end ()  | 
188  | 0  | { | 
189  | 0  |     return _map.end();  | 
190  | 0  | }  | 
191  |  |  | 
192  |  |  | 
193  |  | FrameBuffer::ConstIterator  | 
194  |  | FrameBuffer::end () const  | 
195  | 0  | { | 
196  | 0  |     return _map.end();  | 
197  | 0  | }  | 
198  |  |  | 
199  |  |  | 
200  |  | FrameBuffer::Iterator  | 
201  |  | FrameBuffer::find (const char name[])  | 
202  | 0  | { | 
203  | 0  |     return _map.find (name);  | 
204  | 0  | }  | 
205  |  |  | 
206  |  |  | 
207  |  | FrameBuffer::ConstIterator  | 
208  |  | FrameBuffer::find (const char name[]) const  | 
209  | 0  | { | 
210  | 0  |     return _map.find (name);  | 
211  | 0  | }  | 
212  |  |  | 
213  |  |  | 
214  |  | FrameBuffer::Iterator  | 
215  |  | FrameBuffer::find (const string &name)  | 
216  | 0  | { | 
217  | 0  |     return find (name.c_str());  | 
218  | 0  | }  | 
219  |  |  | 
220  |  |  | 
221  |  | FrameBuffer::ConstIterator  | 
222  |  | FrameBuffer::find (const string &name) const  | 
223  | 0  | { | 
224  | 0  |     return find (name.c_str());  | 
225  | 0  | }  | 
226  |  |  | 
227  |  |  | 
228  |  | OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT  |