Ejemplo n.º 1
0
        void RedrawHue()
        {
            for (int y = 0; y < hueBitmap.Height; y++)
            {
                float    f = y / (float)hueBitmap.Height;
                float    h = f * 359;
                HsvColor v = new HsvColor(h, 1, 1);
                D.Color  c = v.ToColor();

                for (int x = 0; x < hueBitmap.Width; x++)
                {
                    hueBitmap.SetPixel(x, y, c.R, c.G, c.B, 255);
                }
            }

            HueSelector.Source = hueBitmap.ToImageSource();
        }
Ejemplo n.º 2
0
        void RedrawSatVal()
        {
            for (int y = 0; y < svBitmap.Height; y++)
            {
                for (int x = 0; x < svBitmap.Width; x++)
                {
                    float sf = x / (float)svBitmap.Width;
                    float sv = 1.0f - y / (float)svBitmap.Height;

                    HsvColor v = new HsvColor(hsv.H, sf, sv);
                    D.Color  c = v.ToColor();

                    svBitmap.SetPixel(x, y, c.R, c.G, c.B, 255);
                }
            }

            SaturationValueSelector.Source = svBitmap.ToImageSource();
        }
Ejemplo n.º 3
0
        public void BuildHistogramImage()
        {
            if (!isLoaded)
            {
                return;
            }

            if (ActualHeight == 0 || ActualWidth == 0)
            {
                return;
            }

            RawBitmap bmp = new RawBitmap((int)ActualWidth, (int)ActualHeight);

            if (ctk != null)
            {
                ctk.Cancel();
            }

            ctk = new CancellationTokenSource();

            Task.Run(() =>
            {
                if (histograph != null && maxValue != null)
                {
                    if (mode == LevelMode.RGB)
                    {
                        for (int g = 0; g < 3; g++)
                        {
                            if (maxValue[g] != 0)
                            {
                                //gather initial points
                                List <Vector2> points = new List <Vector2>();

                                for (int x = 0; x < 256; x++)
                                {
                                    int t   = histograph[g, x];
                                    float w = (float)x / 255.0f;
                                    int ax  = (int)Math.Floor(w * ActualWidth);

                                    float p = (float)t / (float)maxValue[g];
                                    int may = (int)Math.Min((int)ActualHeight, Math.Floor(p * (int)ActualHeight));

                                    points.Add(new Vector2(ax, may));
                                }

                                List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                                Parallel.For(0, spline.Count, i =>
                                {
                                    Vector2 p = spline[i];

                                    for (int k = 0; k < p.Y; k++)
                                    {
                                        bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                    }
                                });
                            }
                        }
                    }
                    else
                    {
                        int g = (int)mode;

                        if (maxValue[g] != 0)
                        {
                            List <Vector2> points = new List <Vector2>();

                            //gather initial points
                            for (int x = 0; x < 256; x++)
                            {
                                int t   = histograph[g, x];
                                float w = (float)x / 255.0f;
                                int ax  = (int)Math.Floor(w * ActualWidth);

                                float p = (float)t / (float)maxValue[g];
                                int may = (int)Math.Min(ActualHeight, Math.Floor(p * ActualHeight));

                                points.Add(new Vector2(ax, may));
                            }

                            List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                            Parallel.For(0, spline.Count, i =>
                            {
                                Vector2 p = spline[i];

                                for (int k = 0; k < p.Y; k++)
                                {
                                    bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                }
                            });
                        }
                    }
                }
            }, ctk.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return;
                }

                if (bmp == null)
                {
                    return;
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    PreviewView.Source = bmp.ToImageSource();
                });
            });
        }