コード例 #1
0
        public void RenderHSVPlane(HSVAxisDefinitions 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++)
                {
                    double H         = (double)Z / (double)360.0;
                    double S         = (double)y / (double)255.0;
                    double V         = (double)x / (double)255.0;
                    Color  CellColor = GetHSVColorAt(H, S, V, 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);
            }
        }
コード例 #2
0
        private Color GetHSVColorAt(double H, double S, double V, HSVAxisDefinitions AxisLayout)
        {
            byte r = 0;
            byte g = 0;
            byte b = 0;

            switch (AxisLayout)
            {
            case HSVAxisDefinitions.HSV:
                HSVtoRGB(H, S, V, out r, out g, out b);
                break;

            case HSVAxisDefinitions.HVS:
                HSVtoRGB(H, V, S, out r, out g, out b);
                break;

            case HSVAxisDefinitions.VHS:
                HSVtoRGB(V, H, S, out r, out g, out b);
                break;

            case HSVAxisDefinitions.VSH:
                HSVtoRGB(V, S, H, out r, out g, out b);
                break;

            case HSVAxisDefinitions.SHV:
                HSVtoRGB(S, H, V, out r, out g, out b);
                break;

            case HSVAxisDefinitions.SVH:
                HSVtoRGB(S, V, H, out r, out g, out b);
                break;

            default:
                throw new InvalidOperationException("Unexpected axis layout.");
            }
            return(Color.FromRgb(r, g, b));
        }