Esempio n. 1
0
        /// <summary>
        /// Interpolates between two values using an enforced amount.
        /// </summary>
        public static float LerpExact(float a, float b, float amount)
        {
            if (!RangeF.Contains(0.0f, 1.0f, amount))
            {
                throw new ArithmeticException("Cannot interpolate with an amount outside the range of [0, 1].");
            }

            return((1.0f - amount) * a + amount * b);
        }
        public static ImageChannels FromImage(Bitmap image)
        {
            Grid <Color> pixels   = ImageHelper.GetPixelData(image);
            var          channels = new ImageChannels(image.Width, image.Height);

            channels.Red.SetEachValue((x, y) => RangeF.Convert(0, 255, 0, 1, pixels[x, y].R));
            channels.Green.SetEachValue((x, y) => RangeF.Convert(0, 255, 0, 1, pixels[x, y].G));
            channels.Blue.SetEachValue((x, y) => RangeF.Convert(0, 255, 0, 1, pixels[x, y].B));

            return(channels);
        }
Esempio n. 3
0
        private static ImmutableColor CreateFromChmx(float c, float h, float m, float x)
        {
            float rF = 0.00f;
            float gF = 0.00f;
            float bF = 0.00f;

            if (RangeF.Contains(0.00f, 60.00f, h, true, false))
            {
                rF = c;
                gF = x;
                bF = 0;
            }
            else if (RangeF.Contains(60.00f, 120.00f, h, true, false))
            {
                rF = x;
                gF = c;
                bF = 0;
            }
            else if (RangeF.Contains(120.00f, 180.00f, h, true, false))
            {
                rF = 0;
                gF = c;
                bF = x;
            }
            else if (RangeF.Contains(180.00f, 240.00f, h, true, false))
            {
                rF = 0;
                gF = x;
                bF = c;
            }
            else if (RangeF.Contains(240.00f, 300.00f, h, true, false))
            {
                rF = x;
                gF = 0;
                bF = c;
            }
            else if (RangeF.Contains(300.00f, 360.00f, h, true, false))
            {
                rF = c;
                gF = 0;
                bF = x;
            }

            byte r = (byte)Math.Floor((rF + m) * 255);
            byte g = (byte)Math.Floor((gF + m) * 255);
            byte b = (byte)Math.Floor((bF + m) * 255);

            return(new ImmutableColor(r, g, b));
        }
Esempio n. 4
0
        public static ImmutableColor FromCmyk(float c, float m, float y, float k)
        {
            RangeF bounds = RangeF.Percent;

            if (!bounds.All(c, m, y, k))
            {
                throw new ArgumentException("One of the specified float values are out of range.");
            }

            byte r = GetCmy(c, k);
            byte g = GetCmy(m, k);
            byte b = GetCmy(y, k);

            return(new ImmutableColor(r, g, b));
        }
Esempio n. 5
0
 public float Convert(RangeF range, float value)
 => Convert(range.Min, range.Max, Min, Max, value);
Esempio n. 6
0
 public static float Clamp(RangeF range, float value)
 => Clamp(range.Min, range.Max, value);
Esempio n. 7
0
 /// <summary>
 /// Flattens the <see cref="RangeF"/> to whole numbers.
 /// </summary>
 public static RangeF Truncate(RangeF range)
 => new RangeF(MathF.Truncate(range.Min),
               MathF.Truncate(range.Max),
               range.InclusiveMin,
               range.InclusiveMax);
Esempio n. 8
0
 public static float Convert(RangeF from, RangeF to, float value)
 => Convert(from.Min, from.Max, to.Min, to.Max, value);