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

GUI 90% done. Create image from nothing and innovation left to do

parent 6c0d4b85
...@@ -13,31 +13,44 @@ namespace S04_Projet ...@@ -13,31 +13,44 @@ namespace S04_Projet
/// </summary> /// </summary>
public enum Operation public enum Operation
{ {
Rotate90 = 0, Enlarge = 0,
Shrink,
Rotate90,
Rotate180, Rotate180,
Rotate270, Rotate270,
GrayScaleLinear, GrayScaleLinear,
GrayScaleLuminosity, GrayScaleLuminosity,
Shrink, Superposition,
SwitchMultiThreading, Filter,
CreateImage,
Histogram,
Innovation,
Debug,
Save Save
} }
private static string[] menuItems = new string[] private static string[] menuItems = new string[]
{ {
"Rotation à 90°", "Agrandir l'image",
"Rotation à 180°", "Rétrécir l'image",
"Rotation à 270°", "Rotation à 90°",
"Passage à une image en nuances de gris (linéairement)", "Rotation à 180°",
"Passage à une image en nuances de gris (luminosité)", "Rotation à 270°",
"Rétrécissement de l'image", "Passage à une image en nuances de gris (linéairement)",
"Désactiver le multithreading", "Passage à une image en nuances de gris (luminosité)",
"Sauvegarder" "Superposer avec une autre image",
"Ajouter un filtre de convolution",
"Créer une image",
"Générer les histogrammes de l'image",
"",
"Activer le mode debug",
"Sauvegarder"
}; };
public static long elapsedTime; public static long elapsedTime;
public static string lastOperationMessage; public static string lastOperationMessage;
public static string fileInfos; public static string fileInfos;
private static Stopwatch sw = new Stopwatch();
/// <summary> /// <summary>
/// Charge l'image /// Charge l'image
...@@ -48,6 +61,7 @@ namespace S04_Projet ...@@ -48,6 +61,7 @@ namespace S04_Projet
string path; string path;
bool validPath = false; bool validPath = false;
byte[] file = new byte[0]; byte[] file = new byte[0];
do do
{ {
Console.WriteLine("Veuillez saisir le nom du fichier à traiter :"); Console.WriteLine("Veuillez saisir le nom du fichier à traiter :");
...@@ -66,22 +80,16 @@ namespace S04_Projet ...@@ -66,22 +80,16 @@ namespace S04_Projet
} while (!validPath); } while (!validPath);
Console.Clear(); Console.Clear();
/*Thread waitingThread = new Thread(new ThreadStart(WaitingScreen));
Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
waitingThread.Start();*/
MyImage image = new MyImage(path); MyImage image = new MyImage(path);
/*waitingThread.Abort();
sw.Stop(); sw.Stop();
Console.Clear(); Console.Clear();
elapsedTime = sw.ElapsedMilliseconds; elapsedTime = sw.ElapsedMilliseconds;
lastOperationMessage = "Image chargée en " + elapsedTime + "ms"; lastOperationMessage = "Image chargée en " + elapsedTime + "ms";
fileInfos = image.ToString(); fileInfos = image.ToString();
*/
return image; return image;
} }
...@@ -133,6 +141,221 @@ namespace S04_Projet ...@@ -133,6 +141,221 @@ namespace S04_Projet
return (Operation)choosenItem; return (Operation)choosenItem;
} }
public static MyImage PerformOperation(Operation ope, MyImage img)
{
MyImage output = null;
Console.Clear();
switch (ope)
{
case Operation.Enlarge:
output = EnlargeOperation(img);
break;
case Operation.Shrink:
output = ShrinkOperation(img);
break;
case Operation.Rotate90:
output = img.Rotate90();
break;
case Operation.Rotate180:
output = img.Rotate180();
break;
case Operation.Rotate270:
output = img.Rotate270();
break;
case Operation.GrayScaleLinear:
output = GrayOperation(img, ope);
break;
case Operation.GrayScaleLuminosity:
output = GrayOperation(img, ope);
break;
case Operation.Superposition:
output = SuperpositionOperation(img);
break;
case Operation.Filter: // TODO
output = FilterOperation(img);
break;
case Operation.CreateImage: // TODO
break;
case Operation.Histogram:
output = HistogramOperation(img);
break;
// TODO INNOVATION
case Operation.Debug:
output = DebugOperation(img);
break;
case Operation.Save:
SaveOperation(img);
break;
}
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;
}
public static MyImage EnlargeOperation(MyImage img)
{
int coeff = 0;
bool error = false;
do
{
if (error) AlertMessage("Un nombre entier supérieur à 0 est attendu.");
Console.WriteLine("Quel coefficient d'aggrandissement souhaitez-vous utiliser ?");
} while (error = !int.TryParse(Console.ReadLine(), out coeff) || coeff <= 0);
sw.Restart();
return img.Enlarge(coeff);
}
public static MyImage ShrinkOperation(MyImage img)
{
int coeff = 0;
bool error = false;
do
{
if (error) AlertMessage("Un nombre entier supérieur à 0 est attendu.");
Console.WriteLine("Quel coefficient de rétrécissement souhaitez-vous utiliser ?");
} while (error = !int.TryParse(Console.ReadLine(), out coeff) && coeff <= 0);
sw.Restart();
return img.Shrink(coeff);
}
public static MyImage GrayOperation(MyImage img, Operation ope)
{
int nbScale = 0;
bool error = false;
do
{
if (error) AlertMessage("Un nombre entier supérieur à 1 et inférieur ou égal à 255 est attendu.");
Console.WriteLine("Combien de nuances de gris souhaitez-vous obtenir ?");
} while (error = !int.TryParse(Console.ReadLine(), out nbScale) && nbScale <= 1 && nbScale > 255);
sw.Restart();
if (ope == Operation.GrayScaleLinear) return img.ToGrayScale((byte)nbScale, MyImage.GrayFilterType.LINEAR);
else return img.ToGrayScale((byte)nbScale, MyImage.GrayFilterType.LUMINOSITY);
}
public static MyImage SuperpositionOperation(MyImage img)
{
string path = "";
MyImage secondImg = null;
byte[] file = null;
int x = 0;
int y = 0;
bool error = true;
// Get path to image
do
{
error = false;
Console.WriteLine("Veuillez saisir le chemin de l'image que vous voulez superposer à cette image :");
path = Console.ReadLine();
try
{
file = File.ReadAllBytes(path);
}
catch (Exception e)
{
error = true;
AlertMessage("Une erreur est survenue : \n" + e.Message);
}
} while (error);
secondImg = new MyImage(file);
do
{
if (error) AlertMessage("Un nombre entier est attendu.");
Console.WriteLine("A quelle coordonnée x souhaitez vous placer l'image à superposer ?");
} while (error = !int.TryParse(Console.ReadLine(), out x));
do
{
if (error) AlertMessage("Un nombre entier est attendu.");
Console.WriteLine("A quelle coordonnée y souhaitez vous placer l'image à superposer ?");
} while (error = !int.TryParse(Console.ReadLine(), out y));
sw.Restart();
return img.Superposition(secondImg, x, y);
}
public static MyImage FilterOperation(MyImage img)
{
return null;
}
public static MyImage HistogramOperation(MyImage img)
{
int width = 0;
bool error = false;
string path = "";
do
{
if (error) AlertMessage("Un nombre entier supérieur à 0 est attendu.");
Console.WriteLine("Quel largeur souhaitez-vous utiliser pour l'histogramme ?");
} while (error = !int.TryParse(Console.ReadLine(), out width) || width <= 0);
error = false;
do
{
if (error) AlertMessage("Un chemin valide vers un dossier est attendu");
Console.WriteLine("Veuillez saisir le chemin du sauvegarde des histogrammes :");
path = Console.ReadLine();
} while (error = !Directory.Exists(path));
if (!path.EndsWith("\\")) path += "\\";
sw.Restart();
MyImage[] histograms = img.Histogram(width);
histograms[0].Save(path + "red.bmp");
histograms[1].Save(path + "green.bmp");
histograms[2].Save(path + "blue.bmp");
return img;
}
public static MyImage DebugOperation(MyImage img)
{
sw.Restart();
if (Program.DEBUG)
{
Program.DEBUG = false;
menuItems[(int)Operation.Debug] = "Activer le mode debug";
}
else
{
Program.DEBUG = true;
menuItems[(int)Operation.Debug] = "Désactiver le mode debug";
}
return img;
}
public static MyImage SaveOperation(MyImage img)
{
bool error = false;
string path = "";
error = false;
Console.WriteLine("Veuillez saisir le chemin de sauvegarde du fichier");
path = Console.ReadLine();
if (!path.EndsWith(".bmp")) path += ".bmp";
img.Save(path);
return null;
}
public static void AlertMessage(string msg)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(msg);
Console.ForegroundColor = ConsoleColor.White;
}
/// <summary> /// <summary>
/// Effectue l'opération demandée sur l'image passée en paramètres /// Effectue l'opération demandée sur l'image passée en paramètres
/// </summary> /// </summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace S04_Projet
{
public class Filter
{
public static short[,] boxBlurFilter = new short[,]
{
{ 1, 1, 1 },
{ 1, 1, 1 },
{ 1, 1, 1 }
};
public static short[,] identityFilter = new short[,]
{
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 0 }
};
public static short[,] edgeDetect1Filter = new short[,]
{
{ 1, 0, -1 },
{ 0, 0, 0 },
{ -1, 0, 1 }
};
public static short[,] edgeDetect2Filter = new short[,]
{
{ 0, 1, 0 },
{ 1, -4, 1 },
{ 0, 1, 0 }
};
public static short[,] edgeDetect3Filter = new short[,]
{
{ -1, -1, -1 },
{ -1, 8, -1 },
{ -1, -1, -1 }
};
public static short[,] sharpenFilter = new short[,]
{
{ 0, -1, 0 },
{ -1, 5, -1 },
{ 0, -1, 0 }
};
}
}
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Filter.cs" />
<Compile Include="MultiThreadedTask.cs" /> <Compile Include="MultiThreadedTask.cs" />
<Compile Include="MyImage.cs" /> <Compile Include="MyImage.cs" />
<Compile Include="Display.cs" /> <Compile Include="Display.cs" />
......
...@@ -194,7 +194,15 @@ namespace S04_Projet ...@@ -194,7 +194,15 @@ namespace S04_Projet
} }
#endregion #endregion
File.WriteAllBytes(output, file); try
{
File.WriteAllBytes(output, file);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Une erreur est survenue lors de la sauvegarde du fichier : \n" + e.Message);
}
} }
/// <summary> /// <summary>
...@@ -207,7 +215,7 @@ namespace S04_Projet ...@@ -207,7 +215,7 @@ namespace S04_Projet
} }
#endregion #endregion
#region Image processing
#region Rotations #region Rotations
/// <summary> /// <summary>
/// Tourne l'image de 90° dans le sens horaire /// Tourne l'image de 90° dans le sens horaire
...@@ -311,50 +319,50 @@ namespace S04_Projet ...@@ -311,50 +319,50 @@ namespace S04_Projet
#endregion #endregion
/// <summary> /// <summary>
/// Agrandit l'image par rapport au coefficient passé en paramètre /// Passe l'image en nuances de gris
/// </summary> /// </summary>
/// <param name="coeff">Coefficient d'agrandissement de l'image</param> /// <param name="scale">Nombre de nuances de gris désirées (entre 2 et 255) (2 = noir et blanc)</param>
/// <returns>Image élargie</returns> /// <param name="type">Type de transformation. Linéaire ou en fonction de la luminosité de la couleur</param>
public unsafe MyImage Enlarge(int coeff) /// <returns>Image en nuances de gris</returns>
public unsafe MyImage ToGrayScale(byte scale, GrayFilterType type)
{ {
Options options = opt.Copy(); Options options = opt.Copy();
options.width *= coeff; opt.nbColor = scale;
options.height *= coeff; int size = opt.height * opt.width;
int nbPixel = opt.width * opt.height;
int nbNewPixel = options.width * options.height;
byte[] newPixelR = new byte[nbNewPixel];
byte[] newPixelG = new byte[nbNewPixel];
byte[] newPixelB = new byte[nbNewPixel];
int x, y, x0, y0;
fixed (byte* newRPtr = newPixelR, newGPtr = newPixelG, newBPtr = newPixelB) byte[] newRPixel = new byte[size];
byte[] newGPixel = new byte[size];
byte[] newBPixel = new byte[size];
fixed (byte* newRPixePtr = newRPixel, newGPixePtr = newGPixel, newBPixePtr = newBPixel)
{ {
fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels) fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
{ {
for (int i = 0; i < nbPixel; i++) for (int i = 0; i < opt.width * opt.height; i++)
{ {
x0 = i % opt.width; int x = i % opt.width;
y0 = i / opt.width; int y = i / opt.width;
for (int j = 0; j < coeff * coeff; j++) if (type == GrayFilterType.LINEAR)
{ {
x = x0 * coeff + j % coeff; *(newRPixePtr + x + y * opt.width) =
y = y0 * coeff + j / coeff; *(newGPixePtr + x + y * opt.width) =
*(newBPixePtr + x + y * opt.width) = GetGray(*(rPtr + x + y * opt.width), *(gPtr + x + y * opt.width), *(bPtr + x + y * opt.width), scale);
*(newRPtr + x + y * options.width) = *(rPtr + i);
*(newGPtr + x + y * options.width) = *(gPtr + i);
*(newBPtr + x + y * options.width) = *(bPtr + i);
} }
else if (type == GrayFilterType.LUMINOSITY)
*(newRPixePtr + x + y * opt.width) =
*(newGPixePtr + x + y * opt.width) =
*(newBPixePtr + x + y * opt.width) = GetGrayLuminosity(*(rPtr + x + y * opt.width), *(gPtr + x + y * opt.width), *(bPtr + x + y * opt.width), scale);
} }
} }
} }
return new MyImage(options, newRPixel, newGPixel, newBPixel);
return new MyImage(options, newPixelR, newPixelG, newPixelB);
} }
public unsafe MyImage EnlargeGradient(int coeff) /// <summary>
/// Agrandit l'image par rapport au coefficient passé en paramètre
/// </summary>
/// <param name="coeff">Coefficient d'agrandissement de l'image</param>
/// <returns>Image élargie</returns>
public unsafe MyImage Enlarge(int coeff)
{ {
Options options = opt.Copy(); Options options = opt.Copy();
options.width *= coeff; options.width *= coeff;
...@@ -393,53 +401,6 @@ namespace S04_Projet ...@@ -393,53 +401,6 @@ namespace S04_Projet
return new MyImage(options, newPixelR, newPixelG, newPixelB); return new MyImage(options, newPixelR, newPixelG, newPixelB);
} }
/*private unsafe byte[] GenerateGradient(int x, int y, int coeff, RGB rgb, byte* rPtr, byte* gPtr, byte* bPtr)
{
// cf https://stackoverflow.com/a/1106986
int squareCoeff = coeff * coeff;
byte[,] grad = new byte[squareCoeff,3];
byte[] A_RGB, B_RGB, C_RGB, D_RGB;
#region Define ABCD
int xPlus = x + 1 < opt.width ? x + 1 : x;
int yPlus = y + 1 < opt.width ? y + 1 : y;
A_RGB = new byte[] {
*(rPtr + x + y * opt.width),
*(gPtr + x + y * opt.width),
*(bPtr + x + y * opt.width)
};
B_RGB = new byte[] {
*(rPtr + xPlus + y * opt.width),
*(gPtr + xPlus + y * opt.width),
*(bPtr + xPlus + y * opt.width)
};
C_RGB = new byte[] {
*(rPtr + xPlus + yPlus * opt.width),
*(gPtr + xPlus + yPlus * opt.width),
*(bPtr + xPlus + yPlus * opt.width)
};
D_RGB = new byte[] {
*(rPtr + x + yPlus * opt.width),
*(gPtr + x + yPlus * opt.width),
*(bPtr + x + yPlus * opt.width)
};
#endregion
int x0, y0;
for (int i = 1; i < squareCoeff; i++)
{
x0 = i % coeff;
y0 = i / coeff;
}
}*/
/// <summary> /// <summary>
/// Rétrécit l'image par rapport au coefficient passé en paramètres /// Rétrécit l'image par rapport au coefficient passé en paramètres
/// </summary> /// </summary>
...@@ -497,72 +458,6 @@ namespace S04_Projet ...@@ -497,72 +458,6 @@ namespace S04_Projet
return new MyImage(options, newRPixel, newGPixel, newBPixel); return new MyImage(options, newRPixel, newGPixel, newBPixel);
} }
#region Gray tasks
/// <summary>
/// Passe l'image en nuances de gris
/// </summary>
/// <param name="scale">Nombre de nuances de gris désirées (entre 2 et 255) (2 = noir et blanc)</param>
/// <param name="type">Type de transformation. Linéaire ou en fonction de la luminosité de la couleur</param>
/// <returns>Image en nuances de gris</returns>
public unsafe MyImage ToGrayScale(byte scale, GrayFilterType type)
{
Options options = opt.Copy();
opt.nbColor = scale;
int size = opt.height * opt.width;
byte[] newRPixel = new byte[size];
byte[] newGPixel = new byte[size];
byte[] newBPixel = new byte[size];
fixed (byte* newRPixePtr = newRPixel, newGPixePtr = newGPixel, newBPixePtr = newBPixel)
{
fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
{
for (int i = 0; i < opt.width * opt.height; i++)
{
int x = i % opt.width;
int y = i / opt.width;
if (type == GrayFilterType.LINEAR)
{
*(newRPixePtr + x + y * opt.width) =
*(newGPixePtr + x + y * opt.width) =
*(newBPixePtr + x + y * opt.width) = GetGray(*(rPtr + x + y * opt.width), *(gPtr + x + y * opt.width), *(bPtr + x + y * opt.width), scale);
}
else if (type == GrayFilterType.LUMINOSITY)
*(newRPixePtr + x + y * opt.width) =
*(newGPixePtr + x + y * opt.width) =
*(newBPixePtr + x + y * opt.width) = GetGrayLuminosity(*(rPtr + x + y * opt.width), *(gPtr + x + y * opt.width), *(bPtr + x + y * opt.width), scale);
}
}
}
return new MyImage(options, newRPixel, newGPixel, newBPixel);
}
/// <summary>
/// Retourne l'équavalent gris d'un pixel
/// </summary>
/// <param name="scale">Nombre de nuances de gris</param>
/// <returns>Pixel en échelle de gris</returns>
public byte GetGray(byte r, byte g, byte b, byte scale)
{
byte total = (byte)((r + g + b) / 3);
total = (byte)(Math.Round((double)total / (255 / (scale - 1))) * (255 / (scale - 1)));
return total;
}
/// <summary>
/// Retourne l'équivalent gris d'un pixel en prenant en compte les coefficients de luminosité
/// des couleurs RGB
/// </summary>
/// <param name="scale"></param>
/// <returns></returns>
public byte GetGrayLuminosity(byte r, byte g, byte b, byte scale)
{
byte total = (byte)(0.21 * r + 0.72 * g + 0.07 * b);
total = (byte)(Math.Round((double)total / (255 / (scale - 1))) * (255 / (scale - 1)));
return total;
}
#endregion
/// <summary> /// <summary>
/// Applique un filtre de convolution sur une image /// Applique un filtre de convolution sur une image
/// </summary> /// </summary>
...@@ -652,7 +547,7 @@ namespace S04_Projet ...@@ -652,7 +547,7 @@ namespace S04_Projet
Images[2] = new MyImage(options, new byte[options.width * options.height], new byte[options.width * options.height], newBPixel); Images[2] = new MyImage(options, new byte[options.width * options.height], new byte[options.width * options.height], newBPixel);
return Images; return Images;
} }
public unsafe MyImage Superposition(MyImage img, int x, int y) public unsafe MyImage Superposition(MyImage img, int x, int y)
{ {
byte[] newRPixel = rPixels; byte[] newRPixel = rPixels;
...@@ -666,19 +561,24 @@ namespace S04_Projet ...@@ -666,19 +561,24 @@ namespace S04_Projet
for (int i = 0; i < img.opt.height; i++) for (int i = 0; i < img.opt.height; i++)
{ {
if (y + i >= opt.height) break; if (y + i >= opt.height) break;
for (int j = 0; j < img.opt.width; j++) else if (y + i >= 0)
{ for (int j = 0; j < img.opt.width; j++)
if (x + j >= opt.width) break; {
*(newRPtr + x + j + (y + i) * opt.width) = *(rPixelPtr + i * img.opt.width + j); if (x + j >= opt.width) break;
*(newGPtr + x + j + (y + i) * opt.width) = *(gPixelPtr + i * img.opt.width + j); else if (x + j >= 0)
*(newBPtr + x + j + (y + i) * opt.width) = *(bPixelPtr + i * img.opt.width + j); {
} *(newRPtr + x + j + (y + i) * opt.width) = *(rPixelPtr + i * img.opt.width + j);
*(newGPtr + x + j + (y + i) * opt.width) = *(gPixelPtr + i * img.opt.width + j);
*(newBPtr + x + j + (y + i) * opt.width) = *(bPixelPtr + i * img.opt.width + j);
}
}
} }
} }
} }
return new MyImage(opt, newRPixel, newGPixel, newBPixel); return new MyImage(opt, newRPixel, newGPixel, newBPixel);
} }
#endregion
#region Helpers #region Helpers
/// <summary> /// <summary>
...@@ -725,6 +625,31 @@ namespace S04_Projet ...@@ -725,6 +625,31 @@ namespace S04_Projet
return HSV; return HSV;
} }
/// <summary>
/// Retourne l'équavalent gris d'un pixel
/// </summary>
/// <param name="scale">Nombre de nuances de gris</param>
/// <returns>Pixel en échelle de gris</returns>
private byte GetGray(byte r, byte g, byte b, byte scale)
{
byte total = (byte)((r + g + b) / 3);
total = (byte)(Math.Round((double)total / (255 / (scale - 1))) * (255 / (scale - 1)));
return total;
}
/// <summary>
/// Retourne l'équivalent gris d'un pixel en prenant en compte les coefficients de luminosité
/// des couleurs RGB
/// </summary>
/// <param name="scale"></param>
/// <returns></returns>
private byte GetGrayLuminosity(byte r, byte g, byte b, byte scale)
{
byte total = (byte)(0.21 * r + 0.72 * g + 0.07 * b);
total = (byte)(Math.Round((double)total / (255 / (scale - 1))) * (255 / (scale - 1)));
return total;
}
private unsafe byte MaxRGB(int i) private unsafe byte MaxRGB(int i)
{ {
fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels) fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
...@@ -817,5 +742,95 @@ namespace S04_Projet ...@@ -817,5 +742,95 @@ namespace S04_Projet
return str; return str;
} }
#endregion #endregion
#region WIP
/*
public unsafe MyImage EnlargeGradient(int coeff)
{
Options options = opt.Copy();
options.width *= coeff;
options.height *= coeff;
int nbPixel = opt.width * opt.height;
int nbNewPixel = options.width * options.height;
byte[] newPixelR = new byte[nbNewPixel];
byte[] newPixelG = new byte[nbNewPixel];
byte[] newPixelB = new byte[nbNewPixel];
int x, y, x0, y0;
fixed (byte* newRPtr = newPixelR, newGPtr = newPixelG, newBPtr = newPixelB)
{
fixed (byte* rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
{
for (int i = 0; i < nbPixel; i++)
{
x0 = i % opt.width;
y0 = i / opt.width;
for (int j = 0; j < coeff * coeff; j++)
{
x = x0 * coeff + j % coeff;
y = y0 * coeff + j / coeff;
*(newRPtr + x + y * options.width) = *(rPtr + i);
*(newGPtr + x + y * options.width) = *(gPtr + i);
*(newBPtr + x + y * options.width) = *(bPtr + i);
}
}
}
}
return new MyImage(options, newPixelR, newPixelG, newPixelB);
}
*/
/*
private unsafe byte[] GenerateGradient(int x, int y, int coeff, RGB rgb, byte* rPtr, byte* gPtr, byte* bPtr)
{
// cf https://stackoverflow.com/a/1106986
int squareCoeff = coeff * coeff;
byte[,] grad = new byte[squareCoeff,3];
byte[] A_RGB, B_RGB, C_RGB, D_RGB;
#region Define ABCD
int xPlus = x + 1 < opt.width ? x + 1 : x;
int yPlus = y + 1 < opt.width ? y + 1 : y;
A_RGB = new byte[] {
*(rPtr + x + y * opt.width),
*(gPtr + x + y * opt.width),
*(bPtr + x + y * opt.width)
};
B_RGB = new byte[] {
*(rPtr + xPlus + y * opt.width),
*(gPtr + xPlus + y * opt.width),
*(bPtr + xPlus + y * opt.width)
};
C_RGB = new byte[] {
*(rPtr + xPlus + yPlus * opt.width),
*(gPtr + xPlus + yPlus * opt.width),
*(bPtr + xPlus + yPlus * opt.width)
};
D_RGB = new byte[] {
*(rPtr + x + yPlus * opt.width),
*(gPtr + x + yPlus * opt.width),
*(bPtr + x + yPlus * opt.width)
};
#endregion
int x0, y0;
for (int i = 1; i < squareCoeff; i++)
{
x0 = i % coeff;
y0 = i / coeff;
}
}*/
#endregion
} }
} }
\ No newline at end of file
...@@ -13,65 +13,24 @@ namespace S04_Projet ...@@ -13,65 +13,24 @@ namespace S04_Projet
{ {
public static bool MULTITHREADING_LOAD = false; public static bool MULTITHREADING_LOAD = false;
public static bool MULTITHREADING = true; public static bool MULTITHREADING = true;
public static bool DEBUG = false;
static void Main(string[] args) static void Main(string[] args)
{ {
#region Filters Matrix
short[,] boxBlurFilter = new short[,] {
{1,1,1 },
{1,1,1 },
{1,1,1 }
};
short[,] identityFilter = new short[,]
{
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 0 }
};
short[,] edgeDetect1Filter = new short[,]
{
{ 1, 0, -1 },
{ 0, 0, 0 },
{ -1, 0, 1 }
};
short[,] edgeDetect2Filter = new short[,]
{
{ 0, 1, 0 },
{ 1, -4, 1 },
{ 0, 1, 0 }
};
short[,] edgeDetect3Filter = new short[,]
{
{ -1, -1, -1 },
{ -1, 8, -1 },
{ -1, -1, -1 }
};
short[,] sharpenFilter = new short[,]
{
{ 0, -1, 0 },
{ -1, 5, -1 },
{ 0, -1, 0 }
};
#endregion
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
MyImage img = new MyImage("img/image.bmp"); /*MyImage img = new MyImage("img/image.bmp");
MyImage imgg = new MyImage("img/flocon.bmp"); MyImage imgg = new MyImage("img/flocon.bmp");
Console.WriteLine("Loading done"); Console.WriteLine("Loading done");
sw.Start(); sw.Start();
MyImage supperposition = img.Superposition(imgg, 4000, 0); MyImage supperposition = img.Superposition(imgg, -6000, -8000);
sw.Stop(); sw.Stop();
supperposition.Save("sup.bmp"); supperposition.Save("sup.bmp");
Console.WriteLine(sw.ElapsedMilliseconds); Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read(); Console.Read();*/
/*
#region Arguments /*#region Arguments
if (args.Length > 0) if (args.Length > 0)
{ {
MULTITHREADING = false; MULTITHREADING = false;
...@@ -111,10 +70,10 @@ namespace S04_Projet ...@@ -111,10 +70,10 @@ namespace S04_Projet
Console.WriteLine("--input argument required"); Console.WriteLine("--input argument required");
} }
} }
#endregion #endregion*/
#region Display #region Display
else
{ {
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("#############################################################"); Console.WriteLine("#############################################################");
...@@ -138,7 +97,7 @@ namespace S04_Projet ...@@ -138,7 +97,7 @@ namespace S04_Projet
Console.Read(); Console.Read();
} }
#endregion #endregion
*/
} }
} }
} }
This image diff could not be displayed because it is too large. You can view the blob instead.
This image diff could not be displayed because it is too large. You can view the blob instead.
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