|
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 ChannelListAttribute
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
//-----------------------------------------------------------------------------
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
#include <ImfChannelListAttribute.h>
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
namespace {
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
template <size_t N>
|
|
Packit |
0d464f |
void checkIsNullTerminated (const char (&str)[N], const char *what)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (size_t i = 0; i < N; ++i) {
|
|
Packit |
0d464f |
if (str[i] == '\0')
|
|
Packit |
0d464f |
return;
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
std::stringstream s;
|
|
Packit |
0d464f |
s << "Invalid " << what << ": it is more than " << (N - 1)
|
|
Packit |
0d464f |
<< " characters long.";
|
|
Packit |
0d464f |
throw IEX_NAMESPACE::InputExc(s);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
} // namespace
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
template <>
|
|
Packit |
0d464f |
const char *
|
|
Packit |
0d464f |
ChannelListAttribute::staticTypeName ()
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
return "chlist";
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
template <>
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelListAttribute::writeValueTo (OStream &os, int version) const
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
for (ChannelList::ConstIterator i = _value.begin();
|
|
Packit |
0d464f |
i != _value.end();
|
|
Packit |
0d464f |
++i)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Write name
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, i.name());
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Write Channel struct
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, int (i.channel().type));
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, i.channel().pLinear);
|
|
Packit |
0d464f |
Xdr::pad <StreamIO> (os, 3);
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, i.channel().xSampling);
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, i.channel().ySampling);
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Write end of list marker
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Xdr::write <StreamIO> (os, "");
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
template <>
|
|
Packit |
0d464f |
void
|
|
Packit |
0d464f |
ChannelListAttribute::readValueFrom (IStream &is,
|
|
Packit |
0d464f |
int size,
|
|
Packit |
0d464f |
int version)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
while (true)
|
|
Packit |
0d464f |
{
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Read name; zero length name means end of channel list
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
char name[Name::SIZE];
|
|
Packit |
0d464f |
Xdr::read <StreamIO> (is,Name::MAX_LENGTH,name);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
if (name[0] == 0)
|
|
Packit |
0d464f |
break;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
checkIsNullTerminated (name, "channel name");
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
// Read Channel struct
|
|
Packit |
0d464f |
//
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
int type;
|
|
Packit |
0d464f |
bool pLinear;
|
|
Packit |
0d464f |
int xSampling;
|
|
Packit |
0d464f |
int ySampling;
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
Xdr::read <StreamIO> (is, type);
|
|
Packit |
0d464f |
Xdr::read <StreamIO> (is, pLinear);
|
|
Packit |
0d464f |
Xdr::skip <StreamIO> (is, 3);
|
|
Packit |
0d464f |
Xdr::read <StreamIO> (is, xSampling);
|
|
Packit |
0d464f |
Xdr::read <StreamIO> (is, ySampling);
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
_value.insert (name, Channel (PixelType (type),
|
|
Packit |
0d464f |
xSampling,
|
|
Packit |
0d464f |
ySampling,
|
|
Packit |
0d464f |
pLinear));
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
}
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
|
|
Packit |
0d464f |
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
|