Debian Codegraph @

apps/converters/ivdowngrade/SoPackedColorV2.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1995-96 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | Classes:
44 | SoPackedColorV2
45 |
46 | Authors: David Mott
47 |
48 ______________ S I L I C O N G R A P H I C S I N C . ____________
49 _______________________________________________________________________
50 */
51
52 #include <Inventor/elements/SoLazyElement.h>
53 #include <Inventor/actions/SoWriteAction.h>
54 #include "SoPackedColorV2.h"
55
56 SO_NODE_SOURCE(SoPackedColorV2);
57
58 ////////////////////////////////////////////////////////////////////////
59 //
60 // Description:
61 // init that class!
62 //
63 void
64 SoPackedColorV2::initClass()
65 //
66 ////////////////////////////////////////////////////////////////////////
67 {
68 SO__NODE_INIT_CLASS(SoPackedColorV2, "PackedColor", SoPackedColor);
69
70 // Tell the type system whenever it wants to create something
71 // of type SoPackedColor to create a SoPackedColorV2
72 SoType::overrideType(
73 SoPackedColor::getClassTypeId(), &SoPackedColorV2::createInstance);
74 }
75
76 ////////////////////////////////////////////////////////////////////////
77 //
78 // Description:
79 // Constructor
80 //
81 SoPackedColorV2::SoPackedColorV2()
82 //
83 ////////////////////////////////////////////////////////////////////////
84 {
85 SO_NODE_CONSTRUCTOR(SoPackedColorV2);
86 SO_NODE_ADD_FIELD(rgba, (SoLazyElement::getDefaultPacked())); // 2.0 field
87
88 // This is a built in node in all versions of Inventor
89 isBuiltIn = TRUE;
90 }
91
92 ////////////////////////////////////////////////////////////////////////
93 //
94 // Description:
95 // Destructor
96 //
97 SoPackedColorV2::~SoPackedColorV2()
98 //
99 ////////////////////////////////////////////////////////////////////////
100 {
101
102 }
103
104 ////////////////////////////////////////////////////////////////////////
105 //
106 // Description:
107 // write the alternate rep for this node
108 //
109 void
110 SoPackedColorV2::write(SoWriteAction *action)
111 //
112 ////////////////////////////////////////////////////////////////////////
113 {
114 // We don't to trigger notification during writing.
115 enableNotify(FALSE);
116
117 SoOutput *out = action->getOutput();
118
119 // In write-reference counting phase
120 if (out->getStage() == SoOutput::COUNT_REFS) {
121 if (! orderedRGBA.isDefault()) {
122 // Put the RGBA values into the rgba field, reversing the byte order
123 // and write out rgba, not orderedRGBA
124 for (int i= 0; i< orderedRGBA.getNum(); i++){
125 uint32_t val = orderedRGBA[i];
126 uint32_t newval = ((val&0xff) << 24)|((val&0xff00) << 8)|
127 ((val&0xff0000) >> 8)|((val & 0xff000000)>>24);
128 rgba.set1Value(i, newval);
129 }
130
131 orderedRGBA.setDefault(TRUE);
132 }
133 }
134
135 SoPackedColor::write(action);
136 }
137