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

UI done

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