Skip to content

Commit 2dac3de

Browse files
committed
Minor Updates
1 parent 401e7cb commit 2dac3de

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

arithmetic_decode_image.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using namespace std;
55
#define ll long long
66

77
const ll MIN = 0;
8-
const ll MAX = 65535;
8+
const ll MAX = 4294967295;
99

1010
ll lower[257];
1111
vector <ll> _low, _high;
@@ -22,7 +22,7 @@ string write_bits(bool bit, int bit_to_fall){
2222

2323
int to_int(int _pos, string &encode){
2424
int n = 0;
25-
for (int i = _pos; i < sizeof(short) * 8 + _pos; i++)
25+
for (int i = _pos; i < 32 + _pos; i++)
2626
{
2727
n <<= 1;
2828
n |= encode[i] - '0';
@@ -31,7 +31,7 @@ int to_int(int _pos, string &encode){
3131
}
3232

3333
ll add_bit(ll value, int count_taken, bool &flag, string &encode){
34-
bitset<16> a(value);
34+
bitset<32> a(value);
3535

3636
if(flag == 1){
3737
a.reset(0);
@@ -81,14 +81,14 @@ int main()
8181

8282
int itr = 0;
8383

84-
_low.resize(len);
85-
_high.resize(len);
84+
_low.resize(len+1);
85+
_high.resize(len+1);
8686

8787
_low[0] = MIN;
8888
_high[0] = MAX;
8989

9090
ll value = to_int(0, code);
91-
int count_taken = 16;
91+
int count_taken = 32;
9292
bool flag = 0;
9393
for(int i=1;i<len;i++){
9494
ll range = (_high[i-1] - _low[i-1] + 1);

arithmetic_encode_image.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using namespace std;
55
#include "stb_image.h"
66

77
const ll MIN = 0;
8-
const ll MAX = 65535;
8+
const ll MAX = 4294967295;
99

1010
ll lower[257];
1111
vector <ll> low, high;
@@ -81,7 +81,7 @@ int main(int argc, char** argv)
8181
// string filename;
8282
// cin>>filename;
8383

84-
uint8_t* rgb_image = stbi_load("./images/2.bmp", &width, &height, &bpp, num_channel);
84+
uint8_t* rgb_image = stbi_load("./images/9.png", &width, &height, &bpp, num_channel);
8585

8686
const ll ONE_QTR = MAX / 4 + 1;
8787
const ll HALF = 2 * ONE_QTR;
@@ -91,8 +91,8 @@ int main(int argc, char** argv)
9191
cout<<height<<" "<<width<<" "<<num_channel<<"\n";
9292
cout<<len<<"\n";
9393

94-
low.resize(len);
95-
high.resize(len);
94+
low.resize(len+1);
95+
high.resize(len+1);
9696

9797
low[0] = MIN;
9898
high[0] = MAX;
@@ -147,11 +147,12 @@ int main(int argc, char** argv)
147147
low[i] = 2 * low[i];
148148
high[i] = 2 * high[i] + 1;
149149
}
150+
150151
}
151152

152153
ll p = low[i-1];
153154

154-
for(int j=15; j>=0; j--){
155+
for(int j=31; j>=0; j--){
155156
if((p & (1LL<<j))) code += '1';
156157
else code += '0';
157158
}
@@ -167,4 +168,5 @@ int main(int argc, char** argv)
167168

168169
out << height << " " << width << " " << num_channel << "\n";
169170

171+
return 0;
170172
}

0 commit comments

Comments
 (0)