2
* $Id: IMG_Color.h,v 1.6 2005/09/09 22:31:23 bjornmose Exp $
4
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version. The Blender
10
* Foundation also sells licenses for use in proprietary software under
11
* the Blender License. See http://www.blender.org/BL/ for information
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24
* All rights reserved.
26
* The Original Code is: all of this file.
28
* Contributor(s): none yet.
30
* ***** END GPL/BL DUAL LICENSE BLOCK *****
31
* @author Maarten Gribnau
41
* Implements a color with red, green and blue components.
42
* Components are stored as floats.
43
* @author Maarten Gribnau
50
* Constructs a color with the given values.
51
* @param r requested red component of the color
52
* @param g requested green component of the color
53
* @param b requested blue component of the color
55
IMG_ColorRGB(float r=0, float g=0, float b=0)
56
: m_r(r), m_g(g), m_b(b) {}
60
* @param c the color to copy.
62
IMG_ColorRGB(const IMG_ColorRGB& c)
63
: m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) {}
66
* Constructs a color without alpha from one with.
67
* @param c the color to copy.
69
inline IMG_ColorRGB(const IMG_ColorRGBA& c);
71
/** Red component of the color */
73
/** Green component of the color */
75
/** Blue component of the color */
81
* Implements a color with red, green, blue and alpha components.
82
* Components are stored as floats.
83
* @author Maarten Gribnau
90
* Constructs a color with the given values.
91
* @param r requested red component of the color
92
* @param g requested green component of the color
93
* @param b requested blue component of the color
94
* @param a requested alpha component of the color
96
IMG_ColorRGBA(float r=0, float g=0, float b=0, float a=0)
97
: m_r(r), m_g(g), m_b(b), m_a(a) {}
101
* @param c the color to copy.
103
IMG_ColorRGBA(const IMG_ColorRGBA& c)
104
: m_r(c.m_r), m_g(c.m_g), m_b(c.m_b), m_a(c.m_a) {}
107
* Constructs a color with alpha from one without.
108
* @param c the color to copy.
110
IMG_ColorRGBA(const IMG_ColorRGB& c)
111
: m_r(c.m_r), m_g(c.m_g), m_b(c.m_b), m_a(0) {}
114
* Blends the given color with this color.
115
* Uses the alpha of the given color for blending.
116
* The alpha of this color is left untouched.
117
* @param c the color to blend
119
inline void blendColor(const IMG_ColorRGBA& c);
121
/** Red component of the color */
123
/** Green component of the color */
125
/** Blue component of the color */
127
/** Alpha component of the color */
131
inline IMG_ColorRGB::IMG_ColorRGB(const IMG_ColorRGBA& c)
132
: m_r(c.m_r), m_g(c.m_g), m_b(c.m_b) {}
134
inline void IMG_ColorRGBA::blendColor(const IMG_ColorRGBA& c)
136
float r1 = 1 - c.m_a; // The reverse of alpha
137
#if IMG_REVERSED_ALPHA
138
m_r = c.m_a * m_r + r1 * c.m_r;
139
m_g = c.m_a * m_g + r1 * c.m_g;
140
m_b = c.m_a * m_b + r1 * c.m_b;
142
m_r = r1 * m_r + c.m_a * c.m_r;
143
m_g = r1 * m_g + c.m_a * c.m_g;
144
m_b = r1 * m_b + c.m_a * c.m_b;
149
#endif // _H_IMG_Color