Pinta.HistogramWidget.DrawChannel C# (CSharp) Method

DrawChannel() private method

private DrawChannel ( Context g, ColorBgra color, int channel, long max, float mean ) : void
g Context
color ColorBgra
channel int
max long
mean float
return void
        private void DrawChannel(Context g, ColorBgra color, int channel, long max, float mean)
        {
            Rectangle rect = Allocation.ToCairoRectangle ();
            Histogram histogram = Histogram;

            int l = (int)rect.X;
            int t = (int)rect.Y;
            int r = (int)(rect.X + rect.Width);
            int b = (int)(rect.Y + rect.Height);

            int entries = histogram.Entries;
            long[] hist = histogram.HistogramValues [channel];

            ++max;

            if (FlipHorizontal) {
                Utility.Swap(ref l, ref r);
            }

            if (!FlipVertical) {
                Utility.Swap(ref t, ref b);
            }

            PointD[] points = new PointD[entries + 2];

            points[entries] = new PointD (Utility.Lerp (l, r, -1), Utility.Lerp (t, b, 20));
            points[entries + 1] = new PointD (Utility.Lerp (l, r, -1), Utility.Lerp (b, t, 20));

            for (int i = 0; i < entries; i += entries - 1) {
                points[i] = new PointD (
                    Utility.Lerp (l, r, (float)hist[i] / (float)max),
                    Utility.Lerp (t, b, (float)i / (float)entries));

                CheckPoint (rect, points [i]);
            }

            long sum3 = hist[0] + hist[1];

            for (int i = 1; i < entries - 1; ++i) {
                sum3 += hist[i + 1];

                points[i] = new PointD(
                    Utility.Lerp(l, r, (float)(sum3) / (float)(max * 3.1f)),
                    Utility.Lerp(t, b, (float)i / (float)entries));

                CheckPoint (rect, points [i]);
                sum3 -= hist[i - 1];
            }

            byte intensity = selected[channel] ? (byte)96 : (byte)32;
            ColorBgra pen_color = ColorBgra.Blend (ColorBgra.Black, color, intensity);
            ColorBgra brush_color = color;
               	brush_color.A = intensity;

            g.LineWidth = 1;

            g.Rectangle (rect);
            g.Clip ();
            g.DrawPolygonal (points, pen_color.ToCairoColor ());
            g.FillPolygonal (points, brush_color.ToCairoColor ());
        }