CVR-Lib last update 20 Sep 2009

cvr::rgbaPixel Class Reference
[Color Analysis]

Color pixel representation in RGB color space with an alpha channel. More...

#include <cvrRGBAPixel.h>

List of all members.

Public Types

typedef ubyte value_type
typedef int size_type

Public Member Functions

 rgbaPixel ()
 rgbaPixel (const rgbaPixel &other)
 rgbaPixel (const uint32 val)
 rgbaPixel (const ubyte r, const ubyte g, const ubyte b, const ubyte d=0)
void set (const ubyte r, const ubyte g, const ubyte b, const ubyte a)
void set (const ubyte r, const ubyte g, const ubyte blue)
void setRed (const ubyte r)
void setGreen (const ubyte g)
void setBlue (const ubyte b)
void setAlpha (const ubyte d)
void setValue (const uint32 &v)
void get (ubyte &r, ubyte &g, ubyte &b) const
void get (int &r, int &g, int &b) const
void get (ubyte &r, ubyte &g, ubyte &b, ubyte &a) const
void get (int &r, int &g, int &b, int &a) const
const ubytegetRed () const
const ubytegetGreen () const
const ubytegetBlue () const
const ubytegetAlpha () const
ubytegetRed ()
ubytegetGreen ()
ubytegetBlue ()
ubytegetAlpha ()
const uint32getValue () const
uint32getValue ()
ubyteat (const int x)
const ubyteat (const int x) const
ubyteoperator[] (const int x)
const ubyteoperator[] (const int x) const
size_type size () const
rgbaPixelcopy (const rgbaPixel &other)
rgbaPixeloperator= (const rgbaPixel &other)
bool isEqual (const rgbaPixel &other) const
bool operator== (const rgbaPixel &other) const
bool operator!= (const rgbaPixel &other) const
bool operator< (const rgbaPixel &other) const
bool operator> (const rgbaPixel &other) const
rgbaPixeladd (const rgbaPixel &other)
rgbaPixeloperator+= (const rgbaPixel &other)
rgbaPixel operator+ (const rgbaPixel &other) const
rgbaPixelsubtract (const rgbaPixel &other)
rgbaPixeloperator-= (const rgbaPixel &other)
rgbaPixel operator- (const rgbaPixel &other) const
rgbaPixelmultiply (const rgbaPixel &other)
rgbaPixeloperator*= (const rgbaPixel &other)
rgbaPixel operator* (const rgbaPixel &other) const
rgbaPixelmultiply (const int other)
rgbaPixelmultiply (const float &other)
rgbaPixelmultiply (const double &other)
rgbaPixeloperator*= (const int other)
rgbaPixeloperator*= (const float &other)
rgbaPixeloperator*= (const double &other)
rgbaPixel operator* (const int other) const
rgbaPixel operator* (const float &other) const
rgbaPixel operator* (const double &other) const
rgbaPixeldivide (const rgbaPixel &other)
rgbaPixeloperator/= (const rgbaPixel &other)
rgbaPixel operator/ (const rgbaPixel &other) const
rgbaPixeldivide (const int other)
rgbaPixeldivide (const float &other)
rgbaPixeldivide (const double &other)
rgbaPixeloperator/= (const int other)
rgbaPixeloperator/= (const float &other)
rgbaPixeloperator/= (const double &other)
rgbaPixel operator/ (const int other) const
rgbaPixel operator/ (const float &other) const
rgbaPixel operator/ (const double &other) const
rgbaPixeloverlay (const rgbaPixel &below)
rgbaPixeloverlay (const rgbaPixel &above, const rgbaPixel &below)
int absSqr () const
int dot (const rgbaPixel &other) const
int distanceSqr (const rgbaPixel &other) const
Storable interface
bool read (ioHandler &handler, const bool complete=true)
bool write (ioHandler &handler, const bool complete=true) const

Public Attributes

union {
   struct {
      ubyte   blue
      ubyte   green
      ubyte   red
      ubyte   alpha
   } 
   uint32   value
   ubyte   data [4]
}; 


Detailed Description

Color pixel representation in RGB color space with an alpha channel.

Since most modern cameras provide the images as matrices of RGB triplets with values between 0 and 255 for each color channel, and the modern processor architectures allow a more efficient access to the memory if each pixel is 32-bit aligned, the CVR-Libuses a pixel data structure which also corresponds with a cvr::uint32 type.

This type contains therefore four unsigned bytes (cvr::ubyte) which can be accessed through their color names (red, green, blue) and an additional alpha channel, which is ignored in most operations but can also be used to operate with partial "transparent" pixels.

The alpha value of 0 is the default and means also zero transparency. An alpha value of 255 means fully transparent.

The related template type cvr::rgbPixel<T> can be used to represent the RGB triplets with other types.

The use of rgbaPixel as a vector structure considers it as a three dimensional point in the RGB color space, i.e. the alpha value is ignored for the distance and magniture operators, the access operator[] or at() methods can only access the three color components, and the arithmetical operations always ignore the alpha component.


Member Typedef Documentation

Return type of the size() member.

Used for the template-based interface for pixels as vectors.


Constructor & Destructor Documentation

cvr::rgbaPixel::rgbaPixel (  ) 

Default constructor.

The default constructor of the CVR-LibrgbaPixel does not initialize anything, in order to allow the creation of uninitialized images in a more efficient way.

cvr::rgbaPixel::rgbaPixel ( const rgbaPixel other  ) 

Copy constructor.

cvr::rgbaPixel::rgbaPixel ( const uint32  val  ) 

Constructor with initialization of attributes.

The new rgbaPixel will be initialized with the given value.

Parameters:
val a 4 ubyte value to be assigned to the three channels and the alpha channel. Note that the order depends on the system endianness:
  • If you use little endian (for example: Intel Processor) a value of 0x00010203 means red=01,green=02 and blue=03
  • If you use big endian (for example: PowerPC Processor) a value of 0x00010203 means red=02,green=01 and blue=00 Avoid the use of this constructor if you want to maintain platform compatibility.

cvr::rgbaPixel::rgbaPixel ( const ubyte  r,
const ubyte  g,
const ubyte  b,
const ubyte  d = 0 
)

RGB constructor.

Parameters:
r 8 bit value for the red component
g 8 bit value for the green component
b 8 bit value for the blue component
d 8 bit value for the alpha byte (default value 0)


Member Function Documentation

int cvr::rgbaPixel::absSqr (  )  const [inline]

Compute the square of the magnitud of this pixel $red^2+green^2+blue^2$.

rgbaPixel& cvr::rgbaPixel::add ( const rgbaPixel other  )  [inline]

Add this pixel with another one.

The alpha channel is kept unchanged.

const ubyte& cvr::rgbaPixel::at ( const int  x  )  const [inline]

Used to simulate read-only vector access.

The correspondence between the elements of the vector and the color components still depents on the endianness of the system, but is usually at(0) for red, at(1) for green and at(2) for blue.

ubyte& cvr::rgbaPixel::at ( const int  x  )  [inline]

Used to simulate vector access.

The correspondence between the elements of the vector and the color components is at(0) for red, at(1) for green and at(2) for blue.

rgbaPixel& cvr::rgbaPixel::copy ( const rgbaPixel other  )  [inline]

Copy the "other" pixel.

int cvr::rgbaPixel::distanceSqr ( const rgbaPixel other  )  const [inline]

Square of the distance between this pixel and the other one.

$(red-other.red)^2+(green-other.green)^2+(blue-other.blue)^2$.

Referenced by cvr::euclideanDistance(), and cvr::euclideanDistanceSqr().

rgbaPixel& cvr::rgbaPixel::divide ( const double &  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::divide ( const float &  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::divide ( const int  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::divide ( const rgbaPixel other  )  [inline]

Divide this pixel with another one.

The pixel division divides elementwise the elements of the pixel except the alpha channel, which is kept unchanged.

int cvr::rgbaPixel::dot ( const rgbaPixel other  )  const [inline]

Scalar product in the 3D RGB color space.

Get the scalar product of this pixel with another one, considering them as a 3D point in the RGB color space.

The dot product will be the sum of the red*other.red + green*other.green + blue*other.blue

void cvr::rgbaPixel::get ( int &  r,
int &  g,
int &  b,
int &  a 
) const [inline]

Get the four components and write them in the given arguments.

void cvr::rgbaPixel::get ( ubyte r,
ubyte g,
ubyte b,
ubyte a 
) const [inline]

Get the four components and write them in the given arguments.

void cvr::rgbaPixel::get ( int &  r,
int &  g,
int &  b 
) const [inline]

Get the three color components and write them in the given arguments.

void cvr::rgbaPixel::get ( ubyte r,
ubyte g,
ubyte b 
) const [inline]

Get the three color components and write them in the given arguments.

ubyte& cvr::rgbaPixel::getAlpha (  )  [inline]

Returns alpha component.

const ubyte& cvr::rgbaPixel::getAlpha (  )  const [inline]

Returns alpha component.

ubyte& cvr::rgbaPixel::getBlue (  )  [inline]

Returns blue component.

const ubyte& cvr::rgbaPixel::getBlue (  )  const [inline]

Returns blue component.

Referenced by cvr::scale().

ubyte& cvr::rgbaPixel::getGreen (  )  [inline]

Returns green component.

const ubyte& cvr::rgbaPixel::getGreen (  )  const [inline]

Returns green component.

Referenced by cvr::scale().

ubyte& cvr::rgbaPixel::getRed (  )  [inline]

Returns red component.

const ubyte& cvr::rgbaPixel::getRed (  )  const [inline]

Returns red component.

Referenced by cvr::scale().

uint32& cvr::rgbaPixel::getValue (  )  [inline]

Returns 4 byte component with RGB value.

const uint32& cvr::rgbaPixel::getValue (  )  const [inline]

Returns 4 byte component with RGB and alpha value.

bool cvr::rgbaPixel::isEqual ( const rgbaPixel other  )  const [inline]

Compare two pixels (true if equal!).

Two pixels are equal if all four components (red, green, blue, and alpha) are equal. It is an usual error to leave the alpha channel uninizalized and then compare for equalilty.

rgbaPixel& cvr::rgbaPixel::multiply ( const double &  other  )  [inline]

Multiply all components of this pixel with a float, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::multiply ( const float &  other  )  [inline]

Multiply all components of this pixel with a float, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::multiply ( const int  other  )  [inline]

Multiply all components of this pixel with an integer, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::multiply ( const rgbaPixel other  )  [inline]

Multiply this pixel with another one.

The pixel multiplication multiplies elementwise the elements of the pixel, except the alpha channel, which is kept unchanged.

bool cvr::rgbaPixel::operator!= ( const rgbaPixel other  )  const [inline]

Alias for !compare().

Two pixels are equal if all four components (red, green, blue, and alpha) are equal. It is an usual error to leave the alpha channel uninizalized and then compare for equalilty.

rgbaPixel cvr::rgbaPixel::operator* ( const double &  other  )  const [inline]

Multiply all components of this pixel with a a double, except the alpha channel.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator* ( const float &  other  )  const [inline]

Multiply all components of this pixel with a a float, except the alpha channel.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator* ( const int  other  )  const [inline]

Multiply all components of this pixel with a an integer, except the alpha channel.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator* ( const rgbaPixel other  )  const [inline]

Multiply this pixel with another one without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel& cvr::rgbaPixel::operator*= ( const double &  other  )  [inline]

Multiply all components of this pixel with a a double, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::operator*= ( const float &  other  )  [inline]

Multiply all components of this pixel with a a float, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::operator*= ( const int  other  )  [inline]

Multiply all components of this pixel with a an integer, except the alpha channel, which is kept unchanged.

rgbaPixel& cvr::rgbaPixel::operator*= ( const rgbaPixel other  )  [inline]

Multiply this pixel with another one.

The pixel multiplication multiplies elementwise the elements of the pixel, except the alpha channel, which is kept unchanged.

rgbaPixel cvr::rgbaPixel::operator+ ( const rgbaPixel other  )  const [inline]

Add this pixel with the other one without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel& cvr::rgbaPixel::operator+= ( const rgbaPixel other  )  [inline]

Add this pixel with another one.

The alpha channel is kept unchanged.

rgbaPixel cvr::rgbaPixel::operator- ( const rgbaPixel other  )  const [inline]

Subtract 'other' from this pixel without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel& cvr::rgbaPixel::operator-= ( const rgbaPixel other  )  [inline]

Subtract 'other' from this pixel.

The alpha channel is kept unchanged.

rgbaPixel cvr::rgbaPixel::operator/ ( const double &  other  )  const [inline]

Divide all components of this pixel with an integer without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator/ ( const float &  other  )  const [inline]

Divide all components of this pixel with an integer without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator/ ( const int  other  )  const [inline]

Divide all components of this pixel with an integer without altering anything.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel cvr::rgbaPixel::operator/ ( const rgbaPixel other  )  const [inline]

Divide this pixel with another one.

The pixel division divides elementwise the elements of the pixel except the alpha channel.

The alpha channel of the resulting pixel is equal to the one of this pixel (the first operand in the binary expression)

rgbaPixel& cvr::rgbaPixel::operator/= ( const double &  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::operator/= ( const float &  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::operator/= ( const int  other  )  [inline]

Divide all components of this pixel with an integer.

rgbaPixel& cvr::rgbaPixel::operator/= ( const rgbaPixel other  )  [inline]

Divide this pixel with another one.

The pixel division divides elementwise the elements of the pixel except the alpha channel, which is kept unchanged.

bool cvr::rgbaPixel::operator< ( const rgbaPixel other  )  const [inline]

Less than operator.

An rgbaPixel is said to be "smaller" than another one, if getValue() < other.getValue()

rgbaPixel& cvr::rgbaPixel::operator= ( const rgbaPixel other  )  [inline]

Alias for copy.

bool cvr::rgbaPixel::operator== ( const rgbaPixel other  )  const [inline]

Alias for compare().

Two pixels are equal if all four components (red, green, blue, and alpha) are equal. It is an usual error to leave the alpha channel uninizalized and then compare for equalilty.

bool cvr::rgbaPixel::operator> ( const rgbaPixel other  )  const [inline]

Less than operator.

An rgbaPixel is said to be "bigger" than another one, if getValue() > other.getValue()

const ubyte& cvr::rgbaPixel::operator[] ( const int  x  )  const [inline]

Used to simulate read-only vector access.

The correspondence between the elements of the vector and the color components still depents on the endianness of the system, but is usually [0] for red, [1] for green and [2] for blue.

ubyte& cvr::rgbaPixel::operator[] ( const int  x  )  [inline]

Used to simulate vector access.

The correspondence between the elements of the vector and the color components is [0] for red, [1] for green and [2] for blue.

rgbaPixel& cvr::rgbaPixel::overlay ( const rgbaPixel above,
const rgbaPixel below 
) [inline]

Overlay the first pixel on the second pixel.

The current pixel will be computed considering the "transparency" given in the alpha channel of the first pixel.

This pixel will be equal to the first one multiplied by (1.0-alpha/255) plus the other pixel multiplied by (alpha/255). The new alpha value is equal to the product of the alpha values of the other pixels divided by 255.

rgbaPixel& cvr::rgbaPixel::overlay ( const rgbaPixel below  )  [inline]

Overlay the current pixel on the given one.

The current pixel will be altered considering the "transparency" given in the alpha channel.

The new pixel will be equal to the current one multiplied by (1.0-alpha/255) plus the other pixel multiplied by (alpha/255). The new alpha value is equal to the product of both alpha values divided by 255.

void cvr::rgbaPixel::set ( const ubyte  r,
const ubyte  g,
const ubyte  blue 
) [inline]

Set the red, green, blue values for the pixel.

void cvr::rgbaPixel::set ( const ubyte  r,
const ubyte  g,
const ubyte  b,
const ubyte  a 
) [inline]

Set the red, green, blue and alpha values for the pixel.

void cvr::rgbaPixel::setAlpha ( const ubyte  d  )  [inline]

Sets the alpha component to given value.

void cvr::rgbaPixel::setBlue ( const ubyte  b  )  [inline]

Sets the blue component to given value.

void cvr::rgbaPixel::setGreen ( const ubyte  g  )  [inline]

Sets the green component to given value.

void cvr::rgbaPixel::setRed ( const ubyte  r  )  [inline]

Sets the red component to given value.

void cvr::rgbaPixel::setValue ( const uint32 v  )  [inline]

Sets the value component (all components together) to given value.

size_type cvr::rgbaPixel::size (  )  const [inline]

Used to simulate the vector size.

It returns always 3.

rgbaPixel& cvr::rgbaPixel::subtract ( const rgbaPixel other  )  [inline]

Subtract 'other' from this pixel.

The alpha channel is kept unchanged.


Member Data Documentation

union { ... }

Anonymous union to provide efficient access through three different mechanism to the pixel components.

The order of the data in this union assumes little endianness.

Alpha channel.

This value can be considered proportional to transparency. 255 means fully transparent, and 0 means a solid color.

Blue channel.

The four values as array.

Green channel.

Red channel.

All three channels (and the alpha channel) together.


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:09:08 2009 for CVR-Lib by Doxygen 1.5.8