Skip to content

Commit

Permalink
fixed 5-bit long significant bits bug
Browse files Browse the repository at this point in the history
  • Loading branch information
panagiotisl committed Apr 8, 2022
1 parent fe07fad commit 97fb9f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/main/java/gr/aueb/compression/gorilla/Compressor32.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) {
out.writeBits(leadingZeros, 4); // Number of leading zeros in the next 4 bits

int significantBits = 32 - leadingZeros - trailingZeros;
out.writeBits(significantBits, 6); // Length of meaningful bits in the next 5 bits
if (significantBits == 32) {
out.writeBits(0, 5); // Length of meaningful bits in the next 5 bits
} else {
out.writeBits(significantBits, 5); // Length of meaningful bits in the next 5 bits
}

out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR

storedLeadingZeros = leadingZeros;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void nextValue() {
// New leading and trailing zeros
storedLeadingZeros = (int) in.getLong(4);

byte significantBits = (byte) in.getLong(6);
byte significantBits = (byte) in.getLong(5);
if(significantBits == 0) {
significantBits = 32;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class LossyCompressor32 {
private float trailingDiff;
private float leadingDiff;


private BitOutput out;
private int logOfError;

Expand Down Expand Up @@ -158,12 +157,15 @@ private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) {
out.writeBits(leadingZeros, 4); // Number of leading zeros in the next 4 bits

int significantBits = 32 - leadingZeros - trailingZeros;
out.writeBits(significantBits, 6); // Length of meaningful bits in the next 5 bits
if (significantBits == 32) {
out.writeBits(0, 5); // Length of meaningful bits in the next 5 bits
} else {
out.writeBits(significantBits, 5); // Length of meaningful bits in the next 5 bits
}
out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR

storedLeadingZeros = leadingZeros;
storedTrailingZeros = trailingZeros;

size += 1 + 4 + 5 + significantBits;
}

Expand Down

0 comments on commit 97fb9f8

Please sign in to comment.