1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 /*!
34   \class SoPackedColorV20 SoPackedColorV20.h
35   \brief The SoPackedColorV20 class is a node is for Inventor V2.0 support only.
36 
37   \ingroup nodes
38 
39   \sa SoPackedColor
40 */
41 
42 #include "upgraders/SoPackedColorV20.h"
43 
44 #include <Inventor/nodes/SoPackedColor.h>
45 
46 #include "nodes/SoSubNodeP.h"
47 
48 /*!
49   \var SoMFUInt32 SoPackedColorV20::rgba
50 
51   Set of packed 32-bit RGBA vectors.
52 
53   The most significant 8 bits specifies the transparency value, where
54   0x00 means completely transparent, and 0xff completely opaque.
55 
56   The least significant 24 bits specifies 8 bits each for the blue,
57   green and red components.
58 */
59 
60 // *************************************************************************
61 
62 SO_NODE_SOURCE(SoPackedColorV20);
63 
64 /*!
65   Constructor.
66 */
SoPackedColorV20()67 SoPackedColorV20::SoPackedColorV20()
68 {
69   SO_NODE_INTERNAL_CONSTRUCTOR(SoPackedColorV20);
70 
71   SO_NODE_ADD_FIELD(rgba, (0xffcccccc));
72 }
73 
74 /*!
75   Destructor.
76 */
~SoPackedColorV20()77 SoPackedColorV20::~SoPackedColorV20()
78 {
79 }
80 
81 // Doc from superclass.
82 void
initClass(void)83 SoPackedColorV20::initClass(void)
84 {
85   SO_NODE_INTERNAL_INIT_CLASS(SoPackedColorV20, SoNode::INVENTOR_2_0|SoNode::INVENTOR_1);
86 }
87 
88 SoPackedColor *
createUpgrade(void) const89 SoPackedColorV20::createUpgrade(void) const
90 {
91   SoPackedColor * pp = new SoPackedColor;
92   pp->ref();
93 
94   const int n = this->rgba.getNum();
95   const uint32_t * src = this->rgba.getValues(0);
96   pp->orderedRGBA.setNum(n);
97   uint32_t * dst = pp->orderedRGBA.startEditing();
98   for (int i = 0; i < n; i++) {
99     uint32_t val = src[i];
100     dst[i] = (val<<24)|((val<<8)&0xff0000)|((val>>8)&0xff00)|(val>>24);
101   }
102   pp->orderedRGBA.finishEditing();
103 
104   pp->unrefNoDelete();
105   return pp;
106 }
107