3ds Max C++ API Reference
Color Class Reference

#include <color.h>

+ Inheritance diagram for Color:

Public Member Functions

 Color ()=default
 
 Color (const Color &)=default
 
 Color (Color &&)=default
 
Coloroperator= (const Color &)=default
 
Coloroperator= (Color &&)=default
 
 Color (const AColor &c)
 
 Color (AColor &&c)
 
 Color (float R, float G, float B)
 
 Color (double R, double G, double B)
 
 Color (int R, int G, int B)
 
 Color (DWORD rgb)
 
 Color (const Point3 &p)
 
 Color (float af[3])
 
 Color (RealPixel rp)
 
 Color (const BMM_Color_24 &c)
 
 Color (const BMM_Color_32 &c)
 
 Color (const BMM_Color_48 &c)
 
 Color (const BMM_Color_64 &c)
 
 Color (const BMM_Color_fl &c)
 
void Black ()
 
void White ()
 
void ClampMax ()
 
void ClampMin ()
 
void ClampMinMax ()
 
float & operator[] (int i)
 
const float & operator[] (int i) const
 
 operator float * ()
 
 operator const float * () const
 
DWORD toRGB ()
 
 operator RealPixel ()
 
 operator BMM_Color_24 ()
 
 operator BMM_Color_32 ()
 
 operator BMM_Color_48 ()
 
 operator BMM_Color_64 ()
 
 operator BMM_Color_fl ()
 
Color operator- () const
 
Color operator+ () const
 
Coloroperator-= (const Color &)
 
Coloroperator+= (const Color &)
 
Coloroperator*= (float)
 
Coloroperator/= (float)
 
Coloroperator*= (const Color &)
 
int operator== (const Color &p) const
 
int operator!= (const Color &p) const
 
Color operator- (const Color &) const
 
Color operator+ (const Color &) const
 
Color operator/ (const Color &) const
 
Color operator* (const Color &) const
 
Color operator^ (const Color &) const
 

Public Attributes

float r = 0.f
 These values are in the range 0.0 to 1.0. More...
 
float g = 0.f
 These values are in the range 0.0 to 1.0. More...
 
float b = 0.f
 These values are in the range 0.0 to 1.0. More...
 

Kelvin temperature, black body

float FindClosestMatchingKelvinTemperature () const
 Finds the kelvin temperature which, when converted to RGB, would generate the closest possible color to the current RGB value. More...
 
static Color FromKelvinTemperature (const float kelvin_temperature, const float intensity=1.0f)
 Calculates the chromacity of a black body radiator at a given temperature in kelvins. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

See also
Class AColor, Structure BMM_Color_24, Structure BMM_Color_32, Structure BMM_Color_48, Structure BMM_Color_64, Structure BMM_Color_fl, Structure RealPixel.

Description:
This class represents color as three floating point values: r, g, and b. All methods of this class are implemented by the system.
Data Members:
float r,g,b;

These values are in the range 0.0 to 1.0.

Constructor & Destructor Documentation

◆ Color() [1/17]

Color ( )
default
Remarks
Constructor. The resulting object should be initialized with one of the initialization methods.

◆ Color() [2/17]

Color ( const Color )
default

◆ Color() [3/17]

Color ( Color &&  )
default

◆ Color() [4/17]

Color ( const AColor c)

◆ Color() [5/17]

Color ( AColor &&  c)

◆ Color() [6/17]

Color ( float  R,
float  G,
float  B 
)
inline
Remarks
Constructor. Initializes the Color to the RGB color values passed.
Parameters:
float R

Specifies the red component of the color.

float G

Specifies the green component of the color.

float B

Specifies the blue component of the color.
108  {
109  r = R;
110  g = G;
111  b = B;
112  }
float r
These values are in the range 0.0 to 1.0.
Definition: color.h:79
float b
These values are in the range 0.0 to 1.0.
Definition: color.h:83
float g
These values are in the range 0.0 to 1.0.
Definition: color.h:81

◆ Color() [7/17]

Color ( double  R,
double  G,
double  B 
)
inline
Remarks
Constructor. Initializes the Color to the RGB color values passed.
Parameters:
double R

Specifies the red component of the color.

double G

Specifies the green component of the color.

double B

Specifies the blue component of the color.
123  {
124  r = (float)R;
125  g = (float)G;
126  b = (float)B;
127  }

◆ Color() [8/17]

Color ( int  R,
int  G,
int  B 
)
inline
Remarks
Constructor. Initializes the Color to the RGB color values passed.
Parameters:
int R

Specifies the red component of the color.

int G

Specifies the green component of the color.

int B

Specifies the blue component of the color.
138  {
139  r = (float)R;
140  g = (float)G;
141  b = (float)B;
142  }

◆ Color() [9/17]

Color ( DWORD  rgb)
explicit
Remarks
Constructor. Initializes the color to the Windows RGB value.
Parameters:
DWORD rgb

Specifies the initial color via a Windows RGB value.

◆ Color() [10/17]

Color ( const Point3 p)
inline
Remarks
Constructor. Initializes the Color to the value of the Point3 passed.
Parameters:
Point3 p

Specifies the color. r=x, g=y, b=z.
154  {
155  r = p.x;
156  g = p.y;
157  b = p.z;
158  }
float y
Definition: point3.h:61
float x
Definition: point3.h:60
float z
Definition: point3.h:62

◆ Color() [11/17]

Color ( float  af[3])
inlineexplicit
Remarks
Constructor. Initializes the color to the value passed.
Parameters:
float af[3]

Specifies the color. r=af[0], g=af[1], b=af[2].
164  {
165  r = af[0];
166  g = af[1];
167  b = af[2];
168  }

◆ Color() [12/17]

Color ( RealPixel  rp)
inlineexplicit
Remarks
Constructor. Initializes the color to the RealPixel structure passed.
Parameters:
RealPixel rp

Specifies the RealPixel format to convert.
175  {
176  ExpandRealPixel(rp, r, g, b);
177  }
void ExpandRealPixel(const RealPixel &rp, float &r, float &g, float &b)

◆ Color() [13/17]

Color ( const BMM_Color_24 c)
inline
Remarks
Constructor. Initializes this Color from the 24 bit color value passed.
Parameters:
const BMM_Color_24& c

The 24 bit color to initialize from.
183  {
184  r = float(c.r) / 255.0f;
185  g = float(c.g) / 255.0f;
186  b = float(c.b) / 255.0f;
187  }
uint8_t g
Definition: maxtypes.h:67
uint8_t b
Definition: maxtypes.h:67
uint8_t r
Definition: maxtypes.h:67

◆ Color() [14/17]

Color ( const BMM_Color_32 c)
inline
Remarks
Constructor. Initializes this Color from the 32 bit color value passed.
Parameters:
const BMM_Color_32& c

The 32 bit color to initialize from.
193  {
194  r = float(c.r) / 255.0f;
195  g = float(c.g) / 255.0f;
196  b = float(c.b) / 255.0f;
197  }
uint8_t g
Definition: maxtypes.h:75
uint8_t b
Definition: maxtypes.h:75
uint8_t r
Definition: maxtypes.h:75

◆ Color() [15/17]

Color ( const BMM_Color_48 c)
inline
Remarks
Constructor. Initializes this Color from the 48 bit color value passed.
Parameters:
const BMM_Color_48& c

The 48 bit color to initialize from.
203  {
204  r = float(c.r) / 65535.0f;
205  g = float(c.g) / 65535.0f;
206  b = float(c.b) / 65535.0f;
207  }
uint16_t b
Definition: maxtypes.h:83
uint16_t r
Definition: maxtypes.h:83
uint16_t g
Definition: maxtypes.h:83

◆ Color() [16/17]

Color ( const BMM_Color_64 c)
inline
Remarks
Constructor. Initializes this Color from the 64 bit color value passed.
Parameters:
const BMM_Color_64& c

The 64 bit color to initialize from.
213  {
214  r = float(c.r) / 65535.0f;
215  g = float(c.g) / 65535.0f;
216  b = float(c.b) / 65535.0f;
217  }
uint16_t b
Definition: maxtypes.h:91
uint16_t r
Definition: maxtypes.h:91
uint16_t g
Definition: maxtypes.h:91

◆ Color() [17/17]

Color ( const BMM_Color_fl c)
inline
Remarks
Constructor. Initializes this Color from the floating point color passed.
Parameters:
const BMM_Color_fl& c

The floating point color to initialize from. No conversion or scaling is done.
224  {
225  r = c.r;
226  g = c.g;
227  b = c.b;
228  }
float r
Storage for the floating point color information.
Definition: maxtypes.h:101
float b
Definition: maxtypes.h:101
float g
Definition: maxtypes.h:101

Member Function Documentation

◆ operator=() [1/2]

Color& operator= ( const Color )
default

◆ operator=() [2/2]

Color& operator= ( Color &&  )
default

◆ Black()

void Black ( )
inline
Remarks
Sets the Color to black. r = g = b = 0.0f
233  {
234  r = g = b = 0.0f;
235  }

◆ White()

void White ( )
inline
Remarks
Sets the Color to white. r = g = b = 1.0f
238  {
239  r = g = b = 1.0f;
240  }

◆ ClampMax()

void ClampMax ( )
Remarks
Makes all the components of the Color <= 1.0

◆ ClampMin()

void ClampMin ( )
Remarks
Makes all the components of the Color >= 0.0

◆ ClampMinMax()

void ClampMinMax ( )
Remarks
Makes all the components fall in the range [0,1]

◆ operator[]() [1/2]

float& operator[] ( int  i)
inline
Remarks
Access operator.
Parameters:
int i

The index of the component to return.
Returns
0=r, 1=g, 2=b.
256  {
257  return (&r)[i];
258  }

◆ operator[]() [2/2]

const float& operator[] ( int  i) const
inline
Remarks
Access operator.
Parameters:
int i

The index of the component to return.
Returns
0=r, 1=g, 2=b.
265  {
266  return (&r)[i];
267  }

◆ operator float *()

operator float * ( )
inline
Remarks
Returns a pointer to the red component of the color. This may be used to treat the Color as an array of three floats.
273  {
274  return (&r);
275  }

◆ operator const float *()

operator const float * ( ) const
inline
277  {
278  return (&r);
279  }

◆ toRGB()

DWORD toRGB ( )
inline
284  {
285  return RGB(FLto255(r), FLto255(g), FLto255(b));
286  };
#define FLto255(x)
Definition: color.h:24

◆ operator RealPixel()

operator RealPixel ( )
Remarks
Convert the Color to the RealPixel format.

◆ operator BMM_Color_24()

operator BMM_Color_24 ( )
inline
Remarks
Converts this Color to the BMM_Color_24 format.
295  {
296  BMM_Color_24 c;
297  c.r = (BYTE) int(r * 255.0f);
298  c.g = (BYTE) int(g * 255.0f);
299  c.b = (BYTE) int(b * 255.0f);
300  return c;
301  }
24 bit color: 8 bits each for Red, Green, and Blue.
Definition: maxtypes.h:65

◆ operator BMM_Color_32()

operator BMM_Color_32 ( )
inline
Remarks
Converts this Color to the BMM_Color_32 format.
304  {
305  BMM_Color_32 c;
306  c.r = (BYTE) int(r * 255.0f);
307  c.g = (BYTE) int(g * 255.0f);
308  c.b = (BYTE) int(b * 255.0f);
309  return c;
310  }
32 bit color: 8 bits each for Red, Green, Blue, and Alpha.
Definition: maxtypes.h:73

◆ operator BMM_Color_48()

operator BMM_Color_48 ( )
inline
Remarks
Converts this Color to the BMM_Color_48 format.
313  {
314  BMM_Color_48 c;
315  c.r = (WORD) int(r * 65535.0f);
316  c.g = (WORD) int(g * 65535.0f);
317  c.b = (WORD) int(b * 65535.0f);
318  return c;
319  }
48 bit color: 16 bits each for Red, Green, and Blue.
Definition: maxtypes.h:81

◆ operator BMM_Color_64()

operator BMM_Color_64 ( )
inline
Remarks
Converts this Color to the BMM_Color_64 format.
322  {
323  BMM_Color_64 c;
324  c.r = (WORD) int(r * 65535.0f);
325  c.g = (WORD) int(g * 65535.0f);
326  c.b = (WORD) int(b * 65535.0f);
327  return c;
328  }
64 bit color: 16 bits each for Red, Green, Blue, and Alpha.
Definition: maxtypes.h:89

◆ operator BMM_Color_fl()

operator BMM_Color_fl ( )
inline
Remarks
Converts this Color to the BMM_Color_fl format.
331  {
332  BMM_Color_fl c;
333  c.r = r;
334  c.g = g;
335  c.b = b;
336  return c;
337  }
High Dynamic Range bitmaps make use of this class to store color information using floating point val...
Definition: maxtypes.h:97

◆ operator-() [1/2]

Color operator- ( ) const
inline
Remarks
Unary - operator.
Returns
The Color with the components negated, i.e.

{ return(Color(-r,-g,-b)); }
344  {
345  return (Color(-r, -g, -b));
346  }
Color()=default

◆ operator+() [1/2]

Color operator+ ( ) const
inline
Remarks
Unary + operator.
Returns
The Color itself.
350  {
351  return *this;
352  }

◆ operator-=()

Color & operator-= ( const Color a)
inline
Remarks
Subtracts a Color from this Color.
Returns
A Color that is the difference between two Colors.
471 {
472  r -= a.r;
473  g -= a.g;
474  b -= a.b;
475  return *this;
476 }

◆ operator+=()

Color & operator+= ( const Color a)
inline
Remarks
Adds a Color to this Color.
Returns
A Color that is the sum of two Colors.
479 {
480  r += a.r;
481  g += a.g;
482  b += a.b;
483  return *this;
484 }

◆ operator*=() [1/2]

Color & operator*= ( float  f)
inline
Remarks
Multiplies the components of this Color by a float.
Returns
A Color multiplied by a float.
487 {
488  r *= f;
489  g *= f;
490  b *= f;
491  return *this;
492 }

◆ operator/=()

Color & operator/= ( float  f)
inline
Remarks
Divides the components of a Color by a float.
Returns
A Color divided by a float.
495 {
496  r /= f;
497  g /= f;
498  b /= f;
499  return *this;
500 }

◆ operator*=() [2/2]

Color & operator*= ( const Color a)
inline
Remarks
Performs element-by-element multiplying between two Colors.
Returns
A Color element-by-element multiplied by another Color.
503 {
504  r *= a.r;
505  g *= a.g;
506  b *= a.b;
507  return *this;
508 }

◆ operator==()

int operator== ( const Color p) const
inline
Remarks
Test for equality between two Colors.
Returns
Nonzero if the Colors are equal; otherwise 0.
375  {
376  return ((p.r == r) && (p.g == g) && (p.b == b));
377  }

◆ operator!=()

int operator!= ( const Color p) const
inline
Remarks
Tests for inequality between two Colors.
Returns
Nonzero if the Colors are not equal; otherwise 0.
381  {
382  return ((p.r != r) || (p.g != g) || (p.b != b));
383  }

◆ operator-() [2/2]

Color operator- ( const Color c) const
inline
Remarks
Subtracts a Color from a Color.
Returns
A Color that is the difference between two Colors.
511 {
512  return (Color(r - c.r, g - c.g, b - c.b));
513 }

◆ operator+() [2/2]

Color operator+ ( const Color c) const
inline
Remarks
Adds a Color to a Color.
Returns
A Color that is the difference between two Colors.
516 {
517  return (Color(r + c.r, g + c.g, b + c.b));
518 }

◆ operator/()

Color operator/ ( const Color c) const
inline
Remarks
Divides a Color by a Color.
Returns
A Color divided by a Color. r/r, g/g, b/b.
521 {
522  return Color(r / c.r, g / c.g, b / c.b);
523 }

◆ operator*()

Color operator* ( const Color c) const
inline
Remarks
Multiplies a Color by a Color.
Returns
A Color multiplied by a Color. r*r, g*g, b*b.
526 {
527  return Color(r * c.r, g * c.g, b * c.b);
528 }

◆ operator^()

Color operator^ ( const Color c) const
inline
531 {
532  return Color(g * c.b - b * c.g, b * c.r - r * c.b, r * c.g - g * c.r);
533 }

◆ FromKelvinTemperature()

static Color FromKelvinTemperature ( const float  kelvin_temperature,
const float  intensity = 1.0f 
)
static

Calculates the chromacity of a black body radiator at a given temperature in kelvins.

Parameters
kelvin_temperatureThe black body temperature in kelvins.
intensityThe intensity of the color to be generated (the luminance Y of the CIE XYZ color from which the RGB color is converted).
Returns
An RGB value, converted from a CIE XYZ color with the calculated chromacity and provided intensity.
Remarks
The returned color components is guaranteed to have positive values, but may exceed 1.0.

◆ FindClosestMatchingKelvinTemperature()

float FindClosestMatchingKelvinTemperature ( ) const

Finds the kelvin temperature which, when converted to RGB, would generate the closest possible color to the current RGB value.

For a color that was generated from a kelvin temperature, the returned value should match that temperature exactly. But for an arbitrary color, the returned value will only be an approximation (and may vary wildly if the color is very far from the set of valid black body colors).

Returns
The temperature, in kelvins, which would generate the closest matching color to 'this'.
Remarks
This performs a search through the range of valid color temperatures, and may therefore be a bit expensive.

Member Data Documentation

◆ r

float r = 0.f

These values are in the range 0.0 to 1.0.

◆ g

float g = 0.f

These values are in the range 0.0 to 1.0.

◆ b

float b = 0.f

These values are in the range 0.0 to 1.0.