Click or drag to resize
EffectTransferTable3DCreateFromColors Method
Creates a 3D transfer table from an array of colors.

Namespace:  Microsoft.Graphics.Canvas.Effects
Assembly:  Microsoft.Graphics.Canvas (in Microsoft.Graphics.Canvas.dll) Version: 0.0.0.0
Syntax
C#
public static EffectTransferTable3D CreateFromColors(
	ICanvasResourceCreator resourceCreator,
	Color[] colors,
	int sizeB,
	int sizeG,
	int sizeR
)

Parameters

resourceCreator
Type: Microsoft.Graphics.CanvasICanvasResourceCreator
colors
Type: Windows.UIColor
sizeB
Type: SystemInt32
sizeG
Type: SystemInt32
sizeR
Type: SystemInt32

Return Value

Type: EffectTransferTable3D
Remarks

The maximum table size is 256 values per axis, but be warned that a 256x256x256 table, using 32 bits per pixel, takes up 64 megabytes! Thanks to linear interpolation, much smaller tables will usually give good results.

The table data is laid out as a 3D array with the blue values changing with highest frequency. For instance, to generate a table by evaluating an arbitrary color transfer function for every value in it:

EffectTransferTable3D CreateTransferTableFromFunction(ICanvasResourceCreator resourceCreator, int sizeB, int sizeG, int sizeR, Func<Vector3, Vector3> transferFunction)
{
    var tableColors = new List<Color>();

    var maxExtents = new Vector3(sizeR, sizeG, sizeB) - Vector3.One;

    for (int r = 0; r < sizeR; r++)
    {
        for (int g = 0; g < sizeG; g++)
        {
            for (int b = 0; b < sizeB; b++)
            {
                Vector3 sourceColor = new Vector3(r, g, b) / maxExtents;

                Vector3 outputColor = transferFunction(sourceColor);

                tableColors.Add(ToColor(outputColor));
            }
        }
    }

    return EffectTransferTable3D.CreateFromColors(resourceCreator, tableColors.ToArray(), sizeB, sizeG, sizeR);
}
See Also