Пример #1
0
        /// <summary>
        /// Returns the average <see cref="ImmutableColor"/> between two <see cref="ImmutableColor"/> values.
        /// </summary>
        public static ImmutableColor Average(ImmutableColor a, ImmutableColor b)
        {
            byte red   = GetAverage(a.R, b.R);
            byte green = GetAverage(a.G, b.G);
            byte blue  = GetAverage(a.B, b.B);

            return(new ImmutableColor(red, green, blue));
        }
Пример #2
0
        /// <summary>
        /// Gets the distance between two <see cref="ImmutableColor"/> values.
        /// </summary>
        public static int Distance(ImmutableColor from, ImmutableColor to)
        {
            int r = to.R - from.R;
            int g = to.G - from.G;
            int b = to.B - from.B;

            return(r * r + g * g + b * b);
        }
Пример #3
0
        public Bitmap Build()
        {
            // Merge all RGB values into a color
            var image = new Grid <Color>(Width, Height);

            image.SetEachValue((x, y) => ImmutableColor.FromRange(Red[x, y], Green[x, y], Blue[x, y]));

            return(ImageHelper.CreateArgbBitmap(image.Values));
        }
Пример #4
0
        /// <summary>
        /// Merges two <see cref="GammaPalette"/> values together, merging the foreground value with the background value by a specified strength.
        /// </summary>
        public static GammaPalette Merge(GammaPalette background, GammaPalette foreground, float strength)
        {
            List <ImmutableColor> colors = new List <ImmutableColor>();

            for (int g = 0; g < RequiredLength; g++)
            {
                colors.Add(ImmutableColor.Blend(background.Values[g], foreground.Values[g], strength));
            }

            return(new GammaPalette(colors.ToArray()));
        }
Пример #5
0
        // Keep the opacity of the initial alpha
        public static ImmutableColor Blend(ImmutableColor background, ImmutableColor foreground, float strength)
        {
            // TODO: Ensure range of 0.0 to 1.0
            if (strength > 1.00f || strength < 0.00f)
            {
                throw new Exception("The specified merge strength must be within the range of 0.00f to 1.00f.");
            }

            byte r = GetBlendValue(background.R, foreground.R, strength);
            byte g = GetBlendValue(background.G, foreground.G, strength);
            byte b = GetBlendValue(background.B, foreground.B, strength);

            return(new ImmutableColor(r, g, b));
        }
Пример #6
0
        /// <summary>
        /// Smears two <see cref="GammaPalette"/> values together, slowly transitioning the primary palette to the secondary palette.
        /// </summary>
        public static GammaPalette Smear(GammaPalette a, GammaPalette b)
        {
            var colors = new List <ImmutableColor>();

            float mergeStrength = 1.0f / (RequiredLength - 1);

            for (int g = 0; g < RequiredLength; g++)
            {
                var strength = mergeStrength * g;

                //if (g == 0)
                //    strength = 0.1f;

                colors.Add(ImmutableColor.Blend(a[g], b[g], strength));
            }

            return(new GammaPalette(colors.ToArray()));
        }
Пример #7
0
 public static float GetBrightness(ImmutableColor value)
 => MathF.Floor(R_LUMINANCE * value.R + G_LUMINANCE * value.G + B_LUMINANCE * value.B);
Пример #8
0
        /// <summary>
        /// Returns a <see cref="ImmutableColor"/> that is the conversion of the specified <see cref="ImmutableColor"/> to grayscale.
        /// </summary>
        public static ImmutableColor Grayscale(ImmutableColor value)
        {
            byte rgb = (byte)Math.Floor(R_LUMINANCE * value.R + G_LUMINANCE * value.G + B_LUMINANCE * value.B);

            return(new ImmutableColor(rgb, rgb, rgb));
        }