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

Begining of enlarge gradient. Enlarge done

parent 7531c00a
...@@ -27,22 +27,14 @@ namespace S04_Projet ...@@ -27,22 +27,14 @@ namespace S04_Projet
private short[,] filter; private short[,] filter;
private double factor; private double factor;
private int size; private int size;
//private double stepSize;
private Operation ToDo;
#endregion #endregion
public void SetNbPixel(int nbPixel) => this.nbPixel = nbPixel; public void SetNbPixel(int nbPixel) => this.nbPixel = nbPixel;
public void SetFile(byte[] file) => this.file = file; public void SetFile(byte[] file) => this.file = file;
private Operation ToDo;
public MultiThreadedTask(Operation ToDo, byte[] file, Options opt)
{
this.ToDo = ToDo;
this.opt = opt;
this.file = file;
nbPixel = opt.width * opt.height;
nbProcessors = Environment.ProcessorCount;
}
public unsafe MultiThreadedTask(Operation ToDo, byte* rPixelPtr, byte* gPixelPtr, byte* bPixelPtr, Options opt, short[,] filter, double factor) public unsafe MultiThreadedTask(Operation ToDo, byte* rPixelPtr, byte* gPixelPtr, byte* bPixelPtr, Options opt, short[,] filter, double factor)
{ {
...@@ -58,21 +50,33 @@ namespace S04_Projet ...@@ -58,21 +50,33 @@ namespace S04_Projet
nbProcessors = 4; nbProcessors = 4;
} }
public unsafe MultiThreadedTask(Operation ToDo, Options opt, byte* rPixelPtr, byte* gPixelPtr, byte* bPixelPtr)
{
this.ToDo = ToDo;
this.rPixelPtr = rPixelPtr;
this.gPixelPtr = gPixelPtr;
this.bPixelPtr = bPixelPtr;
nbPixel = opt.width * opt.height;
}
#region Filter #region Filter
public MyImage ApplyFilter() public MyImage ApplyFilter()
{ {
int nbPixel = opt.width * opt.height;
int pixelPerThread = nbPixel / nbProcessors; int pixelPerThread = nbPixel / nbProcessors;
NewRMatrix = new byte[nbPixel]; NewRMatrix = new byte[nbPixel];
NewGMatrix = new byte[nbPixel]; NewGMatrix = new byte[nbPixel];
NewBMatrix = new byte[nbPixel]; NewBMatrix = new byte[nbPixel];
//stepSize = (Math.E - 1) / nbProcessors;
Thread[] threads = new Thread[nbProcessors]; Thread[] threads = new Thread[nbProcessors];
Console.WriteLine("Creating {0} thread(s)", nbProcessors); Console.WriteLine("Creating {0} thread(s)", nbProcessors);
for (int i = 0; i < nbProcessors; i++) for (int i = 0; i < nbProcessors; i++)
{ {
threads[i] = new Thread(new ParameterizedThreadStart(ApplyFilterTask)); threads[i] = new Thread(new ParameterizedThreadStart(ApplyFilterTask));
//double param = 1 + i * stepSize;
threads[i].Start(i); threads[i].Start(i);
} }
...@@ -87,8 +91,19 @@ namespace S04_Projet ...@@ -87,8 +91,19 @@ namespace S04_Projet
private unsafe void ApplyFilterTask(object i) private unsafe void ApplyFilterTask(object i)
{ {
int x, y; int x, y;
int start = opt.width * opt.height / nbProcessors * (int)i; int nbPixel = opt.width * opt.height;
int end = opt.width * opt.height / nbProcessors * ((int)i + 1); int start = nbPixel / nbProcessors * (int)i;
int end = nbPixel / nbProcessors * ((int)i + 1);
/*double param = (double)i;
int start = (int)(Math.Log(param) * nbPixel);
int end;
if (param + stepSize < Math.E) end = (int)(Math.Log(param + stepSize) * nbPixel);
else end = nbPixel;
Console.WriteLine((double)i + "Start : " + start);
Console.WriteLine((double)i + "End : " + end);*/
byte[,] rMatrix = new byte[size, size]; byte[,] rMatrix = new byte[size, size];
byte[,] gMatrix = new byte[size, size]; byte[,] gMatrix = new byte[size, size];
byte[,] bMatrix = new byte[size, size]; byte[,] bMatrix = new byte[size, size];
......
This diff is collapsed.
...@@ -24,7 +24,7 @@ namespace S04_Projet ...@@ -24,7 +24,7 @@ namespace S04_Projet
public int fileSize; public int fileSize;
public int offset; public int offset;
public Options() { } public Options() {}
/// <summary> /// <summary>
/// Return a new instance of Options with the same parameters /// Return a new instance of Options with the same parameters
...@@ -32,22 +32,24 @@ namespace S04_Projet ...@@ -32,22 +32,24 @@ namespace S04_Projet
/// <returns>New option instance</returns> /// <returns>New option instance</returns>
public Options Copy() public Options Copy()
{ {
Options options = new Options(); Options options = new Options
options.fileInfoHeaderSize = fileInfoHeaderSize; {
options.width = width; fileInfoHeaderSize = fileInfoHeaderSize,
options.height = height; width = width,
options.padding = padding; height = height,
options.colorPlanesNb = colorPlanesNb; padding = padding,
options.bitsPerPixel = bitsPerPixel; colorPlanesNb = colorPlanesNb,
options.compressionMethod = compressionMethod; bitsPerPixel = bitsPerPixel,
options.imgSize = imgSize; compressionMethod = compressionMethod,
options.horizontalRes = horizontalRes; imgSize = imgSize,
options.VerticalRes = VerticalRes; horizontalRes = horizontalRes,
options.nbColor = nbColor; VerticalRes = VerticalRes,
options.nbImportantColor = nbImportantColor; nbColor = nbColor,
options.format = format; nbImportantColor = nbImportantColor,
options.fileSize = fileSize; format = format,
options.offset = offset; fileSize = fileSize,
offset = offset
};
return options; return options;
} }
......
...@@ -60,12 +60,12 @@ namespace S04_Projet ...@@ -60,12 +60,12 @@ namespace S04_Projet
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
MyImage imgg = new MyImage("img/flocon.bmp"); MyImage imgg = new MyImage("img/image.bmp");
Console.WriteLine("Loading done"); Console.WriteLine("Loading done");
sw.Start(); sw.Start();
MyImage newImg = imgg.Filter(sharpenFilter, 1); MyImage filter = imgg.Filter(edgeDetect3Filter, 1);
sw.Stop(); sw.Stop();
newImg.Save("filter.bmp"); filter.Save("filter.bmp");
Console.WriteLine(sw.ElapsedMilliseconds); Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read(); Console.Read();
......
This diff is collapsed.
This image diff could not be displayed because it is too large. You can view the blob instead.
S04_Projet/bin/Debug/img/coco.bmp

188 KB | W: | H:

S04_Projet/bin/Debug/img/coco.bmp

188 KB | W: | H:

S04_Projet/bin/Debug/img/coco.bmp
S04_Projet/bin/Debug/img/coco.bmp
S04_Projet/bin/Debug/img/coco.bmp
S04_Projet/bin/Debug/img/coco.bmp
  • 2-up
  • Swipe
  • Onion skin
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