1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
4// Digital Ltd. LLC
5//
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11// *       Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// *       Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following disclaimer
15// in the documentation and/or other materials provided with the
16// distribution.
17// *       Neither the name of Industrial Light & Magic nor the names of
18// its contributors may be used to endorse or promote products derived
19// from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33///////////////////////////////////////////////////////////////////////////
34
35
36
37//-----------------------------------------------------------------------------
38//
39//	class ChannelListAttribute
40//
41//-----------------------------------------------------------------------------
42
43#include <ImfChannelListAttribute.h>
44
45
46namespace Imf {
47
48
49template <>
50const char *
51ChannelListAttribute::staticTypeName ()
52{
53    return "chlist";
54}
55
56
57template <>
58void
59ChannelListAttribute::writeValueTo (OStream &os, int version) const
60{
61    for (ChannelList::ConstIterator i = _value.begin();
62	 i != _value.end();
63	 ++i)
64    {
65	//
66	// Write name
67	//
68
69	Xdr::write <StreamIO> (os, i.name());
70
71	//
72	// Write Channel struct
73	//
74
75	Xdr::write <StreamIO> (os, int (i.channel().type));
76	Xdr::write <StreamIO> (os, i.channel().pLinear);
77	Xdr::pad   <StreamIO> (os, 3);
78	Xdr::write <StreamIO> (os, i.channel().xSampling);
79	Xdr::write <StreamIO> (os, i.channel().ySampling);
80    }
81
82    //
83    // Write end of list marker
84    //
85
86    Xdr::write <StreamIO> (os, "");
87}
88
89
90template <>
91void
92ChannelListAttribute::readValueFrom (IStream &is, int size, int version)
93{
94    while (true)
95    {
96	//
97	// Read name; zero length name means end of channel list
98	//
99
100	char name[Name::SIZE];
101	Xdr::read <StreamIO> (is, sizeof (name), name);
102
103	if (name[0] == 0)
104	    break;
105
106	//
107	// Read Channel struct
108	//
109
110	int type;
111	bool pLinear;
112	int xSampling;
113	int ySampling;
114
115	Xdr::read <StreamIO> (is, type);
116	Xdr::read <StreamIO> (is, pLinear);
117	Xdr::skip <StreamIO> (is, 3);
118	Xdr::read <StreamIO> (is, xSampling);
119	Xdr::read <StreamIO> (is, ySampling);
120
121	_value.insert
122	    (name, Channel (PixelType (type), xSampling, ySampling, pLinear));
123    }
124}
125
126
127} // namespace Imf
128