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
ed73cdc6
Commit
ed73cdc6
authored
Feb 14, 2018
by
Théophile BORNON
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UI done
parent
ed995b81
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
22 deletions
+52
-22
Display.cs
S04_Projet/Display.cs
+33
-10
MyImage.cs
S04_Projet/MyImage.cs
+4
-3
MyImageThread.cs
S04_Projet/MyImageThread.cs
+0
-6
Pixel.cs
S04_Projet/Pixel.cs
+6
-1
Program.cs
S04_Projet/Program.cs
+9
-2
No files found.
S04_Projet/Display.cs
View file @
ed73cdc6
using
System
;
using
System.Collections.Generic
;
using
System.
Linq
;
using
System.
Diagnostics
;
using
System.IO
;
using
System.Threading
;
...
...
@@ -21,6 +21,10 @@ namespace S04_Projet
Save
}
public
static
long
elapsedTime
;
public
static
string
lastOperationMessage
;
public
static
string
fileInfos
;
/// <summary>
/// Charge l'image
/// </summary>
...
...
@@ -51,6 +55,9 @@ namespace S04_Projet
MyImageThread
myImageThread
=
new
MyImageThread
(
file
);
Thread
imageThread
=
new
Thread
(
new
ThreadStart
(
myImageThread
.
ThreadLoop
));
Stopwatch
sw
=
new
Stopwatch
();
sw
.
Start
();
imageThread
.
Start
();
Console
.
Write
(
"Traitement en cours de l'image."
);
...
...
@@ -59,13 +66,12 @@ namespace S04_Projet
Thread
.
Sleep
(
250
);
Console
.
Write
(
"."
);
}
sw
.
Stop
();
Console
.
Clear
();
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
WriteLine
(
"Image chargée en {0}ms\n"
,
myImageThread
.
loadTime
);
Console
.
ForegroundColor
=
ConsoleColor
.
Cyan
;
Console
.
WriteLine
(
myImageThread
.
image
.
toString
());
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
elapsedTime
=
sw
.
ElapsedMilliseconds
;
lastOperationMessage
=
"Image chargée en "
+
elapsedTime
+
"ms"
;
fileInfos
=
myImageThread
.
image
.
toString
();
return
myImageThread
.
image
;
}
...
...
@@ -76,6 +82,14 @@ namespace S04_Projet
/// <returns>Retourne le type d'opération souhaitée</returns>
public
static
Operation
AskForOperation
()
{
Console
.
Clear
();
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
WriteLine
(
lastOperationMessage
);
Console
.
WriteLine
();
Console
.
ForegroundColor
=
ConsoleColor
.
Cyan
;
Console
.
WriteLine
(
fileInfos
);
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
int
choosenItem
=
0
;
string
[]
menuItems
=
new
string
[]
{
...
...
@@ -100,12 +114,12 @@ namespace S04_Projet
key
=
Console
.
ReadKey
();
Console
.
SetCursorPosition
(
0
,
9
+
choosenItem
);
Console
.
Write
(
" "
);
if
(
key
.
Key
==
ConsoleKey
.
DownArrow
)
if
(
key
.
Key
==
ConsoleKey
.
DownArrow
)
{
choosenItem
++;
if
(
choosenItem
==
menuItems
.
Length
)
choosenItem
=
0
;
}
else
if
(
key
.
Key
==
ConsoleKey
.
UpArrow
)
else
if
(
key
.
Key
==
ConsoleKey
.
UpArrow
)
{
choosenItem
--;
if
(
choosenItem
==
-
1
)
choosenItem
=
menuItems
.
Length
-
1
;
...
...
@@ -128,12 +142,14 @@ namespace S04_Projet
public
static
MyImage
PerformOperation
(
Operation
ope
,
MyImage
img
)
{
MyImage
output
=
null
;
Stopwatch
sw
=
new
Stopwatch
();
Console
.
Clear
();
sw
.
Start
();
if
(
ope
==
Operation
.
Rotate90
)
output
=
img
.
Rotate90
();
else
if
(
ope
==
Operation
.
Rotate180
)
output
=
img
.
Rotate180
();
else
if
(
ope
==
Operation
.
Rotate270
)
output
=
img
.
Rotate270
();
else
if
(
ope
==
Operation
.
GrayScaleLinear
||
ope
==
Operation
.
GrayScaleLuminosity
)
else
if
(
ope
==
Operation
.
GrayScaleLinear
||
ope
==
Operation
.
GrayScaleLuminosity
)
{
bool
retry
=
false
;
int
input
;
...
...
@@ -146,10 +162,11 @@ namespace S04_Projet
retry
=
!
int
.
TryParse
(
Console
.
ReadLine
(),
out
input
);
}
while
(
retry
&&
input
>=
2
&&
input
<=
255
);
sw
.
Restart
();
if
(
ope
==
Operation
.
GrayScaleLinear
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
grayFilterType
.
LINEAR
);
else
if
(
ope
==
Operation
.
GrayScaleLuminosity
)
output
=
img
.
ToGrayScale
((
byte
)
input
,
MyImage
.
grayFilterType
.
LUMINOSITY
);
}
else
if
(
ope
==
Operation
.
Save
)
else
if
(
ope
==
Operation
.
Save
)
{
string
path
;
bool
anotherTry
=
false
;
...
...
@@ -162,6 +179,7 @@ namespace S04_Projet
if
(!
path
.
EndsWith
(
".bmp"
))
path
+=
".bmp"
;
}
while
(
anotherTry
=
!
Uri
.
IsWellFormedUriString
(
path
,
UriKind
.
RelativeOrAbsolute
));
sw
.
Restart
();
img
.
Save
(
path
);
}
else
...
...
@@ -169,6 +187,11 @@ namespace S04_Projet
throw
new
Exception
(
"Opération non reconnue"
);
}
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
;
}
}
...
...
S04_Projet/MyImage.cs
View file @
ed73cdc6
...
...
@@ -90,9 +90,9 @@ namespace S04_Projet
{
int
x
=
i
%
opt
.
width
;
int
y
=
i
/
opt
.
width
;
byte
r
=
file
[
i
*
3
+
opt
.
offset
];
byte
b
=
file
[
i
*
3
+
opt
.
offset
];
byte
g
=
file
[
i
*
3
+
opt
.
offset
+
1
];
byte
b
=
file
[
i
*
3
+
opt
.
offset
+
2
];
byte
r
=
file
[
i
*
3
+
opt
.
offset
+
2
];
Pixels
[
x
,
y
]
=
new
Pixel
(
r
,
g
,
b
);
}
#
endregion
...
...
@@ -155,7 +155,7 @@ namespace S04_Projet
#
region
Pixel
array
for
(
int
i
=
0
;
i
<
nbPixel
;
i
++)
{
MixArrays
(
file
,
Pixels
[
i
%
opt
.
width
,
i
/
opt
.
width
].
get
RGB
(),
54
+
(
i
*
3
));
MixArrays
(
file
,
Pixels
[
i
%
opt
.
width
,
i
/
opt
.
width
].
get
BGR
(),
54
+
(
i
*
3
));
}
#
endregion
...
...
@@ -332,6 +332,7 @@ namespace S04_Projet
public
string
toString
()
{
string
str
=
""
;
str
+=
String
.
Format
(
"Format : {0}\nTaille : {1} octets"
,
opt
.
format
,
opt
.
fileSize
)
+
"\n"
;
str
+=
String
.
Format
(
"Offset : {0} octets"
,
opt
.
offset
)
+
"\n"
;
str
+=
String
.
Format
(
"File info header size : {0} octets"
,
opt
.
fileInfoHeaderSize
)
+
"\n"
;
...
...
S04_Projet/MyImageThread.cs
View file @
ed73cdc6
...
...
@@ -11,21 +11,15 @@ namespace S04_Projet
{
public
byte
[]
file
;
public
MyImage
image
;
public
long
loadTime
;
private
Stopwatch
sw
;
public
MyImageThread
(
byte
[]
file
)
{
sw
=
new
Stopwatch
();
this
.
file
=
file
;
}
public
void
ThreadLoop
()
{
sw
.
Restart
();
image
=
new
MyImage
(
file
);
sw
.
Stop
();
loadTime
=
sw
.
ElapsedMilliseconds
;
}
}
}
S04_Projet/Pixel.cs
View file @
ed73cdc6
...
...
@@ -56,6 +56,11 @@ namespace S04_Projet
return
new
byte
[]
{
r
,
g
,
b
};
}
public
byte
[]
getBGR
()
{
return
new
byte
[]
{
b
,
g
,
r
};
}
/// <summary>
/// Retourne l'équavalent gris d'un pixel
/// </summary>
...
...
@@ -64,7 +69,7 @@ namespace S04_Projet
public
Pixel
getGrayScale
(
byte
scale
)
{
byte
total
=
(
byte
)((
r
+
g
+
b
)
/
3
);
total
=
(
byte
)(
Math
.
Round
((
double
)
total
/
(
255
/(
scale
-
1
)))
*
(
255
/
(
scale
-
1
)));
total
=
(
byte
)(
Math
.
Round
((
double
)
total
/
(
255
/
(
scale
-
1
)))
*
(
255
/
(
scale
-
1
)));
return
new
Pixel
(
total
);
}
...
...
S04_Projet/Program.cs
View file @
ed73cdc6
...
...
@@ -21,9 +21,16 @@ namespace S04_Projet
MyImage
img
=
Display
.
LoadImage
();
Display
.
Operation
ToDo
=
Display
.
AskForOperation
();
Display
.
PerformOperation
(
ToDo
,
img
);
MyImage
newImg
=
Display
.
PerformOperation
(
ToDo
,
img
);
while
(
newImg
!=
null
)
{
ToDo
=
Display
.
AskForOperation
();
newImg
=
Display
.
PerformOperation
(
ToDo
,
newImg
);
}
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
WriteLine
(
"Image sauvegardée en {0}ms!"
,
Display
.
elapsedTime
);
//Console.Clear();
...
...
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