00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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