Commit ed73cdc6 authored by Théophile BORNON's avatar Théophile BORNON

UI done

parent ed995b81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.IO;
using System.Threading;
......@@ -21,6 +21,10 @@ namespace S04_Projet
Save
}
public static long elapsedTime;
public static string lastOperationMessage;
public static string fileInfos;
/// <summary>
/// Charge l'image
/// </summary>
......@@ -51,6 +55,9 @@ namespace S04_Projet
MyImageThread myImageThread = new MyImageThread(file);
Thread imageThread = new Thread(new ThreadStart(myImageThread.ThreadLoop));
Stopwatch sw = new Stopwatch();
sw.Start();
imageThread.Start();
Console.Write("Traitement en cours de l'image.");
......@@ -59,13 +66,12 @@ namespace S04_Projet
Thread.Sleep(250);
Console.Write(".");
}
sw.Stop();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Image chargée en {0}ms\n", myImageThread.loadTime);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(myImageThread.image.toString());
Console.ForegroundColor = ConsoleColor.White;
elapsedTime = sw.ElapsedMilliseconds;
lastOperationMessage = "Image chargée en " + elapsedTime + "ms";
fileInfos = myImageThread.image.toString();
return myImageThread.image;
}
......@@ -76,6 +82,14 @@ namespace S04_Projet
/// <returns>Retourne le type d'opération souhaitée</returns>
public static Operation AskForOperation()
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(lastOperationMessage);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(fileInfos);
Console.ForegroundColor = ConsoleColor.White;
int choosenItem = 0;
string[] menuItems = new string[]
{
......@@ -100,12 +114,12 @@ namespace S04_Projet
key = Console.ReadKey();
Console.SetCursorPosition(0, 9 + choosenItem);
Console.Write(" ");
if(key.Key == ConsoleKey.DownArrow)
if (key.Key == ConsoleKey.DownArrow)
{
choosenItem++;
if (choosenItem == menuItems.Length) choosenItem = 0;
}
else if(key.Key == ConsoleKey.UpArrow)
else if (key.Key == ConsoleKey.UpArrow)
{
choosenItem--;
if (choosenItem == -1) choosenItem = menuItems.Length - 1;
......@@ -128,12 +142,14 @@ namespace S04_Projet
public static MyImage PerformOperation(Operation ope, MyImage img)
{
MyImage output = null;
Stopwatch sw = new Stopwatch();
Console.Clear();
sw.Start();
if (ope == Operation.Rotate90) output = img.Rotate90();
else if (ope == Operation.Rotate180) output = img.Rotate180();
else if (ope == Operation.Rotate270) output = img.Rotate270();
else if(ope == Operation.GrayScaleLinear || ope == Operation.GrayScaleLuminosity)
else if (ope == Operation.GrayScaleLinear || ope == Operation.GrayScaleLuminosity)
{
bool retry = false;
int input;
......@@ -146,10 +162,11 @@ namespace S04_Projet
retry = !int.TryParse(Console.ReadLine(), out input);
} while (retry && input >= 2 && input <= 255);
sw.Restart();
if (ope == Operation.GrayScaleLinear) output = img.ToGrayScale((byte)input, MyImage.grayFilterType.LINEAR);
else if (ope == Operation.GrayScaleLuminosity) output = img.ToGrayScale((byte)input, MyImage.grayFilterType.LUMINOSITY);
}
else if(ope == Operation.Save)
else if (ope == Operation.Save)
{
string path;
bool anotherTry = false;
......@@ -162,6 +179,7 @@ namespace S04_Projet
if (!path.EndsWith(".bmp")) path += ".bmp";
} while (anotherTry = !Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute));
sw.Restart();
img.Save(path);
}
else
......@@ -169,6 +187,11 @@ namespace S04_Projet
throw new Exception("Opération non reconnue");
}
sw.Stop();
elapsedTime = sw.ElapsedMilliseconds;
lastOperationMessage = String.Format("Opération {0}, effectuée avec succès en {1}ms", ope, elapsedTime);
fileInfos = (output != null) ? output.toString() : "";
return output;
}
}
......
......@@ -90,9 +90,9 @@ namespace S04_Projet
{
int x = i % opt.width;
int y = i / opt.width;
byte r = file[i * 3 + opt.offset];
byte b = file[i * 3 + opt.offset];
byte g = file[i * 3 + opt.offset + 1];
byte b = file[i * 3 + opt.offset + 2];
byte r = file[i * 3 + opt.offset + 2];
Pixels[x, y] = new Pixel(r, g, b);
}
#endregion
......@@ -155,7 +155,7 @@ namespace S04_Projet
#region Pixel array
for (int i = 0; i < nbPixel; i++)
{
MixArrays(file, Pixels[i % opt.width, i / opt.width].getRGB(), 54 + (i * 3));
MixArrays(file, Pixels[i % opt.width, i / opt.width].getBGR(), 54 + (i * 3));
}
#endregion
......@@ -332,6 +332,7 @@ namespace S04_Projet
public string toString()
{
string str = "";
str += String.Format("Format : {0}\nTaille : {1} octets", opt.format, opt.fileSize) + "\n";
str += String.Format("Offset : {0} octets", opt.offset) + "\n";
str += String.Format("File info header size : {0} octets", opt.fileInfoHeaderSize) + "\n";
......
......@@ -11,21 +11,15 @@ namespace S04_Projet
{
public byte[] file;
public MyImage image;
public long loadTime;
private Stopwatch sw;
public MyImageThread(byte[] file)
{
sw = new Stopwatch();
this.file = file;
}
public void ThreadLoop()
{
sw.Restart();
image = new MyImage(file);
sw.Stop();
loadTime = sw.ElapsedMilliseconds;
}
}
}
......@@ -56,6 +56,11 @@ namespace S04_Projet
return new byte[] { r, g, b };
}
public byte[] getBGR()
{
return new byte[] { b, g, r };
}
/// <summary>
/// Retourne l'équavalent gris d'un pixel
/// </summary>
......@@ -64,7 +69,7 @@ namespace S04_Projet
public Pixel getGrayScale(byte scale)
{
byte total = (byte)((r + g + b) / 3);
total = (byte)(Math.Round((double)total / (255/(scale-1))) * (255 / (scale - 1)));
total = (byte)(Math.Round((double)total / (255 / (scale - 1))) * (255 / (scale - 1)));
return new Pixel(total);
}
......
......@@ -21,9 +21,16 @@ namespace S04_Projet
MyImage img = Display.LoadImage();
Display.Operation ToDo = Display.AskForOperation();
Display.PerformOperation(ToDo, img);
MyImage newImg = Display.PerformOperation(ToDo, img);
while (newImg != null)
{
ToDo = Display.AskForOperation();
newImg = Display.PerformOperation(ToDo, newImg);
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Image sauvegardée en {0}ms!", Display.elapsedTime);
//Console.Clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment