Skip to content

Commit

Permalink
Add option for Zopfli iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
NeRdTheNed committed Oct 8, 2023
1 parent 9fd4509 commit 5f3945a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public enum RecompressMode {

private final CompressionUtil compUtil;

CMDUtil(RecompressMode recompressMode) {
CMDUtil(RecompressMode recompressMode, int passes) {
recompress = recompressMode.ordinal() > RecompressMode.NONE.ordinal();
final boolean zopfli = recompressMode.ordinal() >= RecompressMode.ZOPFLI.ordinal();
final Strategy strat = recompressMode.ordinal() >= RecompressMode.ZOPFLI_EXTENSIVE.ordinal() ? Strategy.EXTENSIVE : Strategy.MULTI_CHEAP;
compUtil = recompress ? new CompressionUtil(true, true, recompressMode.ordinal() >= RecompressMode.ZOPFLI_VERY_EXTENSIVE.ordinal(), zopfli, strat, true, true) : null;
compUtil = recompress ? new CompressionUtil(true, true, recompressMode.ordinal() >= RecompressMode.ZOPFLI_VERY_EXTENSIVE.ordinal(), zopfli, passes, strat, true, true) : null;
}

CMDUtil(RecompressMode recompressMode) {
this(recompressMode, 20);
}

/** Read from the given input stream into the container, optimise, and write to the output stream */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ class Optimise implements Callable<Integer> {
@Option(names = { "--recompress-mode", "--mode", "-m" }, defaultValue = "NONE", description = "Enable various levels of recompression. Default: ${DEFAULT-VALUE}. Valid values: ${COMPLETION-CANDIDATES}")
private RecompressMode recompressMode;

@Option(names = { "--zopfli-iter", "--iter", "-I" }, defaultValue = "20", description = "Zopfli iterations. More iterations increases time spent optimising files.")
int recompressZopfliPasses = 20;

@Override
public Integer call() throws Exception {
final CMDUtil deft = new CMDUtil(recompressMode);
final CMDUtil deft = new CMDUtil(recompressMode, recompressZopfliPasses);
final boolean didOpt;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ class OptimiseFolder implements Callable<Integer> {
@Option(names = { "--recompress-mode", "--mode", "-m" }, defaultValue = "NONE", description = "Enable various levels of recompression. Default: ${DEFAULT-VALUE}. Valid values: ${COMPLETION-CANDIDATES}")
private RecompressMode recompressMode;

@Option(names = { "--zopfli-iter", "--iter", "-I" }, defaultValue = "20", description = "Zopfli iterations. More iterations increases time spent optimising files.")
int recompressZopfliPasses = 20;

@Override
public Integer call() throws Exception {
final CMDUtil deft = new CMDUtil(recompressMode);
final CMDUtil deft = new CMDUtil(recompressMode, recompressZopfliPasses);
boolean didOpt = true;

try
Expand Down

0 comments on commit 5f3945a

Please sign in to comment.