MColor Class Reference

#include <MColor.h>

Class Description

A color math class.

This class is used to store values of color attributes. Right now, this class provides no more functionality than the MFltVector class, but it is used because Rendering plans to employ more advanced color models in the future. In these models, colors cannot necessarily be represented as an RGB triple.

+ Examples:

Public Types

enum  MColorType { kRGB, kHSV, kCMY, kCMYK }
 Defines color space. More...
 

Public Member Functions

 MColor ()
 Default class contructor. More...
 
 MColor (const MColor &src)
 Copy contructor. More...
 
 MColor (float rr, float gg, float bb=0.0, float aa=1.0)
 RGB contructor. More...
 
 MColor (const float d[3])
 RGB contructor. More...
 
 MColor (float alpha)
 Alpha contructor. More...
 
 MColor (MColorType colorModel, unsigned char c1, unsigned char c2, unsigned char c3, unsigned char alpha=255U)
 Color space contructor. More...
 
 MColor (MColorType colorModel, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short alpha=65535U)
 Color space contructor. More...
 
 MColor (MColorType colorModel, float c1, float c2, float c3, float alpha=1.0)
 Color space contructor. More...
 
 MColor (MColorType colorModel, double c1, double c2, double c3, double alpha=1.0)
 Color space contructor. More...
 
 ~MColor ()
 Class destructor. More...
 
MColoroperator= (const MColor &src)
 Assignment operator. More...
 
float operator() (unsigned int i) const
 Index operator. More...
 
float operator[] (unsigned int i) const
 Index operator. More...
 
MColoroperator*= (float scalar)
 In place multiply operator. More...
 
MColor operator* (float scalar) const
 Multiply operator. More...
 
MColoroperator*= (const MColor &other)
 In place multiply operator. More...
 
MColor operator* (const MColor &other) const
 Multiply operator. More...
 
MColoroperator/= (float scalar)
 In place divide operator. More...
 
MColor operator/ (float scalar) const
 Divide operator. More...
 
MColoroperator+= (const MColor &other)
 In place add operator. More...
 
MColor operator+ (const MColor &other) const
 Add operator. More...
 
MColor operator- () const
 Unary minus operator. More...
 
MColor operator- (const MColor &other) const
 Substraction operator. More...
 
bool operator== (const MColor &other) const
 Equality operator. More...
 
bool operator!= (const MColor &other) const
 Inequality operator. More...
 
bool get (float d[3]) const
 Color component accessor. More...
 
bool get (MColorType colorModel, float &, float &, float &) const
 Color component accessor. More...
 
bool get (MColorType colorModel, float &, float &, float &, float &alpha) const
 Color component accessor. More...
 
bool set (MColorType colorModel, float, float, float, float alpha=1.0)
 Color component assigment. More...
 
float & operator() (unsigned int i)
 Index operator. NO SCRIPT SUPPORT. More...
 
float & operator[] (unsigned int i)
 Index operator. NO SCRIPT SUPPORT. More...
 

Public Attributes

float r
 The red component of the color.
 
float g
 The green component of the color.
 
float b
 The blue component of the color.
 
float a
 The alpha component of the color.
 

Static Public Attributes

static const MColor kOpaqueBlack
 Opaque black color.
 

Friends

OPENMAYA_EXPORT MColor operator* (float scalar, const MColor &other)
 Multiply operator. NO SCRIPT SUPPORT. More...
 
OPENMAYA_EXPORT std::ostream & operator<< (std::ostream &os, const MColor &c)
 Print operator. NO SCRIPT SUPPORT. More...
 

Member Enumeration Documentation

enum MColorType

Defines color space.

Enumerator
kRGB 

Red, Green, Blue.

kHSV 

Hue, Saturation, Value.

kCMY 

Cyan, Magenta, Yellow.

kCMYK 

Cyan, Magenta, Yellow, Black.

Constructor & Destructor Documentation

MColor ( )
inline

Default class contructor.

Initializes the object to a black opaque color.

MColor ( const MColor src)
inline

Copy contructor.

Create a new color and initialize it to the same values as the given color.

Parameters
[in]srcThe color object to copy.
MColor ( float  rr,
float  gg,
float  bb = 0.0,
float  aa = 1.0 
)
inline

RGB contructor.

Initializes the color with the explicit r, g, b, and a values provided as arguments.

Parameters
[in]rrThe r component of the color.
[in]ggThe g component of the color.
[in]bbThe b component of the color. Defaults to 0.0.
[in]aaThe a component of the color. Defaults to 1.0.
MColor ( const float  d[3])
inline

RGB contructor.

Initializes the color with the explicit red, green and blue values provided in the given float array.

The alpha value will be 1.0: The color is opaque.

Parameters
[in]dThe 3 element array containing the initial red, green, and blue values.
MColor ( float  alpha)
inline

Alpha contructor.

Initializes a black color with transparency.

The r, g, b components are set to 0.

Parameters
[in]alphaThe transparency component of the color.
MColor ( MColor::MColorType  colorModel,
unsigned char  c1,
unsigned char  c2,
unsigned char  c3,
unsigned char  alpha = 255U 
)

Color space contructor.

Initializes the color with the given color model using unsigned int data in range [0-255].

Parameters
[in]colorModelThe color model.
[in]c1First component of color.
[in]c2Second component of color.
[in]c3Third component of color.
[in]alphaTransparency. Defaults to opaque (255).
MColor ( MColor::MColorType  colorModel,
unsigned short  c1,
unsigned short  c2,
unsigned short  c3,
unsigned short  alpha = 65535U 
)

Color space contructor.

Initializes the color with the given color model using unsigned int data in range [0-65535].

Parameters
[in]colorModelThe color model.
[in]c1First component of color.
[in]c2Second component of color.
[in]c3Third component of color.
[in]alphaTransparency. Defaults to opaque (65535).
MColor ( MColor::MColorType  colorModel,
float  c1,
float  c2,
float  c3,
float  alpha = 1.0 
)

Color space contructor.

Initializes the color with the given color model using float data in range [0-1.0].

Parameters
[in]colorModelThe color model.
[in]c1First component of color.
[in]c2Second component of color.
[in]c3Third component of color.
[in]alphaTransparency. Defaults to opaque (1.0).
MColor ( MColor::MColorType  colorModel,
double  c1,
double  c2,
double  c3,
double  alpha = 1.0 
)

Color space contructor.

Class constructor.

Initializes the color with the given color model using double precision data in range [0-1.0].

Parameters
[in]colorModelThe color model.
[in]c1First component of color.
[in]c2Second component of color.
[in]c3Third component of color.
[in]alphaTransparency. Defaults to opaque (1.0).
~MColor ( )

Class destructor.

Deallocates the memory.

Member Function Documentation

MColor & operator= ( const MColor src)
inline

Assignment operator.

Copies a color.

Parameters
[in]srcThe color object to copy.
Returns
A reference to the object whose value was set.
float operator() ( unsigned int  i) const
inline

Index operator.

Accessor to one component of the color.

Parameters
[in]iValue indicating which component to return.
Returns
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
float operator[] ( unsigned int  i) const
inline

Index operator.

Accessor to one component of the color.

Parameters
[in]iValue indicating which component to return.
Returns
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
MColor & operator*= ( float  scalar)

In place multiply operator.

Parameters
[in]scalarColor multiplication factor.
Returns
A reference to the color object which was modified.
MColor operator* ( float  scalar) const

Multiply operator.

Parameters
[in]scalarColor multiplication factor.
Returns
A new MColor object representing the product of the original MColor with the scalar value.
MColor & operator*= ( const MColor other)

In place multiply operator.

Performs a componentwise multiplication of two colors.

Parameters
[in]otherColor to be multiplied with this color.
Returns
A reference to the color whose value was modified.
MColor operator* ( const MColor other) const

Multiply operator.

Performs a componentwise multiplication of two colors.

Parameters
[in]otherColor to be multiplied with this color.
Returns
A new MColor object representing the product of the two colors.
MColor & operator/= ( float  scalar)

In place divide operator.

Parameters
[in]scalarColor division factor.
Returns
A reference to the color whose value was modified.
MColor operator/ ( float  scalar) const

Divide operator.

Parameters
[in]scalarColor division factor.
Returns
A new MColor object representing the color divided by the scalar.
MColor & operator+= ( const MColor other)

In place add operator.

Parameters
[in]otherColor to be added to this color.
Returns
A reference to the color whose value was modified.
MColor operator+ ( const MColor other) const

Add operator.

Parameters
[in]otherColor to be added to this color.
Returns
A new MColor object representing the sum of this color and the specified color.
MColor operator- ( ) const

Unary minus operator.

Negates the value of each of the red, green and blue components of the color.

Transparency is set to opaque.

Returns
The negated color.
MColor operator- ( const MColor other) const

Substraction operator.

Parameters
[in]otherColor to be subtracted from this color.
Returns
A new MColor object representing this color minus the specified other color.
bool operator== ( const MColor other) const

Equality operator.

Compares the r, g, and b components of two color.

Parameters
[in]otherColor to which this color will be compared.
Returns
A bool value:
  • true if the colors are identical
  • false otherwise
bool operator!= ( const MColor other) const

Inequality operator.

Compares the r, g, and b components of two color.

Parameters
[in]otherColor to which this color will be compared.
Returns
A bool value:
  • false if the colors are identical
  • true otherwise
bool get ( float  d[3]) const
inline

Color component accessor.

Extracts the r, g, and b components of the color and places them in elements 0, 1, and 2 of the float array passed.

Parameters
[out]dThe array of 3 floats into which the results are placed.
Returns
Always returns bool true.
+ Examples:
bool get ( MColor::MColorType  colorModel,
float &  c1,
float &  c2,
float &  c3 
) const

Color component accessor.

Retrieves the values of 3 components of the color using the specified color model.

Parameters
[in]colorModelThe color model.
[out]c1Storage for the first component of color.
[out]c2Storage for the second component of color.
[out]c3Storage for the third component of color.
Returns
Always returns bool true.
bool get ( MColor::MColorType  colorModel,
float &  c1,
float &  c2,
float &  c3,
float &  alpha 
) const

Color component accessor.

Retrieves the values of 4 components of the color using the specified color model.

Parameters
[in]colorModelThe color model.
[out]c1Storage for the first component of color.
[out]c2Storage for the second component of color.
[out]c3Storage for the third component of color.
[out]alphaStorage for the alpha component of color.
Returns
Always returns bool true.
bool set ( MColor::MColorType  colorModel,
float  c1,
float  c2,
float  c3,
float  alpha = 1.0 
)

Color component assigment.

Sets the values of the color components using the specified color model.

Parameters
[in]colorModelThe color model.
[in]c1First component of color.
[in]c2Second component of color.
[in]c3Third component of color.
[in]alphaAlpha component of color.
Returns
Always returns bool true.
+ Examples:
float & operator() ( unsigned int  i)
inline

Index operator. NO SCRIPT SUPPORT.

Accessor to one component of the color.

Parameters
[in]iValue indicating which component to return.
Returns
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.
float & operator[] ( unsigned int  i)
inline

Index operator. NO SCRIPT SUPPORT.

Accessor to one component of the color.

Parameters
[in]iValue indicating which component to return.
Returns
A reference to the appropriate component of the color:
  • Reference to the red channel when argument is 0.
  • Reference to the green channel when argument is 1.
  • Reference to the blue channel when argument is 2.
  • Reference to the alpha channel otherwise.

Friends And Related Function Documentation

OPENMAYA_EXPORT MColor operator* ( float  scalar,
const MColor other 
)
friend

Multiply operator. NO SCRIPT SUPPORT.

Parameters
[in]scalarColor multiplication factor.
[in]otherColor object to be multiplied.
Returns
A new MColor object representing the product of the specified scalar and color.
OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  os,
const MColor c 
)
friend

Print operator. NO SCRIPT SUPPORT.

The format used is [r, g, b, a].

Parameters
[in]osThe ostream to print to.
[in]cThe MColor whose value is to be printed.
Returns
The ostream reference, os, provided as the first parameter.

The documentation for this class was generated from the following files:
  • MColor.h
  • MColor.cpp