Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imageProcessing
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ecole
imageProcessing
Commits
a79faff5
Commit
a79faff5
authored
Mar 26, 2018
by
Théophile BORNON
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multithreaded loading and test scripts
parent
158e1f69
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
152 additions
and
83 deletions
+152
-83
ImageProcessing.exe
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
+0
-0
MultiThreadedTask.cs
S04_Projet/MultiThreadedTask.cs
+87
-17
MyImage.cs
S04_Projet/MyImage.cs
+8
-5
Program.cs
S04_Projet/Program.cs
+42
-61
ImageProcessing.exe
S04_Projet/bin/Debug/ImageProcessing.exe
+0
-0
loadMTL.bat
S04_Projet/bin/Debug/loadMTL.bat
+5
-0
loadSaveScript.bat
S04_Projet/bin/Debug/loadSaveScript.bat
+5
-0
loadScript.bat
S04_Projet/bin/Debug/loadScript.bat
+5
-0
No files found.
ImageProcessing_Benchmark/bin/Debug/ImageProcessing.exe
View file @
a79faff5
No preview for this file type
S04_Projet/MultiThreadedTask.cs
View file @
a79faff5
...
...
@@ -8,6 +8,7 @@ namespace S04_Projet
#
region
Attributs
public
enum
Operation
{
Load
,
Filter
}
...
...
@@ -21,6 +22,7 @@ namespace S04_Projet
private
byte
[]
file
;
private
byte
[]
NewRMatrix
,
NewGMatrix
,
NewBMatrix
;
byte
*
rPixelPtr
,
gPixelPtr
,
bPixelPtr
;
byte
*
filePtr
;
private
int
nbPixel
;
private
int
nbProcessors
;
private
Options
opt
;
...
...
@@ -35,8 +37,19 @@ namespace S04_Projet
public
void
SetFile
(
byte
[]
file
)
=>
this
.
file
=
file
;
/// <summary>
/// Constructeur pour l'opération Filter
/// </summary>
/// <param name="ToDo"></param>
/// <param name="rPixelPtr"></param>
/// <param name="gPixelPtr"></param>
/// <param name="bPixelPtr"></param>
/// <param name="opt"></param>
/// <param name="filter"></param>
/// <param name="factor"></param>
public
unsafe
MultiThreadedTask
(
Operation
ToDo
,
byte
*
rPixelPtr
,
byte
*
gPixelPtr
,
byte
*
bPixelPtr
,
Options
opt
,
short
[,]
filter
,
double
factor
)
{
if
(
ToDo
==
Operation
.
Filter
)
{
this
.
ToDo
=
ToDo
;
this
.
opt
=
opt
;
...
...
@@ -49,15 +62,72 @@ namespace S04_Projet
size
=
filter
.
GetLength
(
0
);
nbProcessors
=
4
;
}
else
throw
new
Exception
(
"Impossible d'utiliser ce constructeur pour ce type d'opération"
);
}
public
unsafe
MultiThreadedTask
(
Operation
ToDo
,
Options
opt
,
byte
*
rPixelPtr
,
byte
*
gPixelPtr
,
byte
*
bPixelPtr
)
/// <summary>
/// Constructeur pour l'opération Load
/// </summary>
/// <param name="ToDo"></param>
/// <param name="opt"></param>
/// <param name="rPixelPtr"></param>
/// <param name="gPixelPtr"></param>
/// <param name="bPixelPtr"></param>
/// <param name="filePtr"></param>
public
unsafe
MultiThreadedTask
(
Operation
ToDo
,
Options
opt
,
byte
*
rPixelPtr
,
byte
*
gPixelPtr
,
byte
*
bPixelPtr
,
byte
*
filePtr
)
{
if
(
ToDo
==
Operation
.
Load
)
{
this
.
ToDo
=
ToDo
;
this
.
rPixelPtr
=
rPixelPtr
;
this
.
gPixelPtr
=
gPixelPtr
;
this
.
bPixelPtr
=
bPixelPtr
;
this
.
ToDo
=
ToDo
;
this
.
opt
=
opt
;
this
.
filePtr
=
filePtr
;
nbPixel
=
opt
.
width
*
opt
.
height
;
nbProcessors
=
Environment
.
ProcessorCount
;
}
else
throw
new
Exception
(
"Impossible d'utiliser ce constructeur pour ce type d'opération"
);
}
#
region
LoadImage
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
);
}
for
(
int
i
=
0
;
i
<
nbProcessors
;
i
++)
threads
[
i
].
Join
();
}
private
unsafe
void
LoadImageTask
(
object
i
)
{
if
(
filePtr
!=
null
)
{
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
;
*(
bPixelPtr
+
j
)
=
*(
filePtr
+
opt
.
offset
+
opt
.
padding
*
y
+
j
*
3
);
*(
gPixelPtr
+
j
)
=
*(
filePtr
+
opt
.
offset
+
opt
.
padding
*
y
+
j
*
3
+
1
);
*(
rPixelPtr
+
j
)
=
*(
filePtr
+
opt
.
offset
+
opt
.
padding
*
y
+
j
*
3
+
2
);
}
}
}
#
endregion
#
region
Filter
public
MyImage
ApplyFilter
()
...
...
S04_Projet/MyImage.cs
View file @
a79faff5
...
...
@@ -12,6 +12,7 @@ namespace S04_Projet
byte
[]
file
;
private
int
nbProcessors
;
public
enum
GrayFilterType
{
LINEAR
,
...
...
@@ -129,12 +130,14 @@ namespace S04_Projet
#
endregion
#
region
Multithreading
/*
else
else
{
MultiThreadedTask LoadImageTask = new MultiThreadedTask(MultiThreadedTask.Operation.Load, file, opt);
LoadImageTask.Start();
Pixels = LoadImageTask.getPixelMatrix();
}*/
fixed
(
byte
*
filePtr
=
file
,
rPtr
=
rPixels
,
gPtr
=
gPixels
,
bPtr
=
bPixels
)
{
MultiThreadedTask
LoadImageTask
=
new
MultiThreadedTask
(
MultiThreadedTask
.
Operation
.
Load
,
opt
,
rPtr
,
gPtr
,
bPtr
,
filePtr
);
LoadImageTask
.
LoadImage
();
}
}
#
endregion
file
=
null
;
...
...
S04_Projet/Program.cs
View file @
a79faff5
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Drawing
;
using
System.Diagnostics
;
using
System.IO
;
...
...
@@ -12,71 +7,27 @@ namespace S04_Projet
class
Program
{
public
static
bool
MULTITHREADING_LOAD
=
false
;
public
static
bool
MULTITHREADING
=
tru
e
;
public
static
bool
MULTITHREADING
=
fals
e
;
public
static
bool
DEBUG
=
false
;
private
static
string
[]
menuItems
=
new
string
[]
{
"Charger une image"
,
"Créer une image"
};
private
static
Menu
welcomeMenu
=
new
Menu
(
menuItems
);
private
static
MyImage
img
;
private
static
Stopwatch
sw
=
new
Stopwatch
();
static
void
Main
(
string
[]
args
)
{
Stopwatch
sw
=
new
Stopwatch
();
/*
MyImage img = new MyImage("img/kitten.bmp");
Console.WriteLine("Loading done");
sw.Start();
img = img.ToGrayScale(4, MyImage.GrayFilterType.LUMINOSITY).Dithering(1);
sw.Stop();
img.Save("dither.bmp");
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();
*/
#
region
Arguments
/*if (args.Length > 0)
{
MULTITHREADING = false;
bool filter = false;
string inputPath = "";
string outputPath = "";
for (int i = 0; i < args.Length; i++)
{
if (args[i].Equals("--input"))
{
inputPath = args[i + 1];
i++;
}
else if (args[i].Equals("--output"))
if
(
args
.
Length
>
0
)
{
outputPath = args[i + 1];
i++;
Arguments
(
args
,
0
);
}
else if (args[i].Equals("--multithreading")) MULTITHREADING = true;
else if (args[i].Equals("--filter")) filter = true;
}
if(inputPath != "")
{
MyImage img = new MyImage(inputPath);
if (filter) img = img.ApplyConvFilter(edgeDetect1Filter, 1);
if (outputPath != "")
{
img.Save(outputPath);
} else
{
Console.WriteLine("No output specified, program will only load image in memory and stop");
}
} else
{
Console.WriteLine("--input argument required");
}
}*/
#
endregion
#
region
Display
MyImage
img
;
else
{
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
Console
.
WriteLine
(
"#############################################################"
);
...
...
@@ -111,7 +62,37 @@ namespace S04_Projet
Console
.
Read
();
}
#
endregion
}
private
static
void
Arguments
(
string
[]
args
,
int
i
)
{
int
increment
=
1
;
if
(
DEBUG
)
sw
.
Restart
();
if
(
args
[
i
]
==
"--input"
||
args
[
i
]
==
"-i"
)
{
img
=
new
MyImage
(
args
[
i
+
1
]);
increment
=
2
;
}
else
if
(
args
[
i
]
==
"--output"
||
args
[
i
]
==
"-o"
)
{
if
(
img
!=
null
)
img
.
Save
(
args
[
i
+
1
]);
increment
=
2
;
}
else
if
(
args
[
i
]
==
"--debug"
||
args
[
i
]
==
"-d"
)
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
]
==
"--"
)
;
if
(
DEBUG
)
{
sw
.
Stop
();
File
.
AppendAllText
(
"debug.csv"
,
args
[
i
].
Replace
(
"-"
,
""
)
+
";"
+
sw
.
ElapsedMilliseconds
+
";\n"
);
}
if
(
i
+
increment
<
args
.
Length
)
Arguments
(
args
,
i
+
increment
);
}
}
}
S04_Projet/bin/Debug/ImageProcessing.exe
View file @
a79faff5
No preview for this file type
S04_Projet/bin/Debug/loadMTL.bat
0 → 100644
View file @
a79faff5
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -MTL -i img\flocon.bmp
)
\ No newline at end of file
S04_Projet/bin/Debug/loadSaveScript.bat
0 → 100644
View file @
a79faff5
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -i img\flocon.bmp -o output.bmp
)
\ No newline at end of file
S04_Projet/bin/Debug/loadScript.bat
0 → 100644
View file @
a79faff5
@echo off
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
ImageProcessing.exe -d -i img\flocon.bmp
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment