RenderManAPI  24.0
RixColorUtils.h File Reference
#include <unordered_map>
#include <string>
#include "RixShadingUtils.h"
#include "pxrcore/ustring/ustring.h"

Go to the source code of this file.

Macros

#define F_LOGDOTFIVE   (-0.30102999566f)
 
#define F_INVLOGDOTFIVE   (-3.32192809489f)
 
#define IFLOOR(x)   (((x) < 0.0f && (x) != (int)(x)) ? (int)x - 1 : (int)x)
 

Enumerations

enum  RixColorSpace {
  k_sRGB = 0, k_Rec709, k_Rec2020, k_DCI_P3,
  k_Alexa_wide, k_ACEScg, k_CinemaGamut, k_NTSC,
  k_numColorSpaces
}
 
enum  RenderColorSpace { kScene =-1, kRec709 =0, kACEScg =1, kNumColorSpaces }
 

Functions

PRMAN_INLINE RtColorRGB RixToColorSpace (const RenderColorSpace &from, const RenderColorSpace &to, const RtColorRGB &rgb)
 
PRMAN_INLINE RenderColorSpace RixGetSceneColorSpace (RixContext const &ctx)
 
PRMAN_INLINE void RixHsvToRgb (RtColorRGB const &hsv, RtColorRGB &rgb)
 
PRMAN_INLINE void RixRgbToHsv (RtColorRGB const &rgb, RtColorRGB &hsv)
 
PRMAN_INLINE float rixValue (float n1, float n2, float hue)
 
PRMAN_INLINE void RixHslToRgb (RtColorRGB const &hsl, RtColorRGB &rgb)
 
PRMAN_INLINE void RixRgbToHsl (RtColorRGB const &rgb, RtColorRGB &hsl)
 
PRMAN_INLINE void RixXyzToRgb (RtColorRGB const &xyz, RtColorRGB &rgb, RixColorSpace cs=k_sRGB)
 
PRMAN_INLINE void RixRgbToXyz (RtColorRGB const &rgb, RtColorRGB &xyz, RixColorSpace cs=k_sRGB)
 
PRMAN_INLINE RtFloat RixInputRange (const RtFloat &f, const RtFloat &min, const RtFloat &max)
 Remap [min, max] to [0.0 to 1.0]. More...
 
PRMAN_INLINE RtColorRGB RixInputRange (const RtColorRGB &rgb, const RtFloat &min, const RtFloat &max)
 Remap [min, max] to [0.0 to 1.0]. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixInputRange (const RtColorRGB &rgb, const T &min, const T &max)
 Remap [min, max] to [0.0 to 1.0]. More...
 
PRMAN_INLINE RtFloat RixOutputRange (const RtFloat &f, const RtFloat &min, const RtFloat &max)
 Remap a float from [0.0, 1.0] to [min, max]. More...
 
PRMAN_INLINE RtColorRGB RixOutputRange (const RtColorRGB &rgb, const RtFloat &min, const RtFloat &max)
 Remap a color from [0.0, 1.0] to [min, max]. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixOutputRange (const RtColorRGB &rgb, const T &min, const T &max)
 Remap a color from [0.0, 1.0] to [min, max]. More...
 
PRMAN_INLINE RtFloat RixExposure (float const &f, float const &e)
 Float exposure function. More...
 
PRMAN_INLINE RtColorRGB RixExposure (const RtColorRGB &rgb, const RtFloat &e)
 Color exposure function. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixExposure (const RtColorRGB &rgb, const T &e)
 Color exposure function. More...
 
PRMAN_INLINE RtFloat RixGamma (const RtFloat &f, const RtFloat &g)
 Float gamma correction. More...
 
PRMAN_INLINE RtColorRGB RixGamma (const RtColorRGB &rgb, const RtFloat &g)
 Color gamma correction. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixGamma (const RtColorRGB &rgb, const T &g)
 Color gamma correction. More...
 
PRMAN_INLINE RtFloat RixContrast (float f, float contrast, float pivot)
 Contrast float function. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixContrast (const RtColorRGB &rgb, const T &contrast, const T &pivot)
 Color contrast function. More...
 
PRMAN_INLINE RtColorRGB RixHsvCorrect (const RtColorRGB &rgb, const RtFloat &hue, const RtFloat &sat, const RtFloat &val)
 HSV color correction. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixHsvCorrect (const RtColorRGB &rgb, const T &hsv)
 HSV color correction. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixHslCorrect (const RtColorRGB &rgb, const T &hsl)
 HSL color correction. More...
 
template<typename T >
PRMAN_INLINE RtColorRGB RixColorClamp (const RtColorRGB &rgb, const T &min, const T &max)
 Clamp color : this an extensions of RixClamp. More...
 
PRMAN_INLINE RtColorRGB RixSaturation (const RtColorRGB &rgb, const float saturation)
 Return the saturation-adjusted color. More...
 
PRMAN_INLINE void RixSaturation (RtColorRGB &rgb, const float saturation)
 Adjust the color saturation of the passed color. More...
 

Macro Definition Documentation

◆ F_INVLOGDOTFIVE

#define F_INVLOGDOTFIVE   (-3.32192809489f)

◆ F_LOGDOTFIVE

#define F_LOGDOTFIVE   (-0.30102999566f)

Referenced by RixContrast().

◆ IFLOOR

#define IFLOOR (   x)    (((x) < 0.0f && (x) != (int)(x)) ? (int)x - 1 : (int)x)

Referenced by RixHsvToRgb().

Enumeration Type Documentation

◆ RenderColorSpace

Enumerator
kScene 
kRec709 
kACEScg 
kNumColorSpaces 

◆ RixColorSpace

Enumerator
k_sRGB 
k_Rec709 
k_Rec2020 
k_DCI_P3 
k_Alexa_wide 
k_ACEScg 
k_CinemaGamut 
k_NTSC 
k_numColorSpaces 

Function Documentation

◆ RixColorClamp()

template<typename T >
PRMAN_INLINE RtColorRGB RixColorClamp ( const RtColorRGB rgb,
const T &  min,
const T &  max 
)

Clamp color : this an extensions of RixClamp.

Parameters
[in]rgbThe rgb input
[in]minThe minimum color
[in]maxThe maximum color
Template Parameters
TAny RtFloat3 container
Returns
The clamped color.

References RixClamp().

◆ RixContrast() [1/2]

PRMAN_INLINE RtFloat RixContrast ( float  f,
float  contrast,
float  pivot 
)

Contrast float function.

Parameters
[in]finput float value
[in]contrastThe amount of contrast, from -1 to 1. 0 is neutral.
[in]pivotThe pivot value of the contrast curve.
Returns
float value

References F_LOGDOTFIVE, RixClamp(), and RixMin().

Referenced by RixContrast().

◆ RixContrast() [2/2]

template<typename T >
PRMAN_INLINE RtColorRGB RixContrast ( const RtColorRGB rgb,
const T &  contrast,
const T &  pivot 
)

Color contrast function.

Parameters
[in]rgbThe rgb input
[in]contrastThe contrast value between -1 and +1
[in]pivotThe pivot of the contrast curve.
Template Parameters
TAny RtFloat3 container.
Returns
Adjusted color value.

References RixContrast().

◆ RixExposure() [1/3]

PRMAN_INLINE RtFloat RixExposure ( float const &  f,
float const &  e 
)

Float exposure function.

Parameters
ffloat input value
eexposure value.
Returns
float result

Referenced by RixExposure().

◆ RixExposure() [2/3]

PRMAN_INLINE RtColorRGB RixExposure ( const RtColorRGB rgb,
const RtFloat e 
)

Color exposure function.

Parameters
[in]rgbThe rgb input
[in]eThe float exposure value
Returns
The modified color

◆ RixExposure() [3/3]

template<typename T >
PRMAN_INLINE RtColorRGB RixExposure ( const RtColorRGB rgb,
const T &  e 
)

Color exposure function.

Parameters
[in]rgbThe rgb input
[in]eThe T exposure value
Template Parameters
TAny RtFloat3 container
Returns
The modified color

References RixExposure().

◆ RixGamma() [1/3]

PRMAN_INLINE RtFloat RixGamma ( const RtFloat f,
const RtFloat g 
)

Float gamma correction.

Parameters
[in]fThe float input value
[in]gThe float gamma value
Returns
The modified float value.

References RixMax().

Referenced by RixGamma().

◆ RixGamma() [2/3]

PRMAN_INLINE RtColorRGB RixGamma ( const RtColorRGB rgb,
const RtFloat g 
)

Color gamma correction.

Parameters
[in]rgbThe rgb input
[in]gThe float gamma value
Returns
The modified color

References RixMax().

◆ RixGamma() [3/3]

template<typename T >
PRMAN_INLINE RtColorRGB RixGamma ( const RtColorRGB rgb,
const T &  g 
)

Color gamma correction.

Parameters
[in]rgbThe rgb input
[in]gThe T gamma value
Template Parameters
TAny RtFloat3 container
Returns
The modified color

References RixGamma().

◆ RixGetSceneColorSpace()

◆ RixHslCorrect()

template<typename T >
PRMAN_INLINE RtColorRGB RixHslCorrect ( const RtColorRGB rgb,
const T &  hsl 
)

HSL color correction.

Parameters
[in]rgbThe rgb input
[in]hslThe hsl values.
Template Parameters
TAny RtFloat3 container
Returns
Adjusted color

References RixClamp(), RixFractional(), RixHslToRgb(), and RixRgbToHsl().

◆ RixHslToRgb()

PRMAN_INLINE void RixHslToRgb ( RtColorRGB const &  hsl,
RtColorRGB rgb 
)

References rixValue().

Referenced by RixHslCorrect().

◆ RixHsvCorrect() [1/2]

PRMAN_INLINE RtColorRGB RixHsvCorrect ( const RtColorRGB rgb,
const RtFloat hue,
const RtFloat sat,
const RtFloat val 
)

HSV color correction.

Parameters
[in]rgbThe rgb input
[in]hueThe hue offset
[in]satThe saturation multiplier
[in]valThe value multiplier
Returns
Adjusted color

References RixClamp(), RixFractional(), RixHsvToRgb(), and RixRgbToHsv().

◆ RixHsvCorrect() [2/2]

template<typename T >
PRMAN_INLINE RtColorRGB RixHsvCorrect ( const RtColorRGB rgb,
const T &  hsv 
)

HSV color correction.

Hue, saturation and value are packed in a RtFloat3 container.

Parameters
[in]rgbThe rgb input
[in]hsvThe hsv values in a RtFloat3 container.
Template Parameters
TCan be any RtFloat3 container.
Returns
Adjusted color.

References RixClamp(), RixFractional(), RixHsvToRgb(), and RixRgbToHsv().

◆ RixHsvToRgb()

PRMAN_INLINE void RixHsvToRgb ( RtColorRGB const &  hsv,
RtColorRGB rgb 
)

References IFLOOR.

Referenced by RixHsvCorrect().

◆ RixInputRange() [1/3]

PRMAN_INLINE RtFloat RixInputRange ( const RtFloat f,
const RtFloat min,
const RtFloat max 
)

Remap [min, max] to [0.0 to 1.0].

Parameters
[in]fThe input float value
[in]minThe float value that will be remapped to 0.0
[in]maxThe float value that will be remapped to 1.0
Returns
The remapped float value.

Referenced by RixInputRange().

◆ RixInputRange() [2/3]

PRMAN_INLINE RtColorRGB RixInputRange ( const RtColorRGB rgb,
const RtFloat min,
const RtFloat max 
)

Remap [min, max] to [0.0 to 1.0].

Parameters
[in]rgbThe input color value
[in]minThe float value that will be remapped to 0.0
[in]maxThe float value that will be remapped to 1.0
Returns
The remapped color.

References RixInputRange().

◆ RixInputRange() [3/3]

template<typename T >
PRMAN_INLINE RtColorRGB RixInputRange ( const RtColorRGB rgb,
const T &  min,
const T &  max 
)

Remap [min, max] to [0.0 to 1.0].

Parameters
[in]rgbThe input color value
[in]minThe T value that will be remapped to 0.0
[in]maxThe T value that will be remapped to 1.0
Template Parameters
TAny RtFloat3 container.
Returns
The remapped color.

References RixInputRange().

◆ RixOutputRange() [1/3]

PRMAN_INLINE RtFloat RixOutputRange ( const RtFloat f,
const RtFloat min,
const RtFloat max 
)

Remap a float from [0.0, 1.0] to [min, max].

Parameters
[in]fThe input float value
[in]minThe float value to which 0.0 will be remapped.
[in]maxThe float value to which 1.0 will be remapped.
Returns
The remapped float value

Referenced by RixOutputRange().

◆ RixOutputRange() [2/3]

PRMAN_INLINE RtColorRGB RixOutputRange ( const RtColorRGB rgb,
const RtFloat min,
const RtFloat max 
)

Remap a color from [0.0, 1.0] to [min, max].

Parameters
[in]rgbThe input rgb
[in]minThe float value to which 0.0 will be remapped.
[in]maxThe float value to which 1.0 will be remapped.
Returns
The remapped color

References RixOutputRange().

◆ RixOutputRange() [3/3]

template<typename T >
PRMAN_INLINE RtColorRGB RixOutputRange ( const RtColorRGB rgb,
const T &  min,
const T &  max 
)

Remap a color from [0.0, 1.0] to [min, max].

Parameters
[in]rgbThe input rgb
[in]minThe T value to which 0.0 will be remapped.
[in]maxThe T value to which 1.0 will be remapped.
Template Parameters
TAny RtFloat3 container.
Returns
The remapped color.

References RixOutputRange().

◆ RixRgbToHsl()

PRMAN_INLINE void RixRgbToHsl ( RtColorRGB const &  rgb,
RtColorRGB hsl 
)

Referenced by RixHslCorrect().

◆ RixRgbToHsv()

PRMAN_INLINE void RixRgbToHsv ( RtColorRGB const &  rgb,
RtColorRGB hsv 
)

Referenced by RixHsvCorrect().

◆ RixRgbToXyz()

PRMAN_INLINE void RixRgbToXyz ( RtColorRGB const &  rgb,
RtColorRGB xyz,
RixColorSpace  cs = k_sRGB 
)

References k_numColorSpaces.

◆ RixSaturation() [1/2]

PRMAN_INLINE RtColorRGB RixSaturation ( const RtColorRGB rgb,
const float  saturation 
)

Return the saturation-adjusted color.

Note
This is faster than HSV or HSL if you only need saturation.
Parameters
[in]rgbThe rgb input
[in]saturation0.0 is monochrome (fully desaturated), 1.0 is the original color, values > 1.0 increase color saturation.
Returns
The saturation-adjusted color.

References RixMax().

◆ RixSaturation() [2/2]

PRMAN_INLINE void RixSaturation ( RtColorRGB rgb,
const float  saturation 
)

Adjust the color saturation of the passed color.

Note
This is faster than HSV or HSL if you only need saturation.
Parameters
[in]rgbThe rgb input
[in]saturation0.0 is monochrome (fully desaturated), 1.0 is the original color, values > 1.0 increase color saturation.

References RixMax().

◆ RixToColorSpace()

PRMAN_INLINE RtColorRGB RixToColorSpace ( const RenderColorSpace from,
const RenderColorSpace to,
const RtColorRGB rgb 
)

References kScene.

◆ rixValue()

PRMAN_INLINE float rixValue ( float  n1,
float  n2,
float  hue 
)

Referenced by RixHslToRgb().

◆ RixXyzToRgb()

PRMAN_INLINE void RixXyzToRgb ( RtColorRGB const &  xyz,
RtColorRGB rgb,
RixColorSpace  cs = k_sRGB 
)

References k_numColorSpaces.