EffectTransferTable3DCreateFromBytes Method |
Namespace: Microsoft.Graphics.Canvas.Effects
public static EffectTransferTable3D CreateFromBytes( ICanvasResourceCreator resourceCreator, byte[] bytes, int sizeB, int sizeG, int sizeR, DirectXPixelFormat format )
Supported pixel formats are:
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); }