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

Bench scripts and minor changes

parent a79faff5
......@@ -9,7 +9,8 @@ namespace S04_Projet
public enum Operation
{
Load,
Filter
Filter,
Save
}
private enum RGB
......@@ -60,7 +61,7 @@ namespace S04_Projet
this.bPixelPtr = bPixelPtr;
nbPixel = opt.width * opt.height;
size = filter.GetLength(0);
nbProcessors = 4;
nbProcessors = Math.Min(Environment.ProcessorCount, 8);
}
else throw new Exception("Impossible d'utiliser ce constructeur pour ce type d'opération");
}
......@@ -76,7 +77,7 @@ namespace S04_Projet
/// <param name="filePtr"></param>
public unsafe MultiThreadedTask(Operation ToDo, Options opt, byte* rPixelPtr, byte* gPixelPtr, byte* bPixelPtr, byte* filePtr)
{
if (ToDo == Operation.Load)
if (ToDo == Operation.Load || ToDo == Operation.Save)
{
this.rPixelPtr = rPixelPtr;
this.gPixelPtr = gPixelPtr;
......@@ -85,20 +86,18 @@ namespace S04_Projet
this.opt = opt;
this.filePtr = filePtr;
nbPixel = opt.width * opt.height;
nbProcessors = Environment.ProcessorCount;
nbProcessors = Math.Min(Environment.ProcessorCount, 8);
}
else throw new Exception("Impossible d'utiliser ce constructeur pour ce type d'opération");
}
#region LoadImage
#region Load
public unsafe void LoadImage()
{
Console.WriteLine("Load Image");
Thread[] threads = new Thread[nbProcessors];
for (int i = 0; i < nbProcessors; i++)
{
Console.WriteLine("Creating and starting thread {0}", i);
threads[i] = new Thread(new ParameterizedThreadStart(LoadImageTask));
threads[i].Start(i);
}
......@@ -108,8 +107,6 @@ namespace S04_Projet
}
private unsafe void LoadImageTask(object i)
{
if (filePtr != null)
{
int start = nbPixel / nbProcessors * (int)i;
int end = nbPixel / nbProcessors * ((int)i + 1);
......@@ -126,7 +123,6 @@ namespace S04_Projet
*(rPixelPtr + j) = *(filePtr + opt.offset + opt.padding * y + j * 3 + 2);
}
}
}
#endregion
#region Filter
......@@ -253,5 +249,39 @@ namespace S04_Projet
else return (byte)r;
}
#endregion
#region Save
public unsafe void SaveImage()
{
Thread[] threads = new Thread[nbProcessors];
for (int i = 0; i < nbProcessors; i++)
{
threads[i] = new Thread(new ParameterizedThreadStart(SaveImageTask));
threads[i].Start(i);
}
for (int i = 0; i < nbProcessors; i++)
threads[i].Join();
}
private unsafe void SaveImageTask(object i)
{
int start = nbPixel / nbProcessors * (int)i;
int end = nbPixel / nbProcessors * ((int)i + 1);
int x, y;
for (int j = start; j < end; j++)
{
x = j % opt.width;
y = j / opt.width;
*(filePtr + opt.offset + opt.padding * y + j * 3) = *(bPixelPtr + j);
*(filePtr + opt.offset + opt.padding * y + j * 3 + 1) = *(gPixelPtr + j);
*(filePtr + opt.offset + opt.padding * y + j * 3 + 2) = *(rPixelPtr + j);
}
}
#endregion
}
}
......@@ -112,7 +112,7 @@ namespace S04_Projet
#region Mono
if (!Program.MULTITHREADING_LOAD)
if (!Program.MULTITHREADING)
{
int y;
fixed (byte* filePtr = file, rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
......@@ -181,6 +181,8 @@ namespace S04_Projet
#endregion
#region Pixel array
if (!Program.MULTITHREADING)
{
int x;
int y;
fixed (byte* filePtr = file)
......@@ -195,6 +197,16 @@ namespace S04_Projet
*(filePtr + i * 3 + opt.padding * y + opt.offset + 2) = rPixels[i];
}
}
}
else
{
fixed (byte* filePtr = file, rPtr = rPixels, gPtr = gPixels, bPtr = bPixels)
{
MultiThreadedTask SaveImageTask = new MultiThreadedTask(MultiThreadedTask.Operation.Save, opt, rPtr, gPtr, bPtr, filePtr);
SaveImageTask.SaveImage();
}
}
#endregion
try
......
......@@ -6,7 +6,7 @@ namespace S04_Projet
{
class Program
{
public static bool MULTITHREADING_LOAD = false;
//public static bool MULTITHREADING_LOAD = false;
public static bool MULTITHREADING = false;
public static bool DEBUG = false;
......@@ -83,8 +83,8 @@ namespace S04_Projet
DEBUG = true;
else if (args[i] == "--multithreading" || args[i] == "-MT")
MULTITHREADING = true;
else if (args[i] == "--multithreadingLoad" || args[i] == "-MTL")
MULTITHREADING_LOAD = true;
//else if (args[i] == "--multithreadingLoad" || args[i] == "-MTL")
// MULTITHREADING_LOAD = true;
else if (args[i] == "--") ;
if (DEBUG)
......
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -MTL -i img\flocon.bmp
ImageProcessing.exe -d -MT -i img\flocon.bmp
)
\ No newline at end of file
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -MT -i img\flocon.bmp -o output.bmp
)
\ No newline at end of file
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