#include <colourmat.h>
Inheritance diagram for ColourVector:
Public Types | |
enum | ColourVectorElement { Red = 0, Green = 1, Blue = 2, Alpha = 3, Spare = 4 } |
Public Member Functions | |
ColourVector (double r=0.0, double g=0.0, double b=0.0, double a=1.0, double s=1.0) | |
void | SetRGBA (UINT32 r, UINT32 g, UINT32 b, UINT32 a=255) |
UINT32 | GetR () |
UINT32 | GetG () |
UINT32 | GetB () |
UINT32 | GetA () |
ColourVector | Apply (ColourMatrix &cm) |
Multiplies a ColourVector by a ColourMatrix and returns the result. | |
ColourVector | ComposeOnTop (ColourVector &v) |
Static Public Member Functions | |
static UINT32 | Get (double v) |
Public Attributes | |
double | elements [5] |
Definition at line 105 of file colourmat.h.
|
Definition at line 110 of file colourmat.h.
|
|
Definition at line 119 of file colourmat.h. 00120 { 00121 elements[Red]=r; 00122 elements[Green]=g; 00123 elements[Blue]=b; 00124 elements[Alpha]=a; 00125 elements[Spare]=s; 00126 }
|
|
Multiplies a ColourVector by a ColourMatrix and returns the result.
Definition at line 126 of file colourmat.cpp. 00127 { 00128 ColourVector result; 00129 INT32 i, j; 00130 00131 for (i=0; i<5; i++) // Column of matrix 00132 { 00133 result.elements[i] = 0.0; 00134 for (j=0 ; j<5 ; j++) // Row of matrix 00135 { 00136 result.elements[i]+=elements[j] * cm.elements.el[i+j*5]; 00137 } 00138 } 00139 result.elements[Spare]=1.0; // Fix this up in case of rounding peculiarities 00140 return result; 00141 }
|
|
Definition at line 150 of file colourmat.h. 00151 { 00152 // Check if either is transparent 00153 if (elements[Alpha]==0.0) return v; 00154 if (v.elements[Alpha]==0.0) return *this; 00155 00156 // Generate the new alpha value 00157 double newalpha = v.elements[Alpha] + elements[Alpha] - v.elements[Alpha]*elements[Alpha]; 00158 if (newalpha == 0.0) return ColourVector(elements[Red], elements[Green], elements[Blue], 0.0); 00159 00160 /* Here's how this works: 00161 on a normal composition, of (x1,a1), x= x0 * (1-a1) + x1 * a1 00162 So where (x2,a2) are imposed on top, x = ( x1 * a1 + x0 * (1-a1) ) * (1-a2) + x2 * a2; 00163 Which can be rewritten as 00164 x = x0 ( 1- (a1+a2-a1a2) ) + ( a1+a2-a1a2 )/(a1+a2-a1a2)*((1-a2)(x1a1)+x2a2) 00165 Substituting A = (a1+a2-a2a2), X=((1-a2)(x1a1)+x2a2)/A we get 00166 x = x0 (1-A) + X A 00167 Which is the formula for transparency with alpha A, colour X 00168 */ 00169 00170 return ColourVector( 00171 ((1-v.elements[Alpha])*(elements[Alpha]*elements[Red] ) + (v.elements[Red] * v.elements[Alpha])) / newalpha, 00172 ((1-v.elements[Alpha])*(elements[Alpha]*elements[Green]) + (v.elements[Green] * v.elements[Alpha])) / newalpha, 00173 ((1-v.elements[Alpha])*(elements[Alpha]*elements[Blue] ) + (v.elements[Blue] * v.elements[Alpha])) / newalpha, 00174 newalpha); 00175 }
|
|
Definition at line 136 of file colourmat.h. 00137 { 00138 if (v<0) return 0; 00139 UINT32 x = (UINT32)(v*255.0+0.5); 00140 return (x>255)?255:x; 00141 }
|
|
Definition at line 146 of file colourmat.h.
|
|
Definition at line 145 of file colourmat.h.
|
|
Definition at line 144 of file colourmat.h.
|
|
Definition at line 143 of file colourmat.h.
|
|
Definition at line 128 of file colourmat.h. 00129 { 00130 elements[Red] = ((double)r)/255.0; 00131 elements[Green] = ((double)g)/255.0; 00132 elements[Blue] = ((double)b)/255.0; 00133 elements[Alpha] = ((double)a)/255.0; 00134 }
|
|
Definition at line 108 of file colourmat.h. |