Path: blob/master/3rdparty/openexr/IlmImf/ImfFrameBuffer.h
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////33343536#ifndef INCLUDED_IMF_FRAME_BUFFER_H37#define INCLUDED_IMF_FRAME_BUFFER_H3839//-----------------------------------------------------------------------------40//41// class Slice42// class FrameBuffer43//44//-----------------------------------------------------------------------------4546#include <ImfName.h>47#include <ImfPixelType.h>48#include <map>49#include <string>505152namespace Imf {535455//-------------------------------------------------------56// Description of a single slice of the frame buffer:57//58// Note -- terminology: as part of a file, a component of59// an image (e.g. red, green, blue, depth etc.) is called60// a "channel". As part of a frame buffer, an image61// component is called a "slice".62//-------------------------------------------------------6364struct Slice65{66//------------------------------67// Data type; see ImfPixelType.h68//------------------------------6970PixelType type;717273//---------------------------------------------------------------------74// Memory layout: The address of pixel (x, y) is75//76// base + (xp / xSampling) * xStride + (yp / ySampling) * yStride77//78// where xp and yp are computed as follows:79//80// * If we are reading or writing a scanline-based file:81//82// xp = x83// yp = y84//85// * If we are reading a tile whose upper left coorner is at (xt, yt):86//87// if xTileCoords is true then xp = x - xt, else xp = x88// if yTileCoords is true then yp = y - yt, else yp = y89//90//---------------------------------------------------------------------9192char * base;93size_t xStride;94size_t yStride;959697//--------------------------------------------98// Subsampling: pixel (x, y) is present in the99// slice only if100//101// x % xSampling == 0 && y % ySampling == 0102//103//--------------------------------------------104105int xSampling;106int ySampling;107108109//----------------------------------------------------------110// Default value, used to fill the slice when a file without111// a channel that corresponds to this slice is read.112//----------------------------------------------------------113114double fillValue;115116117//-------------------------------------------------------118// For tiled files, the xTileCoords and yTileCoords flags119// determine whether pixel addressing is performed using120// absolute coordinates or coordinates relative to a121// tile's upper left corner. (See the comment on base,122// xStride and yStride, above.)123//124// For scanline-based files these flags have no effect;125// pixel addressing is always done using absolute126// coordinates.127//-------------------------------------------------------128129bool xTileCoords;130bool yTileCoords;131132133//------------134// Constructor135//------------136137Slice (PixelType type = HALF,138char * base = 0,139size_t xStride = 0,140size_t yStride = 0,141int xSampling = 1,142int ySampling = 1,143double fillValue = 0.0,144bool xTileCoords = false,145bool yTileCoords = false);146};147148149class FrameBuffer150{151public:152153//------------154// Add a slice155//------------156157void insert (const char name[],158const Slice &slice);159160void insert (const std::string &name,161const Slice &slice);162163//----------------------------------------------------------------164// Access to existing slices:165//166// [n] Returns a reference to the slice with name n.167// If no slice with name n exists, an Iex::ArgExc168// is thrown.169//170// findSlice(n) Returns a pointer to the slice with name n,171// or 0 if no slice with name n exists.172//173//----------------------------------------------------------------174175Slice & operator [] (const char name[]);176const Slice & operator [] (const char name[]) const;177178Slice & operator [] (const std::string &name);179const Slice & operator [] (const std::string &name) const;180181Slice * findSlice (const char name[]);182const Slice * findSlice (const char name[]) const;183184Slice * findSlice (const std::string &name);185const Slice * findSlice (const std::string &name) const;186187188//-----------------------------------------189// Iterator-style access to existing slices190//-----------------------------------------191192typedef std::map <Name, Slice> SliceMap;193194class Iterator;195class ConstIterator;196197Iterator begin ();198ConstIterator begin () const;199200Iterator end ();201ConstIterator end () const;202203Iterator find (const char name[]);204ConstIterator find (const char name[]) const;205206Iterator find (const std::string &name);207ConstIterator find (const std::string &name) const;208209private:210211SliceMap _map;212};213214215//----------216// Iterators217//----------218219class FrameBuffer::Iterator220{221public:222223Iterator ();224Iterator (const FrameBuffer::SliceMap::iterator &i);225226Iterator & operator ++ ();227Iterator operator ++ (int);228229const char * name () const;230Slice & slice () const;231232private:233234friend class FrameBuffer::ConstIterator;235236FrameBuffer::SliceMap::iterator _i;237};238239240class FrameBuffer::ConstIterator241{242public:243244ConstIterator ();245ConstIterator (const FrameBuffer::SliceMap::const_iterator &i);246ConstIterator (const FrameBuffer::Iterator &other);247248ConstIterator & operator ++ ();249ConstIterator operator ++ (int);250251const char * name () const;252const Slice & slice () const;253254private:255256friend bool operator == (const ConstIterator &, const ConstIterator &);257friend bool operator != (const ConstIterator &, const ConstIterator &);258259FrameBuffer::SliceMap::const_iterator _i;260};261262263//-----------------264// Inline Functions265//-----------------266267inline268FrameBuffer::Iterator::Iterator (): _i()269{270// empty271}272273274inline275FrameBuffer::Iterator::Iterator (const FrameBuffer::SliceMap::iterator &i):276_i (i)277{278// empty279}280281282inline FrameBuffer::Iterator &283FrameBuffer::Iterator::operator ++ ()284{285++_i;286return *this;287}288289290inline FrameBuffer::Iterator291FrameBuffer::Iterator::operator ++ (int)292{293Iterator tmp = *this;294++_i;295return tmp;296}297298299inline const char *300FrameBuffer::Iterator::name () const301{302return *_i->first;303}304305306inline Slice &307FrameBuffer::Iterator::slice () const308{309return _i->second;310}311312313inline314FrameBuffer::ConstIterator::ConstIterator (): _i()315{316// empty317}318319inline320FrameBuffer::ConstIterator::ConstIterator321(const FrameBuffer::SliceMap::const_iterator &i): _i (i)322{323// empty324}325326327inline328FrameBuffer::ConstIterator::ConstIterator (const FrameBuffer::Iterator &other):329_i (other._i)330{331// empty332}333334inline FrameBuffer::ConstIterator &335FrameBuffer::ConstIterator::operator ++ ()336{337++_i;338return *this;339}340341342inline FrameBuffer::ConstIterator343FrameBuffer::ConstIterator::operator ++ (int)344{345ConstIterator tmp = *this;346++_i;347return tmp;348}349350351inline const char *352FrameBuffer::ConstIterator::name () const353{354return *_i->first;355}356357inline const Slice &358FrameBuffer::ConstIterator::slice () const359{360return _i->second;361}362363364inline bool365operator == (const FrameBuffer::ConstIterator &x,366const FrameBuffer::ConstIterator &y)367{368return x._i == y._i;369}370371372inline bool373operator != (const FrameBuffer::ConstIterator &x,374const FrameBuffer::ConstIterator &y)375{376return !(x == y);377}378379380} // namespace Imf381382#endif383384385