|
Packit |
0d464f |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
|
|
Packit |
0d464f |
// Digital Ltd. LLC
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// All rights reserved.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
0d464f |
// modification, are permitted provided that the following conditions are
|
|
Packit |
0d464f |
// met:
|
|
Packit |
0d464f |
// * Redistributions of source code must retain the above copyright
|
|
Packit |
0d464f |
// notice, this list of conditions and the following disclaimer.
|
|
Packit |
0d464f |
// * Redistributions in binary form must reproduce the above
|
|
Packit |
0d464f |
// copyright notice, this list of conditions and the following disclaimer
|
|
Packit |
0d464f |
// in the documentation and/or other materials provided with the
|
|
Packit |
0d464f |
// distribution.
|
|
Packit |
0d464f |
// * Neither the name of Industrial Light & Magic nor the names of
|
|
Packit |
0d464f |
// its contributors may be used to endorse or promote products derived
|
|
Packit |
0d464f |
// from this software without specific prior written permission.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
0d464f |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
0d464f |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit |
0d464f |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
0d464f |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
0d464f |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
0d464f |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
0d464f |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
0d464f |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
0d464f |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
0d464f |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
///////////////////////////////////////////////////////////////////////////
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------------
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// class Channel
|
|
Packit |
0d464f |
// class ChannelList
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include <ImfChannelList.h>
|
|
Packit |
0d464f |
#include <Iex.h>
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
using std::string;
|
|
Packit |
0d464f |
using std::set;
|
|
Packit |
0d464f |
#include "ImfNamespace.h"
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Channel::Channel (PixelType t, int xs, int ys, bool pl):
|
|
Packit |
0d464f |
type (t),
|
|
Packit |
0d464f |
xSampling (xs),
|
|
Packit |
0d464f |
ySampling (ys),
|
|
Packit |
0d464f |
pLinear (pl)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
// empty
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
bool
|
|
Packit |
0d464f |
Channel::operator == (const Channel &other) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return type == other.type &&
|
|
Packit |
0d464f |
xSampling == other.xSampling &&
|
|
Packit |
0d464f |
ySampling == other.ySampling &&
|
|
Packit |
0d464f |
pLinear == other.pLinear;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::insert (const char name[], const Channel &channel)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
if (name[0] == 0)
|
|
Packit |
0d464f |
THROW (IEX_NAMESPACE::ArgExc, "Image channel name cannot be an empty string.");
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
_map[name] = channel;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::insert (const string &name, const Channel &channel)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
insert (name.c_str(), channel);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Channel &
|
|
Packit |
0d464f |
ChannelList::operator [] (const char name[])
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
ChannelMap::iterator i = _map.find (name);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
if (i == _map.end())
|
|
Packit |
0d464f |
THROW (IEX_NAMESPACE::ArgExc, "Cannot find image channel \"" << name << "\".");
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
return i->second;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
const Channel &
|
|
Packit |
0d464f |
ChannelList::operator [] (const char name[]) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
ChannelMap::const_iterator i = _map.find (name);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
if (i == _map.end())
|
|
Packit |
0d464f |
THROW (IEX_NAMESPACE::ArgExc, "Cannot find image channel \"" << name << "\".");
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
return i->second;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Channel &
|
|
Packit |
0d464f |
ChannelList::operator [] (const string &name)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return this->operator[] (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
const Channel &
|
|
Packit |
0d464f |
ChannelList::operator [] (const string &name) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return this->operator[] (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Channel *
|
|
Packit |
0d464f |
ChannelList::findChannel (const char name[])
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
ChannelMap::iterator i = _map.find (name);
|
|
Packit |
0d464f |
return (i == _map.end())? 0: &i->second;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
const Channel *
|
|
Packit |
0d464f |
ChannelList::findChannel (const char name[]) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
ChannelMap::const_iterator i = _map.find (name);
|
|
Packit |
0d464f |
return (i == _map.end())? 0: &i->second;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Channel *
|
|
Packit |
0d464f |
ChannelList::findChannel (const string &name)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return findChannel (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
const Channel *
|
|
Packit |
0d464f |
ChannelList::findChannel (const string &name) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return findChannel (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::Iterator
|
|
Packit |
0d464f |
ChannelList::begin ()
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.begin();
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::ConstIterator
|
|
Packit |
0d464f |
ChannelList::begin () const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.begin();
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::Iterator
|
|
Packit |
0d464f |
ChannelList::end ()
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.end();
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::ConstIterator
|
|
Packit |
0d464f |
ChannelList::end () const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.end();
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::Iterator
|
|
Packit |
0d464f |
ChannelList::find (const char name[])
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.find (name);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::ConstIterator
|
|
Packit |
0d464f |
ChannelList::find (const char name[]) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return _map.find (name);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::Iterator
|
|
Packit |
0d464f |
ChannelList::find (const string &name)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return find (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
ChannelList::ConstIterator
|
|
Packit |
0d464f |
ChannelList::find (const string &name) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return find (name.c_str());
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::layers (set <string> &layerNames) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
layerNames.clear();
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
for (ConstIterator i = begin(); i != end(); ++i)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
string layerName = i.name();
|
|
Packit |
0d464f |
size_t pos = layerName.rfind ('.');
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
if (pos != string::npos && pos != 0 && pos + 1 < layerName.size())
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
layerName.erase (pos);
|
|
Packit |
0d464f |
layerNames.insert (layerName);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsInLayer (const string &layerName,
|
|
Packit |
0d464f |
Iterator &first,
|
|
Packit |
0d464f |
Iterator &last)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
channelsWithPrefix (layerName + '.', first, last);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsInLayer (const string &layerName,
|
|
Packit |
0d464f |
ConstIterator &first,
|
|
Packit |
0d464f |
ConstIterator &last) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
channelsWithPrefix (layerName + '.', first, last);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsWithPrefix (const char prefix[],
|
|
Packit |
0d464f |
Iterator &first,
|
|
Packit |
0d464f |
Iterator &last)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
first = last = _map.lower_bound (prefix);
|
|
Packit |
0d464f |
size_t n = int(strlen (prefix));
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
while (last != Iterator (_map.end()) &&
|
|
Packit |
0d464f |
strncmp (last.name(), prefix, n) <= 0)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
++last;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsWithPrefix (const char prefix[],
|
|
Packit |
0d464f |
ConstIterator &first,
|
|
Packit |
0d464f |
ConstIterator &last) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
first = last = _map.lower_bound (prefix);
|
|
Packit |
0d464f |
size_t n = strlen (prefix);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
while (last != ConstIterator (_map.end()) &&
|
|
Packit |
0d464f |
strncmp (last.name(), prefix, n) <= 0)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
++last;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsWithPrefix (const string &prefix,
|
|
Packit |
0d464f |
Iterator &first,
|
|
Packit |
0d464f |
Iterator &last)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return channelsWithPrefix (prefix.c_str(), first, last);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelList::channelsWithPrefix (const string &prefix,
|
|
Packit |
0d464f |
ConstIterator &first,
|
|
Packit |
0d464f |
ConstIterator &last) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return channelsWithPrefix (prefix.c_str(), first, last);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
bool
|
|
Packit |
0d464f |
ChannelList::operator == (const ChannelList &other) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
ConstIterator i = begin();
|
|
Packit |
0d464f |
ConstIterator j = other.begin();
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
while (i != end() && j != other.end())
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
if (!(i.channel() == j.channel()))
|
|
Packit |
0d464f |
return false;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
++i;
|
|
Packit |
0d464f |
++j;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
return i == end() && j == other.end();
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
|