Commit 7e7e39a8 authored by BORNON Théophile's avatar BORNON Théophile

Better faster stronger

parent 77e62751
......@@ -3,7 +3,7 @@ using System.Threading;
namespace S04_Projet
{
class MultiThreadedTask
unsafe class MultiThreadedTask
{
#region Attributs
public enum Operation
......@@ -20,6 +20,8 @@ namespace S04_Projet
}
private byte[] file;
private byte[] NewRMatrix, NewGMatrix, NewBMatrix;
byte* rPixelPtr, gPixelPtr, bPixelPtr;
private int nbPixel;
private int nbProcessors;
private Options opt;
......@@ -49,8 +51,11 @@ namespace S04_Projet
this.opt = opt;
this.filter = filter;
this.factor = factor;
this.rPixelPtr = rPixelPtr;
this.gPixelPtr = gPixelPtr;
this.bPixelPtr = bPixelPtr;
size = filter.GetLength(0);
nbProcessors = Environment.ProcessorCount;
nbProcessors = 4;
}
public void Start()
......@@ -96,10 +101,14 @@ namespace S04_Projet
#endregion
#region Filter
public void ApplyFilter()
public MyImage ApplyFilter()
{
int pixelNumber = opt.width * opt.height;
int pixelPerThread = pixelNumber / nbProcessors;
NewRMatrix = new byte[pixelNumber];
NewGMatrix = new byte[pixelNumber];
NewBMatrix = new byte[pixelNumber];
Thread[] threads = new Thread[nbProcessors];
Console.WriteLine("Creating {0} thread(s)", nbProcessors);
......@@ -114,9 +123,11 @@ namespace S04_Projet
{
threads[i].Join();
}
return new MyImage(opt, NewRMatrix, NewGMatrix, NewBMatrix);
}
public unsafe void ApplyFilterTask(object i)
private unsafe void ApplyFilterTask(object i)
{
int x, y;
int start = opt.width * opt.height / nbProcessors * (int)i;
......@@ -141,7 +152,10 @@ namespace S04_Projet
r = ConvolutionalResult(rMatrixPtr, filterPtr, size, factor);
g = ConvolutionalResult(gMatrixPtr, filterPtr, size, factor);
b = ConvolutionalResult(bMatrixPtr, filterPtr, size, factor);
NewRMatrix[j] = r;
NewGMatrix[j] = g;
NewBMatrix[j] = b;
}
}
}
......@@ -167,12 +181,12 @@ namespace S04_Projet
if (y < 0) y = 0;
else if (y >= opt.height) y = opt.height - 1;
if (rgb == RGB.R) ;
// *(matrixPtr + i) = Pixels[x, y].r;
else if (rgb == RGB.G) ;
// *(matrixPtr + i) = Pixels[x, y].g;
else if (rgb == RGB.B) ;
// *(matrixPtr + i) = Pixels[x, y].b;
if (rgb == RGB.R)
*(matrixPtr + i) = *(rPixelPtr + x + y * opt.width);
else if (rgb == RGB.G)
*(matrixPtr + i) = *(gPixelPtr + x + y * opt.width);
else if (rgb == RGB.B)
*(matrixPtr + i) = *(bPixelPtr + x + y * opt.width);
}
}
......
This diff is collapsed.
......@@ -60,12 +60,12 @@ namespace S04_Projet
Stopwatch sw = new Stopwatch();
MyImage imgg = new MyImage("img/image.bmp");
Console.WriteLine("Loading done");
sw.Start();
MyImage imgg = new MyImage("img/flocon.bmp");
MyImage newImg = imgg.Filter(sharpenFilter, 1);
sw.Stop();
imgg.Save("test.bmp");
Console.WriteLine("Loading done");
//imgg.ApplyConvFilter(edgeDetect1Filter, 1);
newImg.Save("filter.bmp");
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();
......
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