Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

glcolor.h

00001 /*
00002 Copyright (c) 2000-2003 Lee Thomason (www.grinninglizard.com)
00003 Grinning Lizard Utilities.
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to anyone to use this software for any 
00010 purpose, including commercial applications, and to alter it and 
00011 redistribute it freely, subject to the following restrictions:
00012 
00013 1. The origin of this software must not be misrepresented; you must 
00014 not claim that you wrote the original software. If you use this 
00015 software in a product, an acknowledgment in the product documentation 
00016 would be appreciated but is not required.
00017 
00018 2. Altered source versions must be plainly marked as such, and 
00019 must not be misrepresented as being the original software.
00020 
00021 3. This notice may not be removed or altered from any source 
00022 distribution.
00023 */
00024 
00025 
00026 #ifndef GRINLIZ_COLOR_INCLUDED
00027 #define GRINLIZ_COLOR_INCLUDED
00028 
00029 #include "glutil.h"
00030 #include "gldebug.h"
00031 
00032 namespace grinliz {
00033 
00035 struct Color3F
00036 {
00037         void Set( float r, float g, float b )   { this->r = r; this->g = g; this->b = b; }
00038         void Scale( float v )   { r*=v; g*=v; b*=v; }
00039         float Average()                 { return (r+g+b)/3.0f; }
00040         float r, g, b;
00041 };
00042 
00044 struct Color3U8
00045 {
00046         void Set( U8 r, U8 g, U8 b )    { this->r = r; this->g = g; this->b = b; }
00047         U8 r, g, b;
00048 };
00049 
00051 struct Color4F
00052 {
00053         void Set( float r, float g, float b, float a )  { this->r = r; this->g = g; this->b = b; this->a = a; }
00054         float r, g, b, a;
00055 };
00056 
00058 struct Color4U8
00059 {
00060         void Set( U8 r, U8 g, U8 b, U8 a )      { this->r = r; this->g = g; this->b = b; this->a=a; }
00061         U8 r, g, b, a;
00062 };
00063 
00064 
00066 inline void Convert( const Color4F& c0, Color3U8* c1 ) {
00067         c1->r = (U8)LRintf( c0.r * 255.0f );
00068         c1->g = (U8)LRintf( c0.g * 255.0f );
00069         c1->b = (U8)LRintf( c0.b * 255.0f );
00070 }
00071 
00073 inline void InterpolateColor( const Color3U8& c0, const Color3U8& c1, float val, Color3U8* out ) {
00074         GLASSERT( val >= 0.0f && val <= 1.0f );
00075         int ival = LRintf( val * 255.0f );
00076         GLASSERT( ival >= 0 && ival < 256 );
00077         out->r = (U8) Interpolate( 0, (int)c0.r, 255, (int)c1.r, ival );
00078         out->g = (U8) Interpolate( 0, (int)c0.g, 255, (int)c1.g, ival );
00079         out->b = (U8) Interpolate( 0, (int)c0.b, 255, (int)c1.b, ival );
00080 }
00081 
00082 
00083 };
00084 
00085 #endif

Generated on Sun Sep 25 16:25:48 2005 for Kyra by  doxygen 1.4.3