/
Cjpeg.cs
88 lines (65 loc) · 1.98 KB
/
Cjpeg.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
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
public class Cjpeg
{
public APP0 app0 = new APP0();
public DQT dqt = new DQT();
public DHT dht = new DHT();
public SOF0 sof = new SOF0();
public SOS sos = new SOS();
public CBlock cb = null;
BinaryReader br;
public Cjpeg(string path)
{
br = new BinaryReader(File.Open(path, FileMode.Open));
read_file();
cb = new CBlock(sof.width / 8, sof.height / 8);
br.Close();
}
public Cjpeg(Cjpeg prev)
{
app0 = new APP0(prev.app0);
dqt = new DQT(prev.dqt);
dht = new DHT(prev.dht);
sof = new SOF0(prev.sof);
sos = new SOS(prev.sos);
cb = new CBlock(prev.cb);
}
public void read_file()
{
for (int i = 0; br.BaseStream.Position < br.BaseStream.Length; i++)
{
if (br.ReadByte() == 0xff)
{
switch (br.ReadByte())
{
case 0xe0:
app0.ReadMarker(ref br);
break;
case 0xdb:
dqt.ReadMarker(ref br);
break;
case 0xc0:
sof.ReadMarker(ref br);
break;
case 0xc4:
dht.ReadMarker(ref br);
break;
case 0xda:
sos.ReadMarker(ref br);
break;
case 0xd9:
return;
default:
break;
}
}
}
}
}
}