Zopfli is not always smaller

This commit is contained in:
topjohnwu 2021-08-28 17:16:20 -07:00
parent 7343c195b7
commit 34e5a7cd24
4 changed files with 16 additions and 1 deletions

View File

@ -541,6 +541,14 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
} else {
hdr->kernel_size() = xwrite(fd, raw_buf, raw_size);
}
if (boot.flags[ZIMAGE_KERNEL] &&
boot.k_fmt == GZIP && hdr->kernel_size() > boot.hdr->kernel_size()) {
// Revert and try zipfoli
ftruncate(fd, lseek(fd, -hdr->kernel_size(), SEEK_CUR));
hdr->kernel_size() = compress(ZOPFLI, fd, raw_buf, raw_size);
}
munmap(raw_buf, raw_size);
}
if (boot.flags[ZIMAGE_KERNEL]) {

View File

@ -624,8 +624,9 @@ stream_ptr get_encoder(format_t type, stream_ptr &&base) {
return make_unique<LZ4_encoder>(std::move(base), false);
case LZ4_LG:
return make_unique<LZ4_encoder>(std::move(base), true);
case GZIP:
case ZOPFLI:
return make_unique<zopfli_encoder>(std::move(base));
case GZIP:
default:
return make_unique<gz_encoder>(std::move(base));
}
@ -643,6 +644,7 @@ stream_ptr get_decoder(format_t type, stream_ptr &&base) {
case LZ4_LEGACY:
case LZ4_LG:
return make_unique<LZ4_decoder>(std::move(base));
case ZOPFLI:
case GZIP:
default:
return make_unique<gz_decoder>(std::move(base));

View File

@ -47,6 +47,8 @@ const char *Fmt2Name::operator[](format_t fmt) {
switch (fmt) {
case GZIP:
return "gzip";
case ZOPFLI:
return "zopfli";
case LZOP:
return "lzop";
case XZ:
@ -73,6 +75,7 @@ const char *Fmt2Name::operator[](format_t fmt) {
const char *Fmt2Ext::operator[](format_t fmt) {
switch (fmt) {
case GZIP:
case ZOPFLI:
return ".gz";
case LZOP:
return ".lzo";
@ -96,6 +99,7 @@ const char *Fmt2Ext::operator[](format_t fmt) {
format_t Name2Fmt::operator[](std::string_view name) {
if (0) {}
CHECK("gzip", GZIP)
CHECK("zopfli", ZOPFLI)
CHECK("xz", XZ)
CHECK("lzma", LZMA)
CHECK("bzip2", BZIP2)

View File

@ -12,6 +12,7 @@ typedef enum {
BLOB,
/* Compression formats */
GZIP,
ZOPFLI,
XZ,
LZMA,
BZIP2,