Color Functions Manual

About

Along with the ColorSwatchData and ColorSwatchGroup types these utility functions were introduced to handle colors. The functions are defined in the lib_colorchooser.h header file.

String Conversion

These functions convert a given RGB color value to a formatted String:

// This example reads the color parameter of the given material
// and prints the value as RGB and HSV.
// access MATERIAL_COLOR_COLOR parameter
GeData data;
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const Vector color = data.GetVector();
const String rgbString = ColorRGBToString(color);
const String hsvString = ColorHSVToString(color);
ApplicationOutput("Material Color: RGB " + rgbString + ", HSV " + hsvString);

Color Format Conversion

The following functions allow easy conversion of colors stored in different formats.

These functions convert float colors (0.0 ... 1.0) to 8-bit colors (0 .. 255):

These functions convert float colors (0.0 ... 1.0) to 16-bit colors (0 .. 65536):

Also, a Kelvin color temperature can be converted:

// This example calculates a RGB value from a light temperature
// and applies it to the given "Light" object.
const Float kelvin = 2600.0; // light bulb
const Vector rgb = ColorKelvinTemperatureToRGB(kelvin);
light->SetParameter(LIGHT_COLOR, rgb, DESCFLAGS_SET::NONE);

Color Harmony

These functions are used to calculate color palettes based on the given input color.

Note
The output maxon::BaseArray contains also the original color.
// This example reads the color value from the given material.
// The complementary color is calculated and applied to a new material.
// access MATERIAL_COLOR_COLOR parameter
GeData data;
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// the original color
const Vector color = data.GetVector();
// calculate the complementary color
if (!ColorHarmonyGetComplementary(color, false, results))
return maxon::UnknownError(MAXON_SOURCE_LOCATION);
// check if the result contains both the original and complementary color
if (results.GetCount() != 2)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// get the result color
const Vector complementaryColor = results[1];
// create new material with complementary color
if (newMaterial == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
newMaterial->SetParameter(MATERIAL_COLOR_COLOR, complementaryColor, DESCFLAGS_SET::NONE);
doc->InsertMaterial(newMaterial);

Further Reading

ColorHSVToString
String ColorHSVToString(const Vector &color)
Float
maxon::Float Float
Definition: ge_sys_math.h:66
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
maxon::BaseArray
Definition: basearray.h:411
DESCFLAGS_SET::NONE
@ NONE
None.
String
Definition: c4d_string.h:38
BaseDocument::InsertMaterial
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::BaseArray::GetCount
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Definition: basearray.h:574
maxon::Vec3< maxon::Float64, 1 >
ColorHarmonyGetComplementary
Bool ColorHarmonyGetComplementary(const Vector &color, Bool ryb, maxon::BaseArray< Vector > &palette)
LIGHT_COLOR
@ LIGHT_COLOR
Definition: olight.h:6
GeData
Definition: c4d_gedata.h:82
ColorKelvinTemperatureToRGB
Vector ColorKelvinTemperatureToRGB(Float kelvinDegrees, Float tint=0.0)
ApplicationOutput
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
ColorRGBToString
String ColorRGBToString(const Vector &color)
Mmaterial
#define Mmaterial
Standard material.
Definition: ge_prepass.h:981
BaseMaterial::Alloc
static BaseMaterial * Alloc(Int32 type)
DESCFLAGS_GET::NONE
@ NONE
None.
BaseMaterial
Definition: c4d_basematerial.h:27
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
GeData::GetVector
const Vector & GetVector(void) const
Definition: c4d_gedata.h:451
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
Definition: mmaterial.h:56