private Color GetColorAt(int X, int Y, int Z, RGBAxisDefinitions AxisLayout) { byte r = 0; byte g = 0; byte b = 0; switch (AxisLayout) { case RGBAxisDefinitions.RGB: r = (byte)X; g = (byte)Y; b = (byte)Z; break; case RGBAxisDefinitions.RBG: r = (byte)X; b = (byte)Y; g = (byte)Z; break; case RGBAxisDefinitions.GRB: g = (byte)X; r = (byte)Y; b = (byte)Z; break; case RGBAxisDefinitions.GBR: g = (byte)X; b = (byte)Y; r = (byte)Z; break; case RGBAxisDefinitions.BRG: b = (byte)X; r = (byte)Y; g = (byte)Z; break; case RGBAxisDefinitions.BGR: b = (byte)X; g = (byte)Y; r = (byte)Z; break; default: throw new InvalidOperationException("Unexpected axis layout."); } return(Color.FromRgb(r, g, b)); }
public void RenderRGBPlane(RGBAxisDefinitions AxisLayout, int Z, Image OutImage, double SurfaceWidth, double SurfaceHeight) { List <ColorBlenderInterface.ColorBlock> ColorBlocks = new List <ColorBlenderInterface.ColorBlock>(); ColorBlenderInterface cbi = new ColorBlenderInterface(); int FinalStride = (int)SurfaceWidth * 4; byte[] PixelMap = new byte[(int)SurfaceHeight * FinalStride]; int CellWidth = (int)SurfaceWidth / 256; int CellHeight = (int)SurfaceHeight / 256; for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { Color CellColor = GetColorAt(x, y, Z, AxisLayout); ColorBlenderInterface.ColorBlock CB = new ColorBlenderInterface.ColorBlock(); CB.Left = x * CellWidth; CB.Top = y * CellHeight; CB.Width = CellWidth; CB.Height = CellHeight; CB.BlockColor = CellColor.ToBGRA(); ColorBlocks.Add(CB); } } cbi.DrawColorBlocks(ref PixelMap, (int)SurfaceWidth, (int)SurfaceHeight, FinalStride, ColorBlocks, Colors.Transparent); if (!OutImage.Dispatcher.CheckAccess()) { OutImage.Dispatcher.Invoke ( System.Windows.Threading.DispatcherPriority.Normal, new Action ( delegate() { OutImage.Source = BitmapSource.Create((int)SurfaceWidth, (int)SurfaceHeight, 96.0, 96.0, PixelFormats.Bgra32, null, PixelMap, FinalStride); } ) ); } else { OutImage.Source = BitmapSource.Create((int)SurfaceWidth, (int)SurfaceHeight, 96.0, 96.0, PixelFormats.Bgra32, null, PixelMap, FinalStride); } }