-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder1.cpp
More file actions
109 lines (96 loc) · 2.28 KB
/
Copy pathdecoder1.cpp
File metadata and controls
109 lines (96 loc) · 2.28 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
// Author: Sean Davis
#include <cstdlib>
#include <iostream>
#include <ostream>
#include "BinaryHeap.h"
#include "decoder.h"
using namespace std;
Decoder::Decoder()
{
} // Decoder()
Decoder::~Decoder()
{
} // ~Decoder()
void Decoder::decode(const unsigned char* encodedMessage, const int encodedSize,
unsigned char* decodedMessage, int *decodedSize)
{
unsigned int codeTable[256];
char length;
int count = 0;
unsigned int t;
int pos = 1;
//for (int i = 0; i < 1025; i++)
// cout << (int)encodedMessage[i] << endl;
for (int i = 1; i < 1023; i++)
{
t = 0;
length = encodedMessage[i];
int j = i;
if (encodedMessage[i] == 32){
if (encodedMessage[i+1] == 255 && encodedMessage[i+2] == 255 && encodedMessage[i+3] == 255){
t = -1;
}
}
else{
while (length > 8)
{
t += encodedMessage[i++] << (length - 8);
length = length - 8;
}
i++;
t += encodedMessage[i] >> (8 - length);
}
//cout << " t is : " << t << endl;
codeTable[count] = t;
count++;
if (i != j + 3)
i = j + 3;
}
for (int i = 0; i < 256; i++){
if (codeTable[i] != -1)
cout << (char)i << " : " << (int)codeTable[i] << endl;
}
//BinaryHeap<node *>decodeHuff(256);
//decodeHuff.read(codeTable);
//decodeHuff.Htree();
pos = 0;
for (int i = 1; i <= 1024; i++)
{
if(codeTable[i] != -1)
{
pos = i;
if (codeTable[pos] == 0)
}
}
//node *min = decodeHuff.findMin();
//i = 1;
/*for (int i = 0; i < 256; i++){
while (min->left)
{
if (codeTable[i] == 0)
min = min->left;
else
min = min->right;
}
decodedMessage[i] = (char)codeTable[i];
}
for (int i =0; i < encodedSize; i++)
cout << (char)decodedMessage[i];*/
/* for (int i = 0; i < 256; i++)
{
codeTable[i] = encodedMessage[i];
//cout << (char)i << " value " << codeTable[i] << endl;
}
for (int i = 0; i < 256; i++)
tab[codeTable[i]] = i;
//cout << " hi";
for (int i = 256; i < encodedSize; i++){
// cout << "_____________________" << endl;
// cout << " " << encodedMessage[i] << " " << endl;
}
for (int i = 256; i < encodedSize; i++)
{
decodedMessage[i - 256] = tab[encodedMessage[i]];
//cout << decodedMessage[i - 256];
}*/
} // decode()