Skip to content

Commit d6eb8c5

Browse files
committed
minor changes
1 parent 2e81466 commit d6eb8c5

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

huffman_image.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ int main(int argc, char** argv)
6565
if (string(argv[1]) == "rgb")
6666
num_channel = 3;
6767
}
68+
69+
string filename;
70+
cin>>filename;
6871

6972
auto start = chrono::high_resolution_clock::now();
7073

71-
uint8_t* rgb_image = stbi_load("7.bmp", &width, &height, &bpp, num_channel);
74+
uint8_t* rgb_image = stbi_load(filename.c_str(), &width, &height, &bpp, num_channel);
75+
76+
uint8_t image[height][width][num_channel];
7277

73-
int image[height][width][num_channel];
7478
int itr = 0;
7579
for (int i = 0; i < height; ++i)
7680
for (int j = 0; j < width; ++j)
@@ -137,7 +141,7 @@ int main(int argc, char** argv)
137141
}
138142
}
139143
}
140-
cout<<compression_size<<"\n";
144+
// cout<<compression_size<<"\n";
141145
out << "\n";
142146
out << height << " " << width << " " << num_channel << "\n";
143147

improved-huffman-decode_image.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,20 @@ int main(){
130130
ptr = root;
131131
}
132132
}
133+
uint8_t* rgb_image_restore;
134+
rgb_image_restore = (uint8_t*) malloc(width*height*num_channel);
135+
itr = 0;
136+
for (int i = 0; i < height; ++i)
137+
{
138+
for (int j = 0; j < width; ++j)
139+
{
140+
rgb_image_restore[itr++] = rgb_image[i*width + j];
141+
rgb_image_restore[itr++] = rgb_image[i*width + j + width*height];
142+
rgb_image_restore[itr++] = rgb_image[i*width + j + 2*width*height];
143+
}
144+
}
133145

134-
stbi_write_png("improved_image.bmp", width, height, num_channel, rgb_image, width*num_channel);
146+
stbi_write_png("improved_image.bmp", width, height, num_channel, rgb_image_restore, width*num_channel);
135147

136148
auto stop = chrono::high_resolution_clock::now();
137149

improved-huffman_image.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ int main(int argc, char** argv)
7777
num_channel = 3;
7878
}
7979

80+
string filename;
81+
cin>>filename;
82+
8083
auto start = chrono::high_resolution_clock::now();
8184

82-
uint8_t* rgb_image = stbi_load("7.bmp", &width, &height, &bpp, num_channel);
85+
uint8_t* rgb_image = stbi_load(filename.c_str(), &width, &height, &bpp, num_channel);
8386

84-
int image[height][width][num_channel];
87+
uint8_t image[height][width][num_channel];
8588
int itr = 0;
8689
for (int i = 0; i < height; ++i)
8790
for (int j = 0; j < width; ++j)
@@ -140,11 +143,11 @@ int main(int argc, char** argv)
140143
int compression_size = 0;
141144
int last = -1;
142145
bool f = 0;
143-
for (int i = 0; i < height; ++i)
146+
for (int k = 0; k < num_channel; ++k)
144147
{
145-
for (int j = 0; j < width; ++j)
148+
for (int i = 0; i < height; ++i)
146149
{
147-
for (int k = 0; k < num_channel; ++k)
150+
for (int j = 0; j < width; ++j)
148151
{
149152
if(f == 0){
150153
compression_size += codes[image[i][j][k]].code.size();
@@ -181,7 +184,7 @@ int main(int argc, char** argv)
181184

182185
float NoBpp = ((float)compression_size)/(height*width*num_channel);
183186
float cp = (1 - ((float)compression_size)/(height*width*num_channel*8))*100;
184-
cout<<cp<<", ";
187+
cout<<height<<"x"<<width<<"x"<<num_channel<<", "<<cp<<", ";
185188
cout<<NoBpp<<", "<<(duration.count()/1000000.0)<<", ";
186189

187190

0 commit comments

Comments
 (0)