library of assembled shared sources

http://lass.cocamware.com

color_rgba.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @struct lass::prim::ColorRGBA
00046  *  @brief an [0, 1] floating point RGB colour with Alpha channel.
00047  *  @author Bram de Greve [BdG]
00048  */
00049 
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_COLOR_RGBA_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_COLOR_RGBA_H
00052 
00053 #include "prim_common.h"
00054 #include "vector_4d.h"
00055 
00056 namespace lass
00057 {
00058 namespace prim
00059 {
00060 
00061 class LASS_DLL ColorRGBA
00062 {
00063 public:
00064 
00065     typedef Vector4D<float> TVector;
00066 
00067     typedef TVector::TValue TValue;
00068     typedef TVector::TParam TParam;
00069     typedef TVector::TReference TReference;
00070     typedef TVector::TConstReference TConstReference;
00071     typedef TVector::TNumTraits TNumTraits;
00072 
00073     enum { dimension = 4 }; /**< number of dimensions */
00074 
00075     TValue r;
00076     TValue g;
00077     TValue b;
00078     TValue a;
00079 
00080     ColorRGBA();
00081     ColorRGBA(TParam iRed, TParam iGreen, TParam iBlue,
00082               TParam iAlpha = ColorRGBA::TNumTraits::one);
00083     explicit ColorRGBA(TParam iWhite, TParam iAlpha = ColorRGBA::TNumTraits::one);
00084     explicit ColorRGBA(const TVector& iVector);
00085     // HACK Yes, you have to use ColorRGBA::TNumTraits::one instead of TNumTraits::one because the
00086     // MSVC7.0 doesn't understand the latter [BdG].
00087 
00088     const TVector vector() const { return TVector(r, g, b, a); }
00089     TConstReference operator[](unsigned iIndex) const { return *(&r + iIndex); }
00090     TReference operator[](unsigned iIndex) { return *(&r + iIndex); }
00091     TConstReference at(signed iIndex) const { return *(&r + num::mod(iIndex, static_cast<unsigned>(dimension))); }
00092     TReference at(signed iIndex) { return *(&r + num::mod(iIndex, static_cast<unsigned>(dimension))); }
00093 
00094     const ColorRGBA& operator+() const;
00095     const ColorRGBA operator-() const;
00096     ColorRGBA& operator+=( const ColorRGBA& iOther );
00097     ColorRGBA& operator-=( const ColorRGBA& iOther );
00098     ColorRGBA& operator*=( const ColorRGBA& iOther );
00099     ColorRGBA& operator/=( const ColorRGBA& iOther );
00100     ColorRGBA& operator+=( TParam iWhite );
00101     ColorRGBA& operator-=( TParam iWhite );
00102     ColorRGBA& operator*=( TParam iWhite );
00103     ColorRGBA& operator/=( TParam iWhite );
00104 
00105     const TValue brightness() const;
00106     const bool isBlack() const;
00107     const bool isZero() const;
00108     const bool isNaN() const;
00109 
00110     const ColorRGBA darkened( TParam iFactor ) const;
00111     const ColorRGBA dissolved( TParam iFactor) const;
00112     const ColorRGBA gammaCorrected(TParam iGamma) const;
00113     const ColorRGBA exposed(TParam iTime) const;
00114     const ColorRGBA invExposed(TParam iTime) const;
00115     const ColorRGBA clamped() const;
00116 
00117     // matlab colormaps
00118     //
00119     static const ColorRGBA mapAutumn(TParam iValue);
00120     static const ColorRGBA mapBone(TParam iValue);
00121     static const ColorRGBA mapCool(TParam iValue);
00122     static const ColorRGBA mapCopper(TParam iValue);
00123     static const ColorRGBA mapGray(TParam iValue);
00124     static const ColorRGBA mapHot(TParam iValue);
00125     static const ColorRGBA mapHsv(TParam iValue);
00126     static const ColorRGBA mapJet(TParam iValue);
00127     static const ColorRGBA mapPink(TParam iValue);
00128     static const ColorRGBA mapSpring(TParam iValue);
00129     static const ColorRGBA mapSummer(TParam iValue);
00130     static const ColorRGBA mapWinter(TParam iValue);
00131     static const ColorRGBA mapCustom(TParam iValue, const std::vector<ColorRGBA>& iColorMap);
00132 private:
00133 
00134     static const ColorRGBA doMap(TParam iValue, const ColorRGBA* iMap, int iMapSize);
00135 };
00136 
00137 LASS_DLL ColorRGBA LASS_CALL operator+( const ColorRGBA& iA, const ColorRGBA& iB );
00138 LASS_DLL ColorRGBA LASS_CALL operator-( const ColorRGBA& iA, const ColorRGBA& iB );
00139 LASS_DLL ColorRGBA LASS_CALL operator*( const ColorRGBA& iA, const ColorRGBA& iB );
00140 LASS_DLL ColorRGBA LASS_CALL operator/( const ColorRGBA& iA, const ColorRGBA& iB );
00141 LASS_DLL ColorRGBA LASS_CALL operator+( ColorRGBA::TParam iA, const ColorRGBA& iB );
00142 LASS_DLL ColorRGBA LASS_CALL operator-( ColorRGBA::TParam iA, const ColorRGBA& iB );
00143 LASS_DLL ColorRGBA LASS_CALL operator*( ColorRGBA::TParam iA, const ColorRGBA& iB );
00144 LASS_DLL ColorRGBA LASS_CALL operator/( ColorRGBA::TParam iA, const ColorRGBA& iB );
00145 LASS_DLL ColorRGBA LASS_CALL operator+( const ColorRGBA& iA, ColorRGBA::TParam iB );
00146 LASS_DLL ColorRGBA LASS_CALL operator-( const ColorRGBA& iA, ColorRGBA::TParam iB );
00147 LASS_DLL ColorRGBA LASS_CALL operator*( const ColorRGBA& iA, ColorRGBA::TParam iB );
00148 LASS_DLL ColorRGBA LASS_CALL operator/( const ColorRGBA& iA, ColorRGBA::TParam iB );
00149 
00150 LASS_DLL ColorRGBA LASS_CALL over( const ColorRGBA& iA, const ColorRGBA& iB );
00151 LASS_DLL ColorRGBA LASS_CALL in( const ColorRGBA& iA, const ColorRGBA& iB );
00152 LASS_DLL ColorRGBA LASS_CALL out( const ColorRGBA& iA, const ColorRGBA& iB );
00153 LASS_DLL ColorRGBA LASS_CALL atop( const ColorRGBA& iA, const ColorRGBA& iB );
00154 LASS_DLL ColorRGBA LASS_CALL plus( const ColorRGBA& iA, const ColorRGBA& iB );
00155 LASS_DLL ColorRGBA LASS_CALL through( const ColorRGBA& iA, const ColorRGBA& iB );
00156 
00157 LASS_DLL ColorRGBA::TValue LASS_CALL distance( const ColorRGBA& iA, const ColorRGBA& iB );
00158 
00159 }
00160 
00161 }
00162 
00163 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_COLOR_RGBA
00164 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00165 #   include "pyobject_util.h"
00166 #endif
00167 
00168 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_3D_H
00169 #   include "color_rgba_transformation_3d.h"
00170 #endif
00171 
00172 #endif
00173 
00174 // EOF

Generated on Mon Nov 10 14:20:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo