source: OGRE/trunk/ogrenew/OgreMain/src/OgreColourValue.cpp @ 657

Revision 657, 5.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreColourValue.h"
27
28namespace Ogre {
29
30    ColourValue ColourValue::Black = ColourValue(0.0,0.0,0.0);
31    ColourValue ColourValue::White = ColourValue(1.0,1.0,1.0);
32    ColourValue ColourValue::Red = ColourValue(1.0,0.0,0.0);
33    ColourValue ColourValue::Green = ColourValue(0.0,1.0,0.0);
34    ColourValue ColourValue::Blue = ColourValue(0.0,0.0,1.0);
35
36    //---------------------------------------------------------------------
37    RGBA ColourValue::getAsRGBA(void) const
38    {
39        uint8 val8;
40        uint32 val32 = 0;
41
42        // Convert to 32bit pattern
43        // (RGBA = 8888)
44
45        // Red
46        val8 = static_cast<uint8>(r * 255);
47        val32 = val8 << 24;
48
49        // Green
50        val8 = static_cast<uint8>(g * 255);
51        val32 += val8 << 16;
52
53        // Blue
54        val8 = static_cast<uint8>(b * 255);
55        val32 += val8 << 8;
56
57        // Alpha
58        val8 = static_cast<uint8>(a * 255);
59        val32 += val8;
60
61        return val32;
62    }
63    //---------------------------------------------------------------------
64    ARGB ColourValue::getAsARGB(void) const
65    {
66        uint8 val8;
67        uint32 val32 = 0;
68
69        // Convert to 32bit pattern
70        // (ARGB = 8888)
71
72        // Alpha
73        val8 = static_cast<uint8>(a * 255);
74        val32 = val8 << 24;
75
76        // Red
77        val8 = static_cast<uint8>(r * 255);
78        val32 += val8 << 16;
79
80        // Green
81        val8 = static_cast<uint8>(g * 255);
82        val32 += val8 << 8;
83
84        // Blue
85        val8 = static_cast<uint8>(b * 255);
86        val32 += val8;
87
88
89        return val32;
90    }
91    //---------------------------------------------------------------------
92    ABGR ColourValue::getAsABGR(void) const
93    {
94        uint8 val8;
95        uint32 val32 = 0;
96
97        // Convert to 32bit pattern
98        // (ABRG = 8888)
99
100        // Alpha
101        val8 = static_cast<uint8>(a * 255);
102        val32 = val8 << 24;
103
104        // Blue
105        val8 = static_cast<uint8>(b * 255);
106        val32 += val8 << 16;
107
108        // Green
109        val8 = static_cast<uint8>(g * 255);
110        val32 += val8 << 8;
111
112        // Red
113        val8 = static_cast<uint8>(r * 255);
114        val32 += val8;
115
116
117        return val32;
118    }
119    //---------------------------------------------------------------------
120    void ColourValue::setAsRGBA(const RGBA val)
121    {
122        uint32 val32 = val;
123
124        // Convert from 32bit pattern
125        // (RGBA = 8888)
126
127        // Red
128        r = static_cast<uint8>(val32 >> 24) / 255.0f;
129
130        // Green
131        g = static_cast<uint8>(val32 >> 16) / 255.0f;
132
133        // Blue
134        b = static_cast<uint8>(val32 >> 8) / 255.0f;
135
136        // Alpha
137        a = static_cast<uint8>(val32) / 255.0f;
138    }
139    //---------------------------------------------------------------------
140    void ColourValue::setAsARGB(const ARGB val)
141    {
142        uint32 val32 = val;
143
144        // Convert from 32bit pattern
145        // (ARGB = 8888)
146
147        // Alpha
148        a = static_cast<uint8>(val32 >> 24) / 255.0f;
149
150        // Red
151        r = static_cast<uint8>(val32 >> 16) / 255.0f;
152
153        // Green
154        g = static_cast<uint8>(val32 >> 8) / 255.0f;
155
156        // Blue
157        b = static_cast<uint8>(val32) / 255.0f;
158    }
159    //---------------------------------------------------------------------
160    void ColourValue::setAsABGR(const ABGR val)
161    {
162        uint32 val32 = val;
163
164        // Convert from 32bit pattern
165        // (ABGR = 8888)
166
167        // Alpha
168        a = static_cast<uint8>(val32 >> 24) / 255.0f;
169
170        // Blue
171        b = static_cast<uint8>(val32 >> 16) / 255.0f;
172
173        // Green
174        g = static_cast<uint8>(val32 >> 8) / 255.0f;
175
176        // Red
177        r = static_cast<uint8>(val32) / 255.0f;
178    }
179    //---------------------------------------------------------------------
180    bool ColourValue::operator==(const ColourValue& rhs) const
181    {
182        return (r == rhs.r &&
183            g == rhs.g &&
184            b == rhs.b &&
185            a == rhs.a);
186    }
187    //---------------------------------------------------------------------
188    bool ColourValue::operator!=(const ColourValue& rhs) const
189    {
190        return !(*this == rhs);
191    }
192
193}
194
Note: See TracBrowser for help on using the repository browser.