ColorBuf Class Reference

Simple RGB and RGBA color buffer where R, G, B and A are represented by byte values. Same as what is stored in the TGA files. More...

#include <ColorBuf.h>

List of all members.

Public Member Functions

void operator+= (const ColorBuf &)
void operator-= (const ColorBuf &)
void operator *= (const float)
ColorBuf operator+ (const ColorBuf &other)
 operator COLORREF ()
ColorBufoperator= (const ColorBuf &other)
RGBFloat GetFactoredRGBFloat () const
RGBFloat GetNormalizedRGBFloat () const
 ColorBuf ()
 ColorBuf (LONG col)
 ColorBuf (UBYTE pred, UBYTE pgreen, UBYTE pblue)
 ColorBuf (UBYTE pred, UBYTE pgreen, UBYTE pblue, UBYTE palpha)
 ColorBuf (COLORREF c)
 ColorBuf (const RGBAFloat &color)
UBYTE Red () const
UBYTE Green () const
UBYTE Blue () const
UBYTE Alpha () const
ULONG Color () const
void Set (UBYTE pred, UBYTE pgreen, UBYTE pblue, UBYTE alpha)
void SetRed (UBYTE red)
void SetGreen (UBYTE green)
void SetBlue (UBYTE blue)
void SetAlpha (UBYTE alpha)
void SetColor (ULONG pcolor)
void GammaCorrect (float power)
RGBFloat Get () const
float GetOpacity () const
void Set (const RGBFloat &)
void SetOpacity (const float value)


Detailed Description

Simple RGB and RGBA color buffer where R, G, B and A are represented by byte values. Same as what is stored in the TGA files.

Note:
ColorBuf is also used to represent depth buffers. The Depth buffer files created by Animation Master are simply a 32-bit Targa (.tga) file. The four color components (Red, Green, Blue, Alpha) and the 4 bytes that make up the 32 bit floating point depth value. Here is a code snipet on how to convert the four bytes into a float.
inline float RGBAToDepth(UBYTE red, UBYTE green, UBYTE blue, UBYTE alpha)
{
   float *fptr;
   DWORD value;

   value = (DWORD)(alpha << 24 | red << 16 | green << 8 | blue);
   fptr = (float *)&value;
   return *fptr;
}

Note:
And ColorBuf is also used to represent normals. Normal buffer files are also a 32-bit Targa file. The four components make up the normal vector of the surface. To calculate normal, z=sqrt(1-X*X-Y*Y); Here is a code snipet on how to convert the four bytes into a normal.
inline Vector RGBAToVector(UBYTE red, UBYTE green, UBYTE blue, UBYTE alpha)
{
   signed short value;
   Vector v;

   value = (signed short)(green << 8 | red);
   v.x = (float)value/32768;

   value = (signed short)(alpha << 8 | blue);
   v.y = (float)value/32768;

   // since the vector is normalized, z can be computed
   v.z = sqrt(1-v.x*v.x-v.y*v.y);
   return v;
}

Note:
The FLM is nothing more than a 32 bit TARGA file. So you can use any tga loader to load the image.
Once the TGA is loaded you can use the rbga byte values to get to a floating point value. Here is how:

red : 11, green : 11, blue : 10;

The 4 rgba bytes represent a long in that order.. The first 11 bits are the red component, the second 11 bits are the green component and the last 10 bits are the blue component. You could create a class like this:

class Color {
public:
   union {
      struct {
         ULONG   m_red : 11,
                 m_green: 11,
                 m_blue : 10;
      };
      UBYTE m_r, m_g, m_b, m_a;
   };

};

#define MAXCOLOR33 2047

You could then make a Set(...) member function that would set the m_r, m_g, m_b, m_a values from the TGA file, and a Get member function that would:

Color::Get(float &r, float &g, float &b ) const
{
   r = (float)m_red/MAXCOLOR33;
   g = (float)m_green/MAXCOLOR33;
   b = (float)m_blue/(MAXCOLOR33/2);
}

Definition at line 39 of file ColorBuf.h.


Constructor & Destructor Documentation

ColorBuf::ColorBuf  )  [inline]
 

Creates an instance of a ColorBuf where the initial color is black and the alpha channel is fully opaque.

Definition at line 62 of file ColorBuf.h.

References color, MAXCOLOR, and values.

ColorBuf::ColorBuf LONG  col  )  [inline]
 

Creates an instance of a ColorBuf. The color is copied from the col parameter. The alpha channel is fully opaque.

Note:
If col parameter contained valid alpha channel values, it was discarded by the constructor.

Definition at line 63 of file ColorBuf.h.

References color, MAXCOLOR, and values.

ColorBuf::ColorBuf UBYTE  pred,
UBYTE  pgreen,
UBYTE  pblue
[inline]
 

Creates an instance of a ColorBuf. The color channels are copied from the parameters and the alpha channel is fully opaque.

Definition at line 64 of file ColorBuf.h.

References MAXCOLOR, and values.

ColorBuf::ColorBuf UBYTE  pred,
UBYTE  pgreen,
UBYTE  pblue,
UBYTE  palpha
[inline]
 

Creates an instance of a ColorBuf. The colors and alpha channels are copied from the parameters.

Definition at line 65 of file ColorBuf.h.

References values.

ColorBuf::ColorBuf COLORREF  c  )  [inline]
 

Creates an instance of a ColorBuf. The color is copied from the c parameter. The alpha channel is fully opaque.

Note:
If c parameter contained valid alpha channel values, it was discarded by the constructor.

Definition at line 66 of file ColorBuf.h.

References values.

ColorBuf::ColorBuf const RGBAFloat color  )  [inline]
 

Creates an instance of a ColorBuf. The colors and alpha channels are set from the color parameter which is interpreted as being normalized. That is color and alpha channel values of 1.0 is mapped to 255.

Definition at line 13 of file ColorBuf.inl.

References RGBAFloat::Alpha(), RGBAFloat::Blue(), fast_ftol_unsigned(), RGBAFloat::Green(), MAXCOLOR, MIN, RGBAFloat::Red(), and values.

Here is the call graph for this function:


Member Function Documentation

UBYTE ColorBuf::Alpha  )  const [inline]
 

Retrieve the alpha channel value. Return value is UBYTE so between 0 and 255.

Definition at line 72 of file ColorBuf.h.

References values.

UBYTE ColorBuf::Blue  )  const [inline]
 

Retrieve the blue channel value. Return value is UBYTE so between 0 and 255.

Definition at line 71 of file ColorBuf.h.

References values.

ULONG ColorBuf::Color  )  const [inline]
 

Retrieve all the color and alpha channel values as a ULONG, so between 0 and 255.

Definition at line 73 of file ColorBuf.h.

References color.

void ColorBuf::GammaCorrect float  power  )  [inline]
 

Apply a Gamma correction to the color channels. Alpha channel is not corrected.

Note:
Applying a Gamma correction directly on a ColorBuf instance is not recommanded because it can produce strong color aliasing where several original colors values will map to the same corrected value and several color values will be left unused resulting in loss of information. It is recommended that Gamma correction be applied from a RGBAFloat or RGBAHalf for optimal results.

Definition at line 152 of file ColorBuf.h.

References GammaCorrectColBuf(), and values.

Here is the call graph for this function:

RGBFloat ColorBuf::Get void   )  const [inline]
 

Retrieve the normalized (from 0.0 to 1.0) color channels values.

Definition at line 28 of file ColorBuf.inl.

References MAXCOLOR, and values.

RGBFloat ColorBuf::GetFactoredRGBFloat  )  const [inline]
 

Factored color values are between 0.0 and 255.0 where 0.0 represent total black and 255.0 represent a theoretical white.

Definition at line 34 of file ColorBuf.inl.

References values.

RGBFloat ColorBuf::GetNormalizedRGBFloat  )  const [inline]
 

Normalized color values are between 0.0 and 1.0 where 0.0 represent total black and 1.0 represent a theoretical white. Note that when stored in a ColorBuf, color values can never exceed 1.0.

Definition at line 39 of file ColorBuf.inl.

References MAXCOLOR, and values.

float ColorBuf::GetOpacity void   )  const [inline]
 

Retrieve the normalized (from 0.0 to 1.0) alpha channel value.

Definition at line 88 of file ColorBuf.h.

References MAXCOLOR, and values.

UBYTE ColorBuf::Green  )  const [inline]
 

Retrieve the green channel value. Return value is UBYTE so between 0 and 255.

Definition at line 70 of file ColorBuf.h.

References values.

void ColorBuf::operator *= const float  factor  )  [inline]
 

Multiplies the current instance channel values by the factor parameter. Result is rounded to the nearest integer.

Definition at line 137 of file ColorBuf.h.

References values.

ColorBuf::operator COLORREF  )  [inline]
 

Casts a ColorBuf into a COLORREF.

Definition at line 56 of file ColorBuf.h.

References values.

ColorBuf ColorBuf::operator+ const ColorBuf other  )  [inline]
 

Returns the result of adding the passed value (right side operand) to the current value (left side operand).

Definition at line 119 of file ColorBuf.h.

References alpha, blue, green, red, and values.

void ColorBuf::operator+= const ColorBuf other  )  [inline]
 

Adds the parameter value to the current instance channels (color and alpha) values. Values are capped to 255.

Definition at line 98 of file ColorBuf.h.

References MAXCOLOR, and values.

void ColorBuf::operator-= const ColorBuf other  )  [inline]
 

Subtracts the parameter value from the current instance value.

Definition at line 129 of file ColorBuf.h.

References values.

ColorBuf & ColorBuf::operator= const ColorBuf other  )  [inline]
 

Sets the color and alpha channels to the new values.

Definition at line 57 of file ColorBuf.h.

References color.

UBYTE ColorBuf::Red  )  const [inline]
 

Retrieve the red channel value. Return value is UBYTE so between 0 and 255.

Definition at line 69 of file ColorBuf.h.

References values.

void ColorBuf::Set const RGBFloat color  )  [inline]
 

Sets the color channel values from the normalized (from 0.0 to 1.0) color parameter.

Definition at line 21 of file ColorBuf.inl.

References RGBFloat::Blue(), fast_ftol_unsigned(), RGBFloat::Green(), MAXCOLOR, MIN, RGBFloat::Red(), and values.

Here is the call graph for this function:

void ColorBuf::Set UBYTE  pred,
UBYTE  pgreen,
UBYTE  pblue,
UBYTE  alpha
[inline]
 

Sets the colors and alpha channels values from the parameters.

Definition at line 74 of file ColorBuf.h.

References values.

void ColorBuf::SetAlpha UBYTE  alpha  )  [inline]
 

Sets the alpha opacity channel value from the parameter.

Definition at line 78 of file ColorBuf.h.

References values.

void ColorBuf::SetBlue UBYTE  blue  )  [inline]
 

Sets the blue color channel value from the parameter.

Definition at line 77 of file ColorBuf.h.

References values.

void ColorBuf::SetColor ULONG  pcolor  )  [inline]
 

Sets the colors and alpha channels values from the parameter.

Definition at line 79 of file ColorBuf.h.

References color, MAXCOLOR, and values.

void ColorBuf::SetGreen UBYTE  green  )  [inline]
 

Sets the green color channel value from the parameter.

Definition at line 76 of file ColorBuf.h.

References values.

void ColorBuf::SetOpacity const float  value  )  [inline]
 

Sets the alpha channel value from the normalized (from 0.0 to 1.0) value parameter.

Definition at line 93 of file ColorBuf.h.

References fast_ftol_unsigned(), MAXCOLOR, and values.

Here is the call graph for this function:

void ColorBuf::SetRed UBYTE  red  )  [inline]
 

Sets the red color channel value from the parameter.

Definition at line 75 of file ColorBuf.h.

References values.


Member Data Documentation

UBYTE ColorBuf::alpha
 

Definition at line 44 of file ColorBuf.h.

Referenced by operator+().

UBYTE ColorBuf::blue
 

Definition at line 44 of file ColorBuf.h.

Referenced by operator+().

ULONG ColorBuf::color
 

Definition at line 49 of file ColorBuf.h.

Referenced by Color(), ColorBuf(), operator=(), and SetColor().

UBYTE ColorBuf::green
 

Definition at line 44 of file ColorBuf.h.

Referenced by operator+().

UBYTE ColorBuf::red
 

Definition at line 44 of file ColorBuf.h.

Referenced by operator+().

struct { ... } ColorBuf::values
 

Referenced by Alpha(), Blue(), ColorBuf(), ColorVectorAlpha::ColorVectorAlpha(), GammaCorrect(), Get(), GetFactoredRGBFloat(), GetNormalizedRGBFloat(), GetOpacity(), Green(), operator *=(), operator COLORREF(), operator+(), operator+=(), operator-=(), Red(), RGBAFloat::RGBAFloat(), Set(), SetAlpha(), SetBlue(), SetColor(), SetGreen(), SetOpacity(), SetRed(), and YAFloat::YAFloat().


The documentation for this class was generated from the following files:
This A:M SDK v12.0 documentation is maintained by Hash Inc. Please address any comments concerning this documentation to AMReports. If you have any information, knowledge, or documentation to share with the A:M developer community, please post them on the Hash SDK forum.

Generated on Thu Oct 27 11:46:51 2005 with doxygen 1.4.5 written by Dimitri van Heesch, © 1997-2001