Commit b2f32485 authored by unknown's avatar unknown

Parallelism

parent 9d492d61
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -13,11 +15,89 @@ namespace S04_Projet
private int offset;
private int width;
private int height;
private Pixel[,] Pixel;
private Pixel[,] Pixels;
public MyImage(string path)
{
byte[] file = new byte[0];
try
{
file = File.ReadAllBytes(path);
}
catch (Exception e)
{
Console.WriteLine("Une erreur est survenue : " + e.Message);
}
finally
{
#region Header
string format = (char)file[0] + "" + (char)file[1];
int endian = EndianToInt(file, 2, 6);
int offset = EndianToInt(file, 10, 14);
Console.WriteLine("Format : {0}\nTaille : {1} octets", format, endian);
Console.WriteLine("Offset : " + offset);
#endregion
#region File info
int fileInfoHeaderSize = EndianToInt(file, 14, 18);
int width = EndianToInt(file, 18, 22);
int height = EndianToInt(file, 22, 26);
int colorPlanesNb = EndianToInt(file, 26, 28);
int bitsPerPixel = EndianToInt(file, 28, 30);
int compressionMethod = EndianToInt(file, 30, 34);
int imgSize = EndianToInt(file, 34, 38);
int horizontalRes = EndianToInt(file, 38, 42);
int VerticalRes = EndianToInt(file, 42, 46);
int nbColor = EndianToInt(file, 46, 50);
int nbImportantColor = EndianToInt(file, 50, 54);
Console.WriteLine("File info header size : {0} octets", fileInfoHeaderSize);
Console.WriteLine("Size : {0}x{1}px", width, height);
Console.WriteLine("Color planes number : " + colorPlanesNb);
Console.WriteLine("Bits per pixel : " + bitsPerPixel);
Console.WriteLine("Compression method : " + compressionMethod);
Console.WriteLine("Image size : {0} octets", imgSize);
Console.WriteLine("Horizontal res : {0}\nVertical res : {1}", horizontalRes, VerticalRes);
Console.WriteLine("Number of colors : " + nbColor);
Console.WriteLine("Number of important colors : " + nbImportantColor);
#endregion
#region Pixel array
int pixelNumber = width * height;
Pixels = new Pixel[width, height];
Stopwatch s = new Stopwatch();
#region Mono
s.Start();
for (int i = 0; i < pixelNumber; i++)
{
int x = i % width;
int y = i / width;
byte r = file[i * 3 + offset];
byte g = file[i * 3 + offset + 1];
byte b = file[i * 3 + offset + 2];
Pixels[x, y] = new Pixel(r,g,b);
}
s.Stop();
Console.WriteLine(s.ElapsedMilliseconds);
#endregion
#region Parallel
/*s.Start();
Parallel.For(0, pixelNumber, i =>
{
int x = i % width;
int y = i / width;
Pixels[x, y] = new Pixel(file[i * 3 + offset], file[i * 3 + offset + 1], file[i * 3 + offset + 2]);
});
s.Stop();
Console.WriteLine(s.ElapsedMilliseconds);*/
#endregion
#endregion
}
}
public void FromImageToFile(string path)
......
......@@ -8,8 +8,15 @@ namespace S04_Projet
{
public class Pixel
{
int red;
int green;
int blue;
byte r;
byte g;
byte b;
public Pixel(byte r, byte g, byte b)
{
this.r = r;
this.g = g;
this.b = b;
}
}
}
......@@ -13,44 +13,7 @@ namespace S04_Projet
{
static void Main(string[] args)
{
byte[] file = File.ReadAllBytes("img/lac_en_montagne.bmp");
#region Header
string format = (char)file[0] + "" + (char)file[1];
int endian = MyImage.EndianToInt(file, 2, 6);
int offset = MyImage.EndianToInt(file, 10, 14);
Console.WriteLine("Format : {0}\nTaille : {1} octets", format, endian);
Console.WriteLine("Offset : " + offset);
#endregion
#region File info
int fileInfoHeaderSize = MyImage.EndianToInt(file, 14, 18);
int width = MyImage.EndianToInt(file, 18, 22);
int height = MyImage.EndianToInt(file, 22, 26);
int colorPlanesNb = MyImage.EndianToInt(file, 26, 28);
int bitsPerPixel = MyImage.EndianToInt(file, 28, 30);
int compressionMethod = MyImage.EndianToInt(file, 30, 34);
int imgSize = MyImage.EndianToInt(file, 34, 38);
int horizontalRes = MyImage.EndianToInt(file, 38, 42);
int VerticalRes = MyImage.EndianToInt(file, 42, 46);
int nbColor = MyImage.EndianToInt(file, 46, 50);
int nbImportantColor = MyImage.EndianToInt(file, 50, 54);
Console.WriteLine("File info header size : {0} octets", fileInfoHeaderSize);
Console.WriteLine("Size : {0}x{1}px",width, height);
Console.WriteLine("Color planes number : " + colorPlanesNb);
Console.WriteLine("Bits per pixel : " + bitsPerPixel);
Console.WriteLine("Compression method : " + compressionMethod);
Console.WriteLine("Image size : {0} octets", imgSize);
Console.WriteLine("Horizontal res : {0}\nVertical res : {1}", horizontalRes, VerticalRes);
Console.WriteLine("Number of colors : " + nbColor);
Console.WriteLine("Number of important colors : " + nbImportantColor);
#endregion
/*for (int i = 54; i < file.Length; i++)
{
Console.Write(file[i] + "\t");
}*/
MyImage img = new MyImage("img/lac_en_montagne.bmp");
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