File: Colour.inl

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (119 lines) | stat: -rw-r--r-- 4,634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * This source file is part of libRocket, the HTML/CSS Interface Middleware
 *
 * For the latest information, see http://www.librocket.com
 *
 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

// Lightweight, non-initialising constructor.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault >::Colour()
{
}

// Initialising constructor.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault >::Colour(ColourType _red, ColourType _green, ColourType _blue, ColourType _alpha)
{
	red = _red;
	green = _green;
	blue = _blue;
	alpha = _alpha;
}

// Returns the sum of this colour and another. This does not saturate the channels.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault > Colour< ColourType, AlphaDefault >::operator+(const Colour< ColourType, AlphaDefault >& rhs) const
{
	return Colour< ColourType, AlphaDefault >(red + rhs.red, green + rhs.green, blue + rhs.blue, alpha + rhs.alpha);
}

// Returns the result of subtracting another colour from this colour.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault > Colour< ColourType, AlphaDefault >::operator-(const Colour< ColourType, AlphaDefault >& rhs) const
{
	return Colour< ColourType, AlphaDefault >(red - rhs.red, green - rhs.green, blue - rhs.blue, alpha - rhs.alpha);
}

// Returns the result of multiplying this colour component-wise by a scalar.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault > Colour< ColourType, AlphaDefault >::operator*(float rhs) const
{
	return Colour((ColourType) (red * rhs), (ColourType) (green * rhs), (ColourType) (blue * rhs), (ColourType) (alpha * rhs));
}

// Returns the result of dividing this colour component-wise by a scalar.
template < typename ColourType, int AlphaDefault >
Colour< ColourType, AlphaDefault > Colour< ColourType, AlphaDefault >::operator/(float rhs) const
{
	return Colour((ColourType) (red / rhs), (ColourType) (green / rhs), (ColourType) (blue / rhs), (ColourType) (alpha / rhs));
}

// Adds another colour to this in-place. This does not saturate the channels.
template < typename ColourType, int AlphaDefault >
void Colour< ColourType, AlphaDefault >::operator+=(const Colour& rhs)
{
	red += rhs.red;
	green += rhs.green;
	blue += rhs.blue;
	alpha += rhs.alpha;
}

// Subtracts another colour from this in-place.
template < typename ColourType, int AlphaDefault >
void Colour< ColourType, AlphaDefault >::operator-=(const Colour& rhs)
{
	red -= rhs.red;
	green -= rhs.green;
	blue -= rhs.blue;
	alpha -= rhs.alpha;
}

// Scales this colour component-wise in-place.
template < typename ColourType, int AlphaDefault >
void Colour< ColourType, AlphaDefault >::operator*=(float rhs)
{
	red = (ColourType)(red * rhs);
	green = (ColourType)(green * rhs);
	blue = (ColourType)(blue * rhs);
	alpha = (ColourType)(alpha * rhs);
}

// Scales this colour component-wise in-place by the inverse of a value.
template < typename ColourType, int AlphaDefault >
void Colour< ColourType, AlphaDefault >::operator/=(float rhs)
{
	*this *= (1.0f / rhs);
}

template < >
Colour< float, 1 > ROCKETCORE_API Colour< float, 1 >::operator*(const Colour< float, 1 >& rhs) const;

template < >
Colour< byte, 255 > ROCKETCORE_API Colour< byte, 255 >::operator*(const Colour< byte, 255 >& rhs) const;

template < >
void ROCKETCORE_API Colour< float, 1 >::operator*=(const Colour& rhs);

template < >
void ROCKETCORE_API Colour< byte, 255 >::operator*=(const Colour& rhs);