Library of Assembled Shared Sources
color_rgba.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @struct lass::prim::ColorRGBA
46 * @brief an [0, 1] floating point RGB colour with Alpha channel.
47 * @author Bram de Greve [BdG]
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_COLOR_RGBA_H
51#define LASS_GUARDIAN_OF_INCLUSION_PRIM_COLOR_RGBA_H
52
53#include "prim_common.h"
54#include "vector_4d.h"
55
56namespace lass
57{
58namespace prim
59{
60
62{
63public:
64
65 typedef Vector4D<float> TVector;
66
67 typedef TVector::TValue TValue;
68 typedef TVector::TParam TParam;
69 typedef TVector::TReference TReference;
70 typedef TVector::TConstReference TConstReference;
71 typedef TVector::TNumTraits TNumTraits;
72
73 enum { dimension = 4 }; /**< number of dimensions */
74
75 TValue r;
76 TValue g;
77 TValue b;
78 TValue a;
79
80 ColorRGBA();
81 ColorRGBA(TParam red, TParam green, TParam blue,
82 TParam alpha = ColorRGBA::TNumTraits::one);
83 explicit ColorRGBA(TParam white, TParam alpha = ColorRGBA::TNumTraits::one);
84 explicit ColorRGBA(const TVector& vector);
85 // HACK Yes, you have to use ColorRGBA::TNumTraits::one instead of TNumTraits::one because the
86 // MSVC7.0 doesn't understand the latter [BdG].
87
88 const TVector vector() const { return TVector(r, g, b, a); }
89 TConstReference operator[](size_t index) const { return *(&r + index); }
90 TReference operator[](size_t index) { return *(&r + index); }
91 TConstReference at(signed index) const { return *(&r + num::mod(index, static_cast<unsigned>(dimension))); }
92 TReference at(signed index) { return *(&r + num::mod(index, static_cast<unsigned>(dimension))); }
93
94 const ColorRGBA& operator+() const;
95 const ColorRGBA operator-() const;
96 ColorRGBA& operator+=( const ColorRGBA& other );
97 ColorRGBA& operator-=( const ColorRGBA& other );
98 ColorRGBA& operator*=( const ColorRGBA& other );
99 ColorRGBA& operator/=( const ColorRGBA& other );
100 ColorRGBA& operator+=( TParam white );
101 ColorRGBA& operator-=( TParam white );
102 ColorRGBA& operator*=( TParam white );
103 ColorRGBA& operator/=( TParam white );
104
105 TValue brightness() const;
106 bool isBlack() const;
107 bool isZero() const;
108 bool isNaN() const;
109
110 const ColorRGBA darkened( TParam factor ) const;
111 const ColorRGBA dissolved( TParam factor) const;
112 const ColorRGBA gammaCorrected(TParam gamma) const;
113 const ColorRGBA exposed(TParam time) const;
114 const ColorRGBA invExposed(TParam time) const;
115 const ColorRGBA clamped() const;
116
117 // matlab colormaps
118 //
119 static const ColorRGBA mapAutumn(TParam value);
120 static const ColorRGBA mapBone(TParam value);
121 static const ColorRGBA mapCool(TParam value);
122 static const ColorRGBA mapCopper(TParam value);
123 static const ColorRGBA mapGray(TParam value);
124 static const ColorRGBA mapHot(TParam value);
125 static const ColorRGBA mapHsv(TParam value);
126 static const ColorRGBA mapJet(TParam value);
127 static const ColorRGBA mapPink(TParam value);
128 static const ColorRGBA mapSpring(TParam value);
129 static const ColorRGBA mapSummer(TParam value);
130 static const ColorRGBA mapWinter(TParam value);
131 static const ColorRGBA mapCustom(TParam value, const std::vector<ColorRGBA>& colorMap);
132private:
133
134 static const ColorRGBA doMap(TParam value, const ColorRGBA* iMap, int iMapSize);
135};
136
137LASS_DLL ColorRGBA LASS_CALL operator+( const ColorRGBA& a, const ColorRGBA& b );
138LASS_DLL ColorRGBA LASS_CALL operator-( const ColorRGBA& a, const ColorRGBA& b );
139LASS_DLL ColorRGBA LASS_CALL operator*( const ColorRGBA& a, const ColorRGBA& b );
140LASS_DLL ColorRGBA LASS_CALL operator/( const ColorRGBA& a, const ColorRGBA& b );
141LASS_DLL ColorRGBA LASS_CALL operator+( ColorRGBA::TParam a, const ColorRGBA& b );
142LASS_DLL ColorRGBA LASS_CALL operator-( ColorRGBA::TParam a, const ColorRGBA& b );
143LASS_DLL ColorRGBA LASS_CALL operator*( ColorRGBA::TParam a, const ColorRGBA& b );
144LASS_DLL ColorRGBA LASS_CALL operator/( ColorRGBA::TParam a, const ColorRGBA& b );
145LASS_DLL ColorRGBA LASS_CALL operator+( const ColorRGBA& a, ColorRGBA::TParam b );
146LASS_DLL ColorRGBA LASS_CALL operator-( const ColorRGBA& a, ColorRGBA::TParam b );
147LASS_DLL ColorRGBA LASS_CALL operator*( const ColorRGBA& a, ColorRGBA::TParam b );
148LASS_DLL ColorRGBA LASS_CALL operator/( const ColorRGBA& a, ColorRGBA::TParam b );
149
150LASS_DLL ColorRGBA LASS_CALL over( const ColorRGBA& a, const ColorRGBA& b );
151LASS_DLL ColorRGBA LASS_CALL in( const ColorRGBA& a, const ColorRGBA& b );
152LASS_DLL ColorRGBA LASS_CALL out( const ColorRGBA& a, const ColorRGBA& b );
153LASS_DLL ColorRGBA LASS_CALL atop( const ColorRGBA& a, const ColorRGBA& b );
154LASS_DLL ColorRGBA LASS_CALL plus( const ColorRGBA& a, const ColorRGBA& b );
155LASS_DLL ColorRGBA LASS_CALL through( const ColorRGBA& a, const ColorRGBA& b );
156
157LASS_DLL ColorRGBA::TValue LASS_CALL distance( const ColorRGBA& a, const ColorRGBA& b );
158
159}
160
161}
162
163#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_COLOR_RGBA
164#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
166#endif
167
168#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_3D_H
170#endif
171
172#endif
173
174// EOF
an [0, 1] floating point RGB colour with Alpha channel.
Definition color_rgba.h:62
ColorRGBA & operator-=(const ColorRGBA &other)
raw subtraction other from this color, including alpha channel
static const ColorRGBA mapWinter(TParam value)
convert a value in range [0, 1] to a color like in colormap 'winter' of matlab.
static const ColorRGBA mapHot(TParam value)
convert a value in range [0, 1] to a color like in colormap 'hot' of matlab.
static const ColorRGBA mapPink(TParam value)
convert a value in range [0, 1] to a color like in colormap 'pink' of matlab.
const ColorRGBA darkened(TParam factor) const
return darkened colour without changing the opaqueness.
static const ColorRGBA mapCopper(TParam value)
convert a value in range [0, 1] to a color like in colormap 'copper' of matlab.
bool isBlack() const
return true if all color components are zero
static const ColorRGBA mapCool(TParam value)
convert a value in range [0, 1] to a color like in colormap 'cool' of matlab.
const ColorRGBA exposed(TParam time) const
return exposed color.
static const ColorRGBA mapBone(TParam value)
convert a value in range [0, 1] to a color like in colormap 'bone' of matlab.
static const ColorRGBA mapJet(TParam value)
convert a value in range [0, 1] to a color like in colormap 'jet' of matlab.
static const ColorRGBA mapAutumn(TParam value)
convert a value in range [0, 1] to a color like in colormap 'autumn' of matlab.
ColorRGBA()
construct an unexisting color (black with zero alpha)
bool isNaN() const
Return true if at least one of the components is NaN.
const ColorRGBA invExposed(TParam time) const
return result of inverse exposure function
static const ColorRGBA mapGray(TParam value)
convert a value in range [0, 1] to a color like in colormap 'gray' of matlab.
static const ColorRGBA mapSummer(TParam value)
convert a value in range [0, 1] to a color like in colormap 'summer' of matlab.
const ColorRGBA clamped() const
clamp all channels (including alpha channel) to the range [0, 1].
ColorRGBA & operator*=(const ColorRGBA &other)
raw multiplication of other with this color, including alpha channel
const ColorRGBA gammaCorrected(TParam gamma) const
return gamma corrected color.
static const ColorRGBA mapCustom(TParam value, const std::vector< ColorRGBA > &colorMap)
convert a value in range [0, 1] to a color from a custom color map.
const ColorRGBA dissolved(TParam factor) const
return color with dissolved opaqueness
ColorRGBA & operator+=(const ColorRGBA &other)
raw addition of other to this color, including alpha channel
static const ColorRGBA mapHsv(TParam value)
convert a value to a color like in colormap 'hsv' of matlab.
ColorRGBA & operator/=(const ColorRGBA &other)
raw division of this color by other, including alpha channel
static const ColorRGBA mapSpring(TParam value)
convert a value in range [0, 1] to a color like in colormap 'spring' of matlab.
bool isZero() const
return true if all components are zero
#define LASS_SIMD_ALIGN
if LASS_SIMD_ALIGNMENT is set, use LASS_SIMD_ALIGN to align some structures on SIMD alignment boundar...
#define LASS_DLL
DLL interface: import or export symbols?
set of geometrical primitives
Definition aabb_2d.h:81
ColorRGBA plus(const ColorRGBA &a, const ColorRGBA &b)
ColorRGBA over(const ColorRGBA &a, const ColorRGBA &b)
placement of foreground a in front of background b.
ColorRGBA out(const ColorRGBA &a, const ColorRGBA &b)
a held out by b, part of a outside b.
ColorRGBA through(const ColorRGBA &a, const ColorRGBA &b)
a seen through color filter b.
ColorRGBA in(const ColorRGBA &a, const ColorRGBA &b)
part of a inside b.
ColorRGBA atop(const ColorRGBA &a, const ColorRGBA &b)
union of a in b and b out a.
Library for Assembled Shared Sources.
Definition config.h:53