-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImg.cs
82 lines (65 loc) · 1.62 KB
/
Img.cs
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
using System;
using System.IO;
using System.Collections.Generic;
using SFML.Graphics;
namespace Nitemare3D
{
public class BitmapImage
{
public byte width, height;
public byte[,] data;
}
public class Img
{
public static Img current;
public List<BitmapImage> entries = new List<BitmapImage>();
void LoadEntries(List<UInt32> offsets, BinaryReader reader)
{
reader.BaseStream.Position = offsets[0];
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
BitmapImage image = new BitmapImage();
image.width = reader.ReadByte();
image.height = reader.ReadByte();
image.data = new byte[image.width, image.height];
reader.BaseStream.Position += 8; //idk what the 8 bytes are lolll
for (int x = 0; x < image.width; x++)
{
for (int y = 0; y < image.height; y++)
{
image.data[x, y] = reader.ReadByte();
}
}
int id = entries.Count;
entries.Add(image);
}
}
public Img(string file)
{
BinaryReader reader = new BinaryReader(File.OpenRead(file));
reader.BaseStream.Position = 4;
//honestly we don't even need the offsets since each entry has a width and height
//smh David Gray
List<UInt32> offsets = new List<UInt32>();
int retval = 0;
UInt32 offset;
UInt32 lowestOffset = 0xFFFFFFFF;
do
{
offset = reader.ReadUInt32();
retval++;
if (offset != 0)
{
offsets.Add(offset);
if (offset < lowestOffset)
{
lowestOffset = offset;
}
}
} while (reader.BaseStream.Position <= lowestOffset);
LoadEntries(offsets, reader);
reader.BaseStream.Close();
current = this;
}
}
}