remove old

This commit is contained in:
AUnicornWithNoLife 2023-01-13 09:36:54 +00:00
parent cb99858cf7
commit 59a6938b0a

View File

@ -30,33 +30,7 @@ namespace Cupola
ConsoleKey keyGG = Console.ReadKey().Key; ConsoleKey keyGG = Console.ReadKey().Key;
if (keyGG == ConsoleKey.S) if (keyGG == ConsoleKey.F)
{
Bitmap final = await Combine(images.ToArray(), 0.6f);
final.Save(name + ".png");
}
else if (keyGG == ConsoleKey.M)
{
Dictionary<string, Task<Bitmap>> log = new Dictionary<string, Task<Bitmap>>();
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<string, Task<Bitmap>> logItem in log)
{
Console.WriteLine(logItem.Key);
Bitmap img = await logItem.Value;
img.Save(logItem.Key);
}
}
else if (keyGG == ConsoleKey.F)
{ {
FloatImage[] fImages = new FloatImage[images.Count]; FloatImage[] fImages = new FloatImage[images.Count];
@ -103,119 +77,6 @@ namespace Cupola
} }
} }
public static async Task<Bitmap> 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<Color>[,] resultBright = new Task<Color>[width, height];
Task<Color>[,] resultBlend = new Task<Color>[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<Color> 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<Color> 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<Color> 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 FloatImage
{ {
public class FloatColor public class FloatColor