Exemple #1
0
            public double GetRelativeError(List <Color> colors, List <double> accumulatedDistances)
            {
                GradientEyedropper.GradientInterval gradientInterval = this.Prev;
                if (gradientInterval == null)
                {
                    return(double.MaxValue);
                }
                bool     flag1     = this.R == colors.Count;
                bool     flag2     = gradientInterval.L == -1;
                double   num1      = accumulatedDistances[flag1 ? colors.Count - 1 : this.R];
                double   num2      = accumulatedDistances[flag2 ? 0 : gradientInterval.L];
                Vector3D vector3D1 = GradientEyedropper.Subtract(colors[flag2 ? this.L : gradientInterval.L], colors[this.L]);
                double   x1        = accumulatedDistances[this.L] - num2;
                Vector3D vector3D2 = GradientEyedropper.Subtract(colors[this.L], colors[flag1 ? this.L : this.R]);
                double   x2        = num1 - accumulatedDistances[this.L];

                if (flag2)
                {
                    return(Math.Max(2.0 * x1 * Math.Abs(vector3D2.X) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D2.X), new Vector(x2, vector3D2.X))), Math.Max(2.0 * x1 * Math.Abs(vector3D2.Y) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D2.Y), new Vector(x2, vector3D2.Y))), 2.0 * x1 * Math.Abs(vector3D2.Z) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D2.Z), new Vector(x2, vector3D2.Z))))));
                }
                if (flag1)
                {
                    return(Math.Max(2.0 * x2 * Math.Abs(vector3D1.X) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D1.X), new Vector(x1, vector3D1.X))), Math.Max(2.0 * x2 * Math.Abs(vector3D1.Y) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D1.Y), new Vector(x1, vector3D1.Y))), 2.0 * x2 * Math.Abs(vector3D1.Z) + Math.Abs(Vector.CrossProduct(new Vector(0.0, vector3D1.Z), new Vector(x1, vector3D1.Z))))));
                }
                return(Math.Max(Math.Abs(Vector.CrossProduct(new Vector(-x1, -vector3D1.X), new Vector(x2, vector3D2.X))), Math.Max(Math.Abs(Vector.CrossProduct(new Vector(-x1, -vector3D1.Y), new Vector(x2, vector3D2.Y))), Math.Abs(Vector.CrossProduct(new Vector(-x1, -vector3D1.Z), new Vector(x2, vector3D2.Z))))));
            }
Exemple #2
0
        private ICollection <GradientEyedropper.GradientInterval> GenerateMinimalIntervalSet(List <Color> colors, List <double> accumulatedDistances)
        {
            SortedDictionary <GradientEyedropper.GradientInterval, bool> intervals = new SortedDictionary <GradientEyedropper.GradientInterval, bool>((IComparer <GradientEyedropper.GradientInterval>) new GradientEyedropper.IntervalComparer(colors, accumulatedDistances));

            GradientEyedropper.GradientInterval gradientInterval = (GradientEyedropper.GradientInterval)null;
            for (int l = -1; l < colors.Count; ++l)
            {
                GradientEyedropper.GradientInterval key = new GradientEyedropper.GradientInterval(l, l + 1);
                if (gradientInterval != null)
                {
                    key.Prev = gradientInterval;
                    gradientInterval.Next = key;
                }
                intervals.Add(key, true);
                gradientInterval = key;
            }
            while (intervals.Count > 2)
            {
                GradientEyedropper.GradientInterval best = this.FindBest(intervals, colors, accumulatedDistances);
                if (best != null)
                {
                    intervals.Remove(best);
                    GradientEyedropper.GradientInterval key1 = best.Prev;
                    intervals.Remove(key1);
                    GradientEyedropper.GradientInterval key2 = best.Next;
                    if (key2 != null)
                    {
                        intervals.Remove(key2);
                    }
                    GradientEyedropper.GradientInterval key3 = new GradientEyedropper.GradientInterval(key1.L, best.R);
                    if (key1.Prev != null)
                    {
                        key3.Prev      = key1.Prev;
                        key1.Prev.Next = key3;
                    }
                    if (best.Next != null)
                    {
                        key3.Next      = best.Next;
                        best.Next.Prev = key3;
                        intervals.Add(key2, true);
                    }
                    intervals.Add(key3, true);
                }
                else
                {
                    break;
                }
            }
            return((ICollection <GradientEyedropper.GradientInterval>)intervals.Keys);
        }
Exemple #3
0
            public double GetAbsoluteError(List <Color> colors, List <double> accumulatedDistances)
            {
                GradientEyedropper.GradientInterval gradientInterval = this.Prev;
                double   num1      = 0.0;
                bool     flag1     = this.R == colors.Count;
                bool     flag2     = gradientInterval.L == -1;
                Color    a1        = colors[flag2 ? this.R : gradientInterval.L];
                Color    b         = colors[flag1 ? gradientInterval.L : this.R];
                double   num2      = accumulatedDistances[flag1 ? colors.Count - 1 : this.R];
                double   num3      = accumulatedDistances[flag2 ? 0 : gradientInterval.L];
                double   num4      = num2 - num3;
                Vector3D vector3D1 = GradientEyedropper.Subtract(a1, b);

                for (int index = gradientInterval.L + 1; index < this.R; ++index)
                {
                    Vector3D vector3D2 = vector3D1 * ((accumulatedDistances[index] - num3) / num4);
                    Color    a2        = Color.FromArgb(byte.MaxValue, (byte)((double)a1.R + vector3D2.X), (byte)((double)a1.G + vector3D2.Y), (byte)((double)a1.B + vector3D2.Z));
                    num1 = Math.Max(num1, GradientEyedropper.Subtract(a2, colors[index]).LengthSquared);
                }
                return(Math.Sqrt(num1));
            }
Exemple #4
0
        private LinearGradientBrush ReconstructGradient(List <Color> colors, List <double> accumulatedDistances, ICollection <GradientEyedropper.GradientInterval> intervals)
        {
            LinearGradientBrush brush = new LinearGradientBrush();

            GradientEyedropper.GradientInterval gradientInterval = (GradientEyedropper.GradientInterval)null;
            using (IEnumerator <GradientEyedropper.GradientInterval> enumerator = intervals.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    gradientInterval = enumerator.Current;
                }
            }
            while (gradientInterval.Prev != null)
            {
                gradientInterval = gradientInterval.Prev;
            }
            if (intervals.Count == 2)
            {
                this.AddGradientStop(brush, colors, 0, accumulatedDistances);
                if (gradientInterval.R != 0 && gradientInterval.R != colors.Count - 1)
                {
                    this.AddGradientStop(brush, colors, gradientInterval.R, accumulatedDistances);
                }
                this.AddGradientStop(brush, colors, colors.Count - 1, accumulatedDistances);
            }
            else
            {
                for (; gradientInterval != null; gradientInterval = gradientInterval.Next)
                {
                    if (gradientInterval.L >= 0)
                    {
                        this.AddGradientStop(brush, colors, gradientInterval.L, accumulatedDistances);
                    }
                }
            }
            return(brush);
        }