Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Unified Diff: utility/bmpblk_utility.cc

Issue 6523019: Enable LZMA compression in bmpbklk_utility. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Remove unnecessary code Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utility/bmpblk_util.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utility/bmpblk_utility.cc
diff --git a/utility/bmpblk_utility.cc b/utility/bmpblk_utility.cc
index 9f912d0b0a0b6ae1af239a0e6438013551ddbf77..c9188a8e76e5349cb823b267586cbc257399eed6 100644
--- a/utility/bmpblk_utility.cc
+++ b/utility/bmpblk_utility.cc
@@ -10,6 +10,7 @@
#include <assert.h>
#include <errno.h>
#include <getopt.h>
+#include <lzma.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -326,6 +327,38 @@ void BmpBlockUtil::load_all_image_files() {
free(tmpbuf);
}
break;
+ case COMPRESS_LZMA1:
+ {
+ // Calculate the worst case of buffer size.
+ uint32_t tmpsize = lzma_stream_buffer_bound(content.size());
+ uint8_t *tmpbuf = (uint8_t *)malloc(tmpsize);
+ lzma_stream stream = LZMA_STREAM_INIT;
+ lzma_options_lzma options;
+ lzma_ret result;
+
+ lzma_lzma_preset(&options, 9);
+ result = lzma_alone_encoder(&stream, &options);
+ if (result != LZMA_OK) {
+ error("Unable to initialize easy encoder (error: %d)!\n", result);
+ }
+
+ stream.next_in = (uint8_t *)content.data();
+ stream.avail_in = content.size();
+ stream.next_out = tmpbuf;
+ stream.avail_out = tmpsize;
+ result = lzma_code(&stream, LZMA_FINISH);
+ if (result != LZMA_STREAM_END) {
+ error("Unable to encode data (error: %d)!\n", result);
+ }
+
+ it->second.data.compression = compression_;
+ it->second.compressed_content.assign((const char *)tmpbuf,
+ tmpsize - stream.avail_out);
+ it->second.data.compressed_size = tmpsize - stream.avail_out;
+ lzma_end(&stream);
+ free(tmpbuf);
+ }
+ break;
default:
error("Unsupported compression method attempted.\n");
}
@@ -535,7 +568,7 @@ static void usagehelp_exit(const char *prog_name) {
" -z NUM = compression algorithm to use\n"
" 0 = none\n"
" 1 = EFIv1\n"
- " 2 = TBD\n"
+ " 2 = LZMA1\n"
"\n", prog_name);
printf(
"To display the contents of a BMPBLOCK:\n"
« no previous file with comments | « utility/bmpblk_util.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698