Skip to content

Commit

Permalink
Merge static blocks, test converting and merging
Browse files Browse the repository at this point in the history
  • Loading branch information
NeRdTheNed committed Nov 9, 2023
1 parent efb5ca7 commit 37a60cf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1223,15 +1223,50 @@ public void discard() {
rlePairs = null;
}

// TODO
// TODO Merge dynamic blocks
@Override
public boolean canMerge(DeflateBlock append) {
return false;
return (append != null) && ((append.getDeflateBlockType() == DeflateBlockType.FIXED) || (append.getDeflateBlockType() == DeflateBlockType.DYNAMIC));
}

// TODO
// TODO Merge dynamic blocks
@Override
public DeflateBlock merge(DeflateBlock append) {
if ((append.getDeflateBlockType() == DeflateBlockType.FIXED) || (append.getDeflateBlockType() == DeflateBlockType.DYNAMIC)) {
DeflateBlockHuffman thisFixed;

if (getDeflateBlockType() == DeflateBlockType.DYNAMIC) {
thisFixed = (DeflateBlockHuffman) copy();
thisFixed.recodeToFixedHuffman();
} else {
thisFixed = this;
}

DeflateBlockHuffman otherFixed;

if (append.getDeflateBlockType() == DeflateBlockType.DYNAMIC) {
otherFixed = (DeflateBlockHuffman) append.copy();
otherFixed.recodeToFixedHuffman();
} else {
otherFixed = (DeflateBlockHuffman) append;
}

final DeflateBlockHuffman merged = (DeflateBlockHuffman) thisFixed.copy();
merged.decodedData = Util.combine(getUncompressedData(), append.getUncompressedData());
merged.ensureDidCopyLitLens();
final LitLen eob = merged.litlens.remove(merged.litlens.size() - 1);
merged.litlens.addAll(otherFixed.litlens);
merged.sizeBits -= merged.litlenSizeBits;

for (final LitLen litlenThis : otherFixed.litlens) {
merged.litlenSizeBits += getLitLenSize(litlenThis, merged.litlenDec, merged.distDec);
}

merged.litlenSizeBits -= getLitLenSize(eob, merged.litlenDec, merged.distDec);
merged.sizeBits += merged.litlenSizeBits;
return merged;
}

return null;
}
}
1 change: 1 addition & 0 deletions runTestOpt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
gradle build

java -ea -jar ./deft4j-cmd/build/libs/deft4j-cmd-all.jar optimise ./test/deflate-store-2.txt.gz ./test/deflate-store-2-opt.txt.gz | tee ./test/deflate-store-2-opt.txt.gz.txt
java -ea -jar ./deft4j-cmd/build/libs/deft4j-cmd-all.jar optimise ./test/lz-twice-twice.txt.gz ./test/lz-twice-twice-opt.txt.gz | tee ./test/lz-twice-twice-opt.txt.gz.txt
java -ea -jar ./deft4j-cmd/build/libs/deft4j-cmd-all.jar optimise ./test/asyoulik/asyoulik-gzip.txt.gz ./test/asyoulik/asyoulik-gzip-opt.txt.gz | tee ./test/asyoulik/asyoulik-gzip-opt.txt.gz.txt
java -ea -jar ./deft4j-cmd/build/libs/deft4j-cmd-all.jar optimise ./test/asyoulik/asyoulik-zopfli.txt.gz ./test/asyoulik/asyoulik-zopfli-opt.txt.gz | tee ./test/asyoulik/asyoulik-zopfli-opt.txt.gz.txt
java -ea -jar ./deft4j-cmd/build/libs/deft4j-cmd-all.jar optimise ./test/text.png ./test/text-opt.png | tee ./test/text-opt.png.txt
Expand Down
Binary file added test/lz-twice-twice-opt.txt.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions test/lz-twice-twice-opt.txt.gz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File type recognised as GZip
10 bits saved in stream 0 (lz.txt)
Total bits saved 10
Saved 10 bits with optimisation

0 comments on commit 37a60cf

Please sign in to comment.