diff --git a/Program.cs b/Program.cs index 841fbe0..97bbbf7 100644 --- a/Program.cs +++ b/Program.cs @@ -30,33 +30,7 @@ namespace Cupola ConsoleKey keyGG = Console.ReadKey().Key; - if (keyGG == ConsoleKey.S) - { - Bitmap final = await Combine(images.ToArray(), 0.6f); - - final.Save(name + ".png"); - } - else if (keyGG == ConsoleKey.M) - { - Dictionary> log = new Dictionary>(); - - for (int i = 1; i < images.Count; i++) - { - Console.WriteLine(i.ToString()); - - log.Add(name + "-" + (i - 1).ToString() + ".png", Combine(images.Take(i).ToArray(), 0.6f)); - } - - foreach (KeyValuePair> logItem in log) - { - Console.WriteLine(logItem.Key); - - Bitmap img = await logItem.Value; - - img.Save(logItem.Key); - } - } - else if (keyGG == ConsoleKey.F) + if (keyGG == ConsoleKey.F) { FloatImage[] fImages = new FloatImage[images.Count]; @@ -103,119 +77,6 @@ namespace Cupola } } - public static async Task Combine(Bitmap[] images, float oldWeight = 1f) // default to brightest - { - int width = images[0].Width; - int height = images[0].Height; - - for (int i = 0; i < images.Length; i++) - { - if (images[i].Width != width || images[i].Height != height) - throw new ArgumentException("images not same size"); - } - - Bitmap final = new Bitmap(width, height); - - Task[,] resultBright = new Task[width, height]; - Task[,] resultBlend = new Task[width, height]; - - - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - Color[] potentialColors = new Color[images.Length]; - - for (int i = 0; i < potentialColors.Length; i++) - potentialColors[i] = images[i].GetPixel(x, y); - - if (oldWeight > 0f) - resultBright[x, y] = GetBrighter(potentialColors); - - if (oldWeight < 1f) - resultBlend[x, y] = GetAverage(potentialColors); - } - } - - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - Color brightColor = new Color(); - Color blendColor = new Color(); - Color finalColor = new Color(); - - if (oldWeight > 0f) - brightColor = await resultBright[x, y]; - - if (oldWeight < 1f) - blendColor = await resultBlend[x, y]; - - finalColor = await GetBlend(brightColor, blendColor, oldWeight); - - final.SetPixel(x, y, finalColor); - } - } - - return final; - } - - public static async Task GetBrighter(Color[] colors) - { - Color brightest = new Color(); - int brightestScore = 0; - - for (int i = 0; i < colors.Length; i++) - { - if (ColorToInt(colors[i]) > brightestScore) - { - brightest = colors[i]; - brightestScore = ColorToInt(colors[i]); - } - } - - return brightest; - } - - public static int ColorToInt(Color color) - { - return color.R + color.B + color.G; - } - - public static async Task GetAverage(Color[] colors) - { - int red = 0; - int green = 0; - int blue = 0; - - for (int i = 0; i < colors.Length; i++) - { - red += colors[i].R; - green += colors[i].G; - blue += colors[i].B; - } - - red = red / colors.Length; - green = green / colors.Length; - blue = blue / colors.Length; - - if (red > 255) - red = 255; - - if (green > 255) - green = 255; - - if (blue > 255) - blue = 255; - - return Color.FromArgb(red, green, blue); - } - - public static async Task GetBlend(Color color1, Color color2, float weight) - { - return Color.FromArgb((int)(((weight) * color1.R) + ((1 - weight) * color2.R)), (int)(((weight) * color1.G) + ((1 - weight) * color2.G)), (int)(((weight) * color1.B) + ((1 - weight) * color2.B))); - } - public class FloatImage { public class FloatColor