[855] | 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 | #ifndef INCLUDED_IMF_FRAME_BUFFER_H |
---|
| 38 | #define INCLUDED_IMF_FRAME_BUFFER_H |
---|
| 39 | |
---|
| 40 | //----------------------------------------------------------------------------- |
---|
| 41 | // |
---|
| 42 | // class Slice |
---|
| 43 | // class FrameBuffer |
---|
| 44 | // |
---|
| 45 | //----------------------------------------------------------------------------- |
---|
| 46 | |
---|
| 47 | #include <ImfName.h> |
---|
| 48 | #include <ImfPixelType.h> |
---|
| 49 | #include <map> |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | namespace Imf { |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | //------------------------------------------------------- |
---|
| 56 | // Description of a single slice of the frame buffer: |
---|
| 57 | // |
---|
| 58 | // Note -- terminology: as part of a file, a component of |
---|
| 59 | // an image (e.g. red, green, blue, depth etc.) is called |
---|
| 60 | // a "channel". As part of a frame buffer, an image |
---|
| 61 | // component is called a "slice". |
---|
| 62 | //------------------------------------------------------- |
---|
| 63 | |
---|
| 64 | struct Slice |
---|
| 65 | { |
---|
| 66 | //------------------------------ |
---|
| 67 | // Data type; see ImfPixelType.h |
---|
| 68 | //------------------------------ |
---|
| 69 | |
---|
| 70 | PixelType type; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | //-------------------------------------------------------------- |
---|
| 74 | // Memory layout: The address of pixel (x, y) is |
---|
| 75 | // |
---|
| 76 | // base + (x / xSampling) * xStride + (y / ySampling) * yStride |
---|
| 77 | // |
---|
| 78 | //-------------------------------------------------------------- |
---|
| 79 | |
---|
| 80 | char * base; |
---|
| 81 | size_t xStride; |
---|
| 82 | size_t yStride; |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | //-------------------------------------------- |
---|
| 86 | // Subsampling: pixel (x, y) is present in the |
---|
| 87 | // slice only if |
---|
| 88 | // |
---|
| 89 | // x % xSampling == 0 && y % ySampling == 0 |
---|
| 90 | // |
---|
| 91 | //-------------------------------------------- |
---|
| 92 | |
---|
| 93 | int xSampling; |
---|
| 94 | int ySampling; |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | //---------------------------------------------------------- |
---|
| 98 | // Default value, used to fill the slice when a file without |
---|
| 99 | // a channel that corresponds to this slice is read. |
---|
| 100 | //---------------------------------------------------------- |
---|
| 101 | |
---|
| 102 | double fillValue; |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | //------------ |
---|
| 106 | // Constructor |
---|
| 107 | //------------ |
---|
| 108 | |
---|
| 109 | Slice (PixelType type = HALF, |
---|
| 110 | char * base = 0, |
---|
| 111 | size_t xStride = 0, |
---|
| 112 | size_t yStride = 0, |
---|
| 113 | int xSampling = 1, |
---|
| 114 | int ySampling = 1, |
---|
| 115 | double fillValue = 0.0); |
---|
| 116 | }; |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | class FrameBuffer |
---|
| 120 | { |
---|
| 121 | public: |
---|
| 122 | |
---|
| 123 | //------------ |
---|
| 124 | // Add a slice |
---|
| 125 | //------------ |
---|
| 126 | |
---|
| 127 | void insert (const char name[], |
---|
| 128 | const Slice &slice); |
---|
| 129 | |
---|
| 130 | //---------------------------------------------------------------- |
---|
| 131 | // Access to existing slices: |
---|
| 132 | // |
---|
| 133 | // [n] Returns a reference to the slice with name n. |
---|
| 134 | // If no slice with name n exists, an Iex::ArgExc |
---|
| 135 | // is thrown. |
---|
| 136 | // |
---|
| 137 | // findSlice(n) Returns a pointer to the slice with name n, |
---|
| 138 | // or 0 if no slice with name n exists. |
---|
| 139 | // |
---|
| 140 | //---------------------------------------------------------------- |
---|
| 141 | |
---|
| 142 | Slice & operator [] (const char name[]); |
---|
| 143 | const Slice & operator [] (const char name[]) const; |
---|
| 144 | |
---|
| 145 | Slice * findSlice (const char name[]); |
---|
| 146 | const Slice * findSlice (const char name[]) const; |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | //----------------------------------------- |
---|
| 150 | // Iterator-style access to existing slices |
---|
| 151 | //----------------------------------------- |
---|
| 152 | |
---|
| 153 | typedef std::map <Name, Slice> SliceMap; |
---|
| 154 | |
---|
| 155 | class Iterator; |
---|
| 156 | class ConstIterator; |
---|
| 157 | |
---|
| 158 | Iterator begin (); |
---|
| 159 | ConstIterator begin () const; |
---|
| 160 | Iterator end (); |
---|
| 161 | ConstIterator end () const; |
---|
| 162 | Iterator find (const char name[]); |
---|
| 163 | ConstIterator find (const char name[]) const; |
---|
| 164 | |
---|
| 165 | private: |
---|
| 166 | |
---|
| 167 | SliceMap _map; |
---|
| 168 | }; |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | //---------- |
---|
| 172 | // Iterators |
---|
| 173 | //---------- |
---|
| 174 | |
---|
| 175 | class FrameBuffer::Iterator |
---|
| 176 | { |
---|
| 177 | public: |
---|
| 178 | |
---|
| 179 | Iterator (); |
---|
| 180 | Iterator (const FrameBuffer::SliceMap::iterator &i); |
---|
| 181 | |
---|
| 182 | Iterator & operator ++ (); |
---|
| 183 | Iterator operator ++ (int); |
---|
| 184 | |
---|
| 185 | const char * name () const; |
---|
| 186 | Slice & slice () const; |
---|
| 187 | |
---|
| 188 | private: |
---|
| 189 | |
---|
| 190 | friend class FrameBuffer::ConstIterator; |
---|
| 191 | |
---|
| 192 | FrameBuffer::SliceMap::iterator _i; |
---|
| 193 | }; |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | class FrameBuffer::ConstIterator |
---|
| 197 | { |
---|
| 198 | public: |
---|
| 199 | |
---|
| 200 | ConstIterator (); |
---|
| 201 | ConstIterator (const FrameBuffer::SliceMap::const_iterator &i); |
---|
| 202 | ConstIterator (const FrameBuffer::Iterator &other); |
---|
| 203 | |
---|
| 204 | ConstIterator & operator ++ (); |
---|
| 205 | ConstIterator operator ++ (int); |
---|
| 206 | |
---|
| 207 | const char * name () const; |
---|
| 208 | const Slice & slice () const; |
---|
| 209 | |
---|
| 210 | private: |
---|
| 211 | |
---|
| 212 | friend bool operator == (const ConstIterator &, const ConstIterator &); |
---|
| 213 | friend bool operator != (const ConstIterator &, const ConstIterator &); |
---|
| 214 | |
---|
| 215 | FrameBuffer::SliceMap::const_iterator _i; |
---|
| 216 | }; |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | //----------------- |
---|
| 220 | // Inline Functions |
---|
| 221 | //----------------- |
---|
| 222 | |
---|
| 223 | inline |
---|
| 224 | FrameBuffer::Iterator::Iterator (): _i() |
---|
| 225 | { |
---|
| 226 | // empty |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | inline |
---|
| 231 | FrameBuffer::Iterator::Iterator (const FrameBuffer::SliceMap::iterator &i): |
---|
| 232 | _i (i) |
---|
| 233 | { |
---|
| 234 | // empty |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | inline FrameBuffer::Iterator & |
---|
| 239 | FrameBuffer::Iterator::operator ++ () |
---|
| 240 | { |
---|
| 241 | ++_i; |
---|
| 242 | return *this; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | inline FrameBuffer::Iterator |
---|
| 247 | FrameBuffer::Iterator::operator ++ (int) |
---|
| 248 | { |
---|
| 249 | Iterator tmp = *this; |
---|
| 250 | ++_i; |
---|
| 251 | return tmp; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | inline const char * |
---|
| 256 | FrameBuffer::Iterator::name () const |
---|
| 257 | { |
---|
| 258 | return *_i->first; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | inline Slice & |
---|
| 263 | FrameBuffer::Iterator::slice () const |
---|
| 264 | { |
---|
| 265 | return _i->second; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | inline |
---|
| 270 | FrameBuffer::ConstIterator::ConstIterator (): _i() |
---|
| 271 | { |
---|
| 272 | // empty |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | inline |
---|
| 276 | FrameBuffer::ConstIterator::ConstIterator |
---|
| 277 | (const FrameBuffer::SliceMap::const_iterator &i): _i (i) |
---|
| 278 | { |
---|
| 279 | // empty |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | inline |
---|
| 284 | FrameBuffer::ConstIterator::ConstIterator (const FrameBuffer::Iterator &other): |
---|
| 285 | _i (other._i) |
---|
| 286 | { |
---|
| 287 | // empty |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | inline FrameBuffer::ConstIterator & |
---|
| 291 | FrameBuffer::ConstIterator::operator ++ () |
---|
| 292 | { |
---|
| 293 | ++_i; |
---|
| 294 | return *this; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | inline FrameBuffer::ConstIterator |
---|
| 299 | FrameBuffer::ConstIterator::operator ++ (int) |
---|
| 300 | { |
---|
| 301 | ConstIterator tmp = *this; |
---|
| 302 | ++_i; |
---|
| 303 | return tmp; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | |
---|
| 307 | inline const char * |
---|
| 308 | FrameBuffer::ConstIterator::name () const |
---|
| 309 | { |
---|
| 310 | return *_i->first; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | inline const Slice & |
---|
| 314 | FrameBuffer::ConstIterator::slice () const |
---|
| 315 | { |
---|
| 316 | return _i->second; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | inline bool |
---|
| 321 | operator == (const FrameBuffer::ConstIterator &x, |
---|
| 322 | const FrameBuffer::ConstIterator &y) |
---|
| 323 | { |
---|
| 324 | return x._i == y._i; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | |
---|
| 328 | inline bool |
---|
| 329 | operator != (const FrameBuffer::ConstIterator &x, |
---|
| 330 | const FrameBuffer::ConstIterator &y) |
---|
| 331 | { |
---|
| 332 | return !(x == y); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | } // namespace Imf |
---|
| 337 | |
---|
| 338 | #endif |
---|