Platform SDK: DirectX

D3DXColorAdjustSaturation

The D3DXColorAdjustSaturation function adjusts the saturation value of a given color.

D3DXCOLOR* D3DXColorAdjustSaturation(
  D3DXCOLOR* pOut,
  D3DXCOLOR* pC,
  float s
); 

Parameters

pOut
A pointer to a D3DXCOLOR structure that is the result of the operation.
pC
A pointer to a source D3DXCOLOR structure.
s
The saturation value. This parameter linearly interpolates between the color converted to gray-scale and the original color, pC. There are no limits on the value of s. If s is zero, then the returned color is the gray-scale color. If s is 1, then the returned color is the original color.

Return Values

The function returns a pointer to a D3DXCOLOR structure that is the result of the saturation adjustment.

Remarks

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXColorAdjustSaturation function can be used as a parameter for another function.

This function interpolates the red, green, and blue color components of a D3DXCOLOR structure between an unsaturated color and a given color:

    // Approximate values for each component's contribution to luminance.
    // Based upon the NTSC standard described in ITU-R Recommendation BT.709.
    float grey = pC->r * 0.2125f + pC->g * 0.7154f + pC->b * 0.0721f;
    
    pOut->r = grey + s * (pC->r - grey);

If s is greater than zero and less than 1, then the saturation will be decreased. If s is greater than 1, then the saturation will be increased.

The gray-scale color is computed as: r = g = b = 0.2125*r + 0.7154*g + 0.0721*b.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Version: Requires DirectX 7.0.
  Header: Declared in d3dxmath.h.
  Library: Use d3dx.lib.

See Also

D3DXColorAdjustContrast