3ds Max C++ API Reference
Loading...
Searching...
No Matches
Color Class Reference

#include <color.h>

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 (uint32_t 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
 
uint32_t toRGB ()
 
 operator RealPixel () const
 
 operator BMM_Color_24 () const
 
 operator BMM_Color_32 () const
 
 operator BMM_Color_48 () const
 
 operator BMM_Color_64 () const
 
 operator BMM_Color_fl () const
 
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.
 
float g = 0.f
 These values are in the range 0.0 to 1.0.
 
float b = 0.f
 These values are in the range 0.0 to 1.0.
 

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.
 
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.
 

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.
107 {
108 r = R;
109 g = G;
110 b = B;
111 }
float r
These values are in the range 0.0 to 1.0.
Definition: color.h:78
float b
These values are in the range 0.0 to 1.0.
Definition: color.h:82
float g
These values are in the range 0.0 to 1.0.
Definition: color.h:80

◆ 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.
122 {
123 r = (float)R;
124 g = (float)G;
125 b = (float)B;
126 }

◆ 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.
137 {
138 r = (float)R;
139 g = (float)G;
140 b = (float)B;
141 }

◆ Color() [9/17]

Color ( uint32_t  rgb)
explicit
Remarks
Constructor. Initializes the color to the Windows RGB value.
Parameters:
uint32_t 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.
153 {
154 r = p.x;
155 g = p.y;
156 b = p.z;
157 }
float y
Definition: point3.h:57
float x
Definition: point3.h:56
float z
Definition: point3.h:58

◆ 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].
163 {
164 r = af[0];
165 g = af[1];
166 b = af[2];
167 }

◆ 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.
174 {
175 ExpandRealPixel(rp, r, g, b);
176 }
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.
182 {
183 r = float(c.r) / 255.0f;
184 g = float(c.g) / 255.0f;
185 b = float(c.b) / 255.0f;
186 }
uint8_t g
Definition: maxcolors.h:71
uint8_t b
Definition: maxcolors.h:71
uint8_t r
Definition: maxcolors.h:71

◆ 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.
192 {
193 r = float(c.r) / 255.0f;
194 g = float(c.g) / 255.0f;
195 b = float(c.b) / 255.0f;
196 }
uint8_t g
Definition: maxcolors.h:85
uint8_t b
Definition: maxcolors.h:85
uint8_t r
Definition: maxcolors.h:85

◆ 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.
202 {
203 r = float(c.r) / 65535.0f;
204 g = float(c.g) / 65535.0f;
205 b = float(c.b) / 65535.0f;
206 }
uint16_t b
Definition: maxcolors.h:98
uint16_t r
Definition: maxcolors.h:98
uint16_t g
Definition: maxcolors.h:98

◆ 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.
212 {
213 r = float(c.r) / 65535.0f;
214 g = float(c.g) / 65535.0f;
215 b = float(c.b) / 65535.0f;
216 }
uint16_t b
Definition: maxcolors.h:112
uint16_t r
Definition: maxcolors.h:112
uint16_t g
Definition: maxcolors.h:112

◆ 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.
223 {
224 r = c.r;
225 g = c.g;
226 b = c.b;
227 }
float r
Storage for the floating point color information.
Definition: maxcolors.h:128
float b
Definition: maxcolors.h:128
float g
Definition: maxcolors.h:128

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
232 {
233 r = g = b = 0.0f;
234 }

◆ White()

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

◆ 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.
255 {
256 return (&r)[i];
257 }

◆ 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.
264 {
265 return (&r)[i];
266 }

◆ 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.
272 {
273 return (&r);
274 }

◆ operator const float *()

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

◆ toRGB()

uint32_t toRGB ( )
inline
283 {
284 return MAX_RGB(FLto255(r), FLto255(g), FLto255(b));
285 };
#define FLto255(x)
Definition: color.h:21
#define MAX_RGB(r, g, b)
Definition: color.h:23

◆ operator RealPixel()

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

◆ operator BMM_Color_24()

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

◆ operator BMM_Color_32()

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

◆ operator BMM_Color_48()

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

◆ operator BMM_Color_64()

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

◆ operator BMM_Color_fl()

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

◆ operator-() [1/2]

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

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

◆ operator+() [1/2]

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

◆ operator-=()

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

◆ operator+=()

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

◆ 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.
486{
487 r *= f;
488 g *= f;
489 b *= f;
490 return *this;
491}

◆ operator/=()

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

◆ 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.
502{
503 r *= a.r;
504 g *= a.g;
505 b *= a.b;
506 return *this;
507}

◆ operator==()

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

◆ 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.
380 {
381 return ((p.r != r) || (p.g != g) || (p.b != b));
382 }

◆ 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.
510{
511 return (Color(r - c.r, g - c.g, b - c.b));
512}

◆ 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.
515{
516 return (Color(r + c.r, g + c.g, b + c.b));
517}

◆ 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.
520{
521 return Color(r / c.r, g / c.g, b / c.b);
522}

◆ 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.
525{
526 return Color(r * c.r, g * c.g, b * c.b);
527}

◆ operator^()

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

◆ 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.