Color spaces

I have a question regarding color spaces in WPF and DXEngine. We've run into some weird issues with converting colors from WPF into SharpDX and during debugging we found these methods (decompiled). 

/// <summary>Converts WPF Color to SharpDX Color3</summary>
/// <param name="color">WPF Color</param>
/// <returns>SharpDX Color3</returns>
public static Color3 ToColor3(this System.Windows.Media.Color color) => new Color3((float) color.R  0.003921569f, (float) color.G  0.003921569f, (float) color.B * 0.003921569f);

/// <summary>Converts WPF Color to SharpDX Color4</summary>
/// <param name="color">WPF Color</param>
/// <returns>SharpDX Color4</returns>
public static Color4 ToColor4(this System.Windows.Media.Color color) => new Color4((float) color.R  0.003921569f, (float) color.G  0.003921569f, (float) color.B  0.003921569f, (float) color.A  0.003921569f);

WPF allows creation of colors in 2 color spaces - sRGB and scRGB. I can safely assume that these extension methods take into account only sRGB, but why is there that additional multiplication? From the values it uses we could guess that it might be a PhotoYCC<->RGB conversion, but why it's there?

Best regards,
Janovsky Roman
The color components in WPF are defined by byte values. So each color component (color.R, color.G, color.B) is a value from 0 to 255.

SharpDX (and DirectX) requires that the color components are in float values in the range from 0 to 1 - so the byte value needs to be multiplied by 1/255 (=0.003921569) to convert bytes to floats.

I have quickly checked the scRgb. If you create the color in WPF by calling Color.FromScRgb than this also sets the R, B and B properties to byte values in the sRGB space. The ToColor3 and ToColor4 methods use those values to convert the colors to float values.

The DXEngine does not support scRgb space so all colors need to be converted to sRGB. 

If you have a proposal on how to improve that in DXEngine, I would glad to hear that.
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)