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

Namespace:  Microsoft.Graphics.Canvas.Effects
Assembly:  Microsoft.Graphics.Canvas (in Microsoft.Graphics.Canvas.dll) Version: 0.0.0.0
Syntax
C#
public static EffectTransferTable3D CreateFromBytes(
	ICanvasResourceCreator resourceCreator,
	byte[] bytes,
	int sizeB,
	int sizeG,
	int sizeR,
	DirectXPixelFormat format
)

Parameters

resourceCreator
Type: Microsoft.Graphics.CanvasICanvasResourceCreator
bytes
Type: SystemByte
sizeB
Type: SystemInt32
sizeG
Type: SystemInt32
sizeR
Type: SystemInt32
format
Type: Windows.Graphics.DirectXDirectXPixelFormat

Return Value

Type: EffectTransferTable3D
Remarks

Supported pixel formats are:

  • R8G8B8A8UIntNormalized
  • R8G8B8A8UIntNormalizedSrgb
  • R16G16B16A16UIntNormalized
  • R16G16B16A16Float
  • R32G32B32A32Float

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 tableBytes = new List<byte>();

    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);

                tableBytes.Add((byte)(outputColor.R * 255));
                tableBytes.Add((byte)(outputColor.G * 255));
                tableBytes.Add((byte)(outputColor.B * 255));
                tableBytes.Add((byte)(255));
            }
        }
    }

    return EffectTransferTable3D.CreateFromBytes(resourceCreator, tableBytes.ToArray(), sizeB, sizeG, sizeR, DirectXPixelFormat.R8G8B8A8UIntNormalized);
}
See Also