Path: blob/master/3rdparty/openexr/IlmImf/ImfChannelList.cpp
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//-----------------------------------------------------------------------------37//38// class Channel39// class ChannelList40//41//-----------------------------------------------------------------------------4243#include <ImfChannelList.h>44#include <Iex.h>454647using std::string;48using std::set;4950namespace Imf {515253Channel::Channel (PixelType t, int xs, int ys, bool pl):54type (t),55xSampling (xs),56ySampling (ys),57pLinear (pl)58{59// empty60}616263bool64Channel::operator == (const Channel &other) const65{66return type == other.type &&67xSampling == other.xSampling &&68ySampling == other.ySampling &&69pLinear == other.pLinear;70}717273void74ChannelList::insert (const char name[], const Channel &channel)75{76if (name[0] == 0)77THROW (Iex::ArgExc, "Image channel name cannot be an empty string.");7879_map[name] = channel;80}818283void84ChannelList::insert (const string &name, const Channel &channel)85{86insert (name.c_str(), channel);87}888990Channel &91ChannelList::operator [] (const char name[])92{93ChannelMap::iterator i = _map.find (name);9495if (i == _map.end())96THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");9798return i->second;99}100101102const Channel &103ChannelList::operator [] (const char name[]) const104{105ChannelMap::const_iterator i = _map.find (name);106107if (i == _map.end())108THROW (Iex::ArgExc, "Cannot find image channel \"" << name << "\".");109110return i->second;111}112113114Channel &115ChannelList::operator [] (const string &name)116{117return this->operator[] (name.c_str());118}119120121const Channel &122ChannelList::operator [] (const string &name) const123{124return this->operator[] (name.c_str());125}126127128Channel *129ChannelList::findChannel (const char name[])130{131ChannelMap::iterator i = _map.find (name);132return (i == _map.end())? 0: &i->second;133}134135136const Channel *137ChannelList::findChannel (const char name[]) const138{139ChannelMap::const_iterator i = _map.find (name);140return (i == _map.end())? 0: &i->second;141}142143144Channel *145ChannelList::findChannel (const string &name)146{147return findChannel (name.c_str());148}149150151const Channel *152ChannelList::findChannel (const string &name) const153{154return findChannel (name.c_str());155}156157158ChannelList::Iterator159ChannelList::begin ()160{161return _map.begin();162}163164165ChannelList::ConstIterator166ChannelList::begin () const167{168return _map.begin();169}170171172ChannelList::Iterator173ChannelList::end ()174{175return _map.end();176}177178179ChannelList::ConstIterator180ChannelList::end () const181{182return _map.end();183}184185186ChannelList::Iterator187ChannelList::find (const char name[])188{189return _map.find (name);190}191192193ChannelList::ConstIterator194ChannelList::find (const char name[]) const195{196return _map.find (name);197}198199200ChannelList::Iterator201ChannelList::find (const string &name)202{203return find (name.c_str());204}205206207ChannelList::ConstIterator208ChannelList::find (const string &name) const209{210return find (name.c_str());211}212213214void215ChannelList::layers (set <string> &layerNames) const216{217layerNames.clear();218219for (ConstIterator i = begin(); i != end(); ++i)220{221string layerName = i.name();222size_t pos = layerName.rfind ('.');223224if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())225{226layerName.erase (pos);227layerNames.insert (layerName);228}229}230}231232233void234ChannelList::channelsInLayer (const string &layerName,235Iterator &first,236Iterator &last)237{238channelsWithPrefix (layerName + '.', first, last);239}240241242void243ChannelList::channelsInLayer (const string &layerName,244ConstIterator &first,245ConstIterator &last) const246{247channelsWithPrefix (layerName + '.', first, last);248}249250251void252ChannelList::channelsWithPrefix (const char prefix[],253Iterator &first,254Iterator &last)255{256first = last = _map.lower_bound (prefix);257int n = strlen (prefix);258259while (last != Iterator (_map.end()) &&260strncmp (last.name(), prefix, n) <= 0)261{262++last;263}264}265266267void268ChannelList::channelsWithPrefix (const char prefix[],269ConstIterator &first,270ConstIterator &last) const271{272first = last = _map.lower_bound (prefix);273int n = strlen (prefix);274275while (last != ConstIterator (_map.end()) &&276strncmp (last.name(), prefix, n) <= 0)277{278++last;279}280}281282283void284ChannelList::channelsWithPrefix (const string &prefix,285Iterator &first,286Iterator &last)287{288return channelsWithPrefix (prefix.c_str(), first, last);289}290291292void293ChannelList::channelsWithPrefix (const string &prefix,294ConstIterator &first,295ConstIterator &last) const296{297return channelsWithPrefix (prefix.c_str(), first, last);298}299300301bool302ChannelList::operator == (const ChannelList &other) const303{304ConstIterator i = begin();305ConstIterator j = other.begin();306307while (i != end() && j != other.end())308{309if (!(i.channel() == j.channel()))310return false;311312++i;313++j;314}315316return i == end() && j == other.end();317}318319320} // namespace Imf321322323