ColourVector Class Reference

#include <colourmat.h>

Inheritance diagram for ColourVector:

SimpleCCObject List of all members.

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]

Detailed Description

Definition at line 105 of file colourmat.h.


Member Enumeration Documentation

enum ColourVector::ColourVectorElement
 

Enumerator:
Red 
Green 
Blue 
Alpha 
Spare 

Definition at line 110 of file colourmat.h.

00111     {
00112         Red     = 0,
00113         Green   = 1,
00114         Blue    = 2,
00115         Alpha   = 3,
00116         Spare   = 4
00117     };


Constructor & Destructor Documentation

ColourVector::ColourVector double  r = 0.0,
double  g = 0.0,
double  b = 0.0,
double  a = 1.0,
double  s = 1.0
[inline]
 

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     }


Member Function Documentation

ColourVector ColourVector::Apply ColourMatrix cm  ) 
 

Multiplies a ColourVector by a ColourMatrix and returns the result.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
cm - Colour matrix to operate on [INPUTS]
[OUTPUTS] 
Returns:
The matrix multiplied colour vector

Errors: -

See also:
-
( a1 a2 a3 a4 a5 ) ( b1 b2 b3 b4 b5 ) ( a b c d e ) ( c1 c2 c3 c4 c5 ) = (a*a1+b*b1+c*c1+d*d1+e*e1, a*a2+b*b2+c*c2+d*d2+e*e2 etc.) ( d1 d2 d3 d4 d5 ) ( e1 e2 e3 e4 e5 )

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 }

ColourVector ColourVector::ComposeOnTop ColourVector v  )  [inline]
 

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     }

static UINT32 ColourVector::Get double  v  )  [inline, static]
 

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     }

UINT32 ColourVector::GetA  )  [inline]
 

Definition at line 146 of file colourmat.h.

00146 {return Get(elements[Alpha]);}

UINT32 ColourVector::GetB  )  [inline]
 

Definition at line 145 of file colourmat.h.

00145 {return Get(elements[Blue]);}

UINT32 ColourVector::GetG  )  [inline]
 

Definition at line 144 of file colourmat.h.

00144 {return Get(elements[Green]);}

UINT32 ColourVector::GetR  )  [inline]
 

Definition at line 143 of file colourmat.h.

00143 {return Get(elements[Red]);}

void ColourVector::SetRGBA UINT32  r,
UINT32  g,
UINT32  b,
UINT32  a = 255
[inline]
 

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     }


Member Data Documentation

double ColourVector::elements[5]
 

Definition at line 108 of file colourmat.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:01 2007 for Camelot by  doxygen 1.4.4