last update 20 Sep 2009 |
#include <cvrRGBAPixel.h>
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 ubyte & | getRed () const |
const ubyte & | getGreen () const |
const ubyte & | getBlue () const |
const ubyte & | getAlpha () const |
ubyte & | getRed () |
ubyte & | getGreen () |
ubyte & | getBlue () |
ubyte & | getAlpha () |
const uint32 & | getValue () const |
uint32 & | getValue () |
ubyte & | at (const int x) |
const ubyte & | at (const int x) const |
ubyte & | operator[] (const int x) |
const ubyte & | operator[] (const int x) const |
size_type | size () const |
rgbaPixel & | copy (const rgbaPixel &other) |
rgbaPixel & | operator= (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 |
rgbaPixel & | add (const rgbaPixel &other) |
rgbaPixel & | operator+= (const rgbaPixel &other) |
rgbaPixel | operator+ (const rgbaPixel &other) const |
rgbaPixel & | subtract (const rgbaPixel &other) |
rgbaPixel & | operator-= (const rgbaPixel &other) |
rgbaPixel | operator- (const rgbaPixel &other) const |
rgbaPixel & | multiply (const rgbaPixel &other) |
rgbaPixel & | operator*= (const rgbaPixel &other) |
rgbaPixel | operator* (const rgbaPixel &other) const |
rgbaPixel & | multiply (const int other) |
rgbaPixel & | multiply (const float &other) |
rgbaPixel & | multiply (const double &other) |
rgbaPixel & | operator*= (const int other) |
rgbaPixel & | operator*= (const float &other) |
rgbaPixel & | operator*= (const double &other) |
rgbaPixel | operator* (const int other) const |
rgbaPixel | operator* (const float &other) const |
rgbaPixel | operator* (const double &other) const |
rgbaPixel & | divide (const rgbaPixel &other) |
rgbaPixel & | operator/= (const rgbaPixel &other) |
rgbaPixel | operator/ (const rgbaPixel &other) const |
rgbaPixel & | divide (const int other) |
rgbaPixel & | divide (const float &other) |
rgbaPixel & | divide (const double &other) |
rgbaPixel & | operator/= (const int other) |
rgbaPixel & | operator/= (const float &other) |
rgbaPixel & | operator/= (const double &other) |
rgbaPixel | operator/ (const int other) const |
rgbaPixel | operator/ (const float &other) const |
rgbaPixel | operator/ (const double &other) const |
rgbaPixel & | overlay (const rgbaPixel &below) |
rgbaPixel & | overlay (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] | |
}; |
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.
typedef int cvr::rgbaPixel::size_type |
Return type of the size() member.
typedef ubyte cvr::rgbaPixel::value_type |
Used for the template-based interface for pixels as vectors.
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.
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:
|
RGB constructor.
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) |
int cvr::rgbaPixel::absSqr | ( | ) | const [inline] |
Compute the square of the magnitud of this pixel .
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] |
int cvr::rgbaPixel::distanceSqr | ( | const rgbaPixel & | other | ) | const [inline] |
Square of the distance between this pixel and the other one.
.
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.
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.
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.
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] |
ubyte& cvr::rgbaPixel::getGreen | ( | ) | [inline] |
Returns green component.
const ubyte& cvr::rgbaPixel::getGreen | ( | ) | const [inline] |
ubyte& cvr::rgbaPixel::getRed | ( | ) | [inline] |
Returns red component.
const ubyte& cvr::rgbaPixel::getRed | ( | ) | const [inline] |
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.
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] |
rgbaPixel cvr::rgbaPixel::operator* | ( | const float & | other | ) | const [inline] |
rgbaPixel cvr::rgbaPixel::operator* | ( | const int | 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.
Multiply this pixel with another one.
The pixel multiplication multiplies elementwise the elements of the pixel, except the alpha channel, which is kept unchanged.
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)
Add this pixel with another one.
The alpha channel is kept unchanged.
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)
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 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.
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()
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] |
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.
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.
Set the red, green, blue values for the pixel.
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.
Subtract 'other' from this pixel.
The alpha channel is kept unchanged.
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.
All three channels (and the alpha channel) together.