-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmapHelper.cs
More file actions
118 lines (103 loc) · 2.92 KB
/
BitmapHelper.cs
File metadata and controls
118 lines (103 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
namespace BmpInspector
{
static class BitmapHelper
{
static public void PrintRawHex(byte[] hex_data) {
int line_counter = 0;
foreach(byte s in hex_data) {
Console.Write(s.ToString("X2"));
line_counter++;
if(line_counter == 16) {
line_counter = 0;
Console.Write("\n");
}
else {
Console.Write(" ");
}
}
}
static public void PrintHexString(byte[] string_to_print) {
foreach(byte s in string_to_print) {
Console.Write(s.ToString("X2"));
Console.Write(" ");
}
}
static private void PrintDivider() {
Console.Write(" | ");
}
static private void PrintSpacer() {
Console.Write("\n\n");
}
static public void PrintFormattedHeader(MonochromeBitmap bitmap) {
Console.WriteLine("Signature | File Size | Reserved | Data Offset");
PrintHexString(bitmap.signature);
Console.Write(" | ");
PrintHexString(bitmap.file_size);
PrintDivider();
PrintHexString(bitmap.reserved);
PrintDivider();
PrintHexString(bitmap.data_offset);
PrintSpacer();
Console.WriteLine("Size | Width | Height | Planes | Bits Per Pixel");
PrintHexString(bitmap.size);
PrintDivider();
PrintHexString(bitmap.width);
PrintDivider();
PrintHexString(bitmap.height);
PrintDivider();
PrintHexString(bitmap.planes);
PrintDivider();
PrintHexString(bitmap.bits_per_pixel);
PrintSpacer();
Console.WriteLine("Compression | Image Size | XpixelsPerM | YpixelsPerM");
PrintHexString(bitmap.compression);
PrintDivider();
PrintHexString(bitmap.image_size);
PrintDivider();
PrintHexString(bitmap.xPixelsPerM);
PrintDivider();
PrintHexString(bitmap.yPixelsPerM);
PrintSpacer();
Console.WriteLine("Colors Used | Important Colors");
PrintHexString(bitmap.colors_used);
PrintDivider();
PrintHexString(bitmap.important_colors);
PrintSpacer();
Console.WriteLine("Red | Green | Blue | Reserved");
for(int chunk = 0; chunk < 4; chunk++ ) {
Console.Write(bitmap.color_table[chunk].ToString("X2"));
PrintDivider();
}
PrintSpacer();
Console.WriteLine("Red | Green | Blue | Reserved");
for(int chunk = 4; chunk < 8; chunk++ ) {
Console.Write(bitmap.color_table[chunk].ToString("X2"));
PrintDivider();
}
PrintSpacer();
PrintPixelData(bitmap, true);
}
static public void PrintPixelData(MonochromeBitmap bitmap, Boolean withBinary = true) {
int lineCounter = 0;
string binaryLine = "";
foreach(byte chunk in bitmap.pixel_data) {
Console.Write(chunk.ToString("X2"));
Console.Write(" " );
lineCounter++;
if(withBinary) {
binaryLine += Convert.ToString(chunk, 2).PadLeft(8, '0');
binaryLine += " ";
}
if(lineCounter == 4) {
if(withBinary) {
Console.Write( " | " + binaryLine );
binaryLine = "";
}
Console.Write("\n");
lineCounter = 0;
}
}
}
}
}