Path: blob/master/3rdparty/openexr/IlmImf/ImfChannelList.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_CHANNEL_LIST_H37#define INCLUDED_IMF_CHANNEL_LIST_H3839//-----------------------------------------------------------------------------40//41// class Channel42// class ChannelList43//44//-----------------------------------------------------------------------------4546#include <ImfName.h>47#include <ImfPixelType.h>48#include <map>49#include <set>50#include <string>515253namespace Imf {545556struct Channel57{58//------------------------------59// Data type; see ImfPixelType.h60//------------------------------6162PixelType type;636465//--------------------------------------------66// Subsampling: pixel (x, y) is present in the67// channel only if68//69// x % xSampling == 0 && y % ySampling == 070//71//--------------------------------------------7273int xSampling;74int ySampling;757677//--------------------------------------------------------------78// Hint to lossy compression methods that indicates whether79// human perception of the quantity represented by this channel80// is closer to linear or closer to logarithmic. Compression81// methods may optimize image quality by adjusting pixel data82// quantization acording to this hint.83// For example, perception of red, green, blue and luminance is84// approximately logarithmic; the difference between 0.1 and 0.285// is perceived to be roughly the same as the difference between86// 1.0 and 2.0. Perception of chroma coordinates tends to be87// closer to linear than logarithmic; the difference between 0.188// and 0.2 is perceived to be roughly the same as the difference89// between 1.0 and 1.1.90//--------------------------------------------------------------9192bool pLinear;939495//------------96// Constructor97//------------9899Channel (PixelType type = HALF,100int xSampling = 1,101int ySampling = 1,102bool pLinear = false);103104105//------------106// Operator ==107//------------108109bool operator == (const Channel &other) const;110};111112113class ChannelList114{115public:116117//--------------118// Add a channel119//--------------120121void insert (const char name[],122const Channel &channel);123124void insert (const std::string &name,125const Channel &channel);126127//------------------------------------------------------------------128// Access to existing channels:129//130// [n] Returns a reference to the channel with name n.131// If no channel with name n exists, an Iex::ArgExc132// is thrown.133//134// findChannel(n) Returns a pointer to the channel with name n,135// or 0 if no channel with name n exists.136//137//------------------------------------------------------------------138139Channel & operator [] (const char name[]);140const Channel & operator [] (const char name[]) const;141142Channel & operator [] (const std::string &name);143const Channel & operator [] (const std::string &name) const;144145Channel * findChannel (const char name[]);146const Channel * findChannel (const char name[]) const;147148Channel * findChannel (const std::string &name);149const Channel * findChannel (const std::string &name) const;150151152//-------------------------------------------153// Iterator-style access to existing channels154//-------------------------------------------155156typedef std::map <Name, Channel> ChannelMap;157158class Iterator;159class ConstIterator;160161Iterator begin ();162ConstIterator begin () const;163164Iterator end ();165ConstIterator end () const;166167Iterator find (const char name[]);168ConstIterator find (const char name[]) const;169170Iterator find (const std::string &name);171ConstIterator find (const std::string &name) const;172173174//-----------------------------------------------------------------175// Support for image layers:176//177// In an image file with many channels it is sometimes useful to178// group the channels into "layers", that is, into sets of channels179// that logically belong together. Grouping channels into layers180// is done using a naming convention: channel C in layer L is181// called "L.C".182//183// For example, a computer graphic image may contain separate184// R, G and B channels for light that originated at each of185// several different virtual light sources. The channels in186// this image might be called "light1.R", "light1.G", "light1.B",187// "light2.R", "light2.G", "light2.B", etc.188//189// Note that this naming convention allows layers to be nested;190// for example, "light1.specular.R" identifies the "R" channel191// in the "specular" sub-layer of layer "light1".192//193// Channel names that don't contain a "." or that contain a194// "." only at the beginning or at the end are not considered195// to be part of any layer.196//197// layers(lns) sorts the channels in this ChannelList198// into layers and stores the names of199// all layers, sorted alphabetically,200// into string set lns.201//202// channelsInLayer(ln,f,l) stores a pair of iterators in f and l203// such that the loop204//205// for (ConstIterator i = f; i != l; ++i)206// ...207//208// iterates over all channels in layer ln.209// channelsInLayer (ln, l, p) calls210// channelsWithPrefix (ln + ".", l, p).211//212//-----------------------------------------------------------------213214void layers (std::set <std::string> &layerNames) const;215216void channelsInLayer (const std::string &layerName,217Iterator &first,218Iterator &last);219220void channelsInLayer (const std::string &layerName,221ConstIterator &first,222ConstIterator &last) const;223224225//-------------------------------------------------------------------226// Find all channels whose name begins with a given prefix:227//228// channelsWithPrefix(p,f,l) stores a pair of iterators in f and l229// such that the following loop iterates over all channels whose name230// begins with string p:231//232// for (ConstIterator i = f; i != l; ++i)233// ...234//235//-------------------------------------------------------------------236237void channelsWithPrefix (const char prefix[],238Iterator &first,239Iterator &last);240241void channelsWithPrefix (const char prefix[],242ConstIterator &first,243ConstIterator &last) const;244245void channelsWithPrefix (const std::string &prefix,246Iterator &first,247Iterator &last);248249void channelsWithPrefix (const std::string &prefix,250ConstIterator &first,251ConstIterator &last) const;252253//------------254// Operator ==255//------------256257bool operator == (const ChannelList &other) const;258259private:260261ChannelMap _map;262};263264265//----------266// Iterators267//----------268269class ChannelList::Iterator270{271public:272273Iterator ();274Iterator (const ChannelList::ChannelMap::iterator &i);275276Iterator & operator ++ ();277Iterator operator ++ (int);278279const char * name () const;280Channel & channel () const;281282private:283284friend class ChannelList::ConstIterator;285286ChannelList::ChannelMap::iterator _i;287};288289290class ChannelList::ConstIterator291{292public:293294ConstIterator ();295ConstIterator (const ChannelList::ChannelMap::const_iterator &i);296ConstIterator (const ChannelList::Iterator &other);297298ConstIterator & operator ++ ();299ConstIterator operator ++ (int);300301const char * name () const;302const Channel & channel () const;303304private:305306friend bool operator == (const ConstIterator &, const ConstIterator &);307friend bool operator != (const ConstIterator &, const ConstIterator &);308309ChannelList::ChannelMap::const_iterator _i;310};311312313//-----------------314// Inline Functions315//-----------------316317inline318ChannelList::Iterator::Iterator (): _i()319{320// empty321}322323324inline325ChannelList::Iterator::Iterator (const ChannelList::ChannelMap::iterator &i):326_i (i)327{328// empty329}330331332inline ChannelList::Iterator &333ChannelList::Iterator::operator ++ ()334{335++_i;336return *this;337}338339340inline ChannelList::Iterator341ChannelList::Iterator::operator ++ (int)342{343Iterator tmp = *this;344++_i;345return tmp;346}347348349inline const char *350ChannelList::Iterator::name () const351{352return *_i->first;353}354355356inline Channel &357ChannelList::Iterator::channel () const358{359return _i->second;360}361362363inline364ChannelList::ConstIterator::ConstIterator (): _i()365{366// empty367}368369inline370ChannelList::ConstIterator::ConstIterator371(const ChannelList::ChannelMap::const_iterator &i): _i (i)372{373// empty374}375376377inline378ChannelList::ConstIterator::ConstIterator (const ChannelList::Iterator &other):379_i (other._i)380{381// empty382}383384inline ChannelList::ConstIterator &385ChannelList::ConstIterator::operator ++ ()386{387++_i;388return *this;389}390391392inline ChannelList::ConstIterator393ChannelList::ConstIterator::operator ++ (int)394{395ConstIterator tmp = *this;396++_i;397return tmp;398}399400401inline const char *402ChannelList::ConstIterator::name () const403{404return *_i->first;405}406407inline const Channel &408ChannelList::ConstIterator::channel () const409{410return _i->second;411}412413414inline bool415operator == (const ChannelList::ConstIterator &x,416const ChannelList::ConstIterator &y)417{418return x._i == y._i;419}420421422inline bool423operator != (const ChannelList::ConstIterator &x,424const ChannelList::ConstIterator &y)425{426return !(x == y);427}428429430} // namespace Imf431432#endif433434435