diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-11-30 20:46:49 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-11-30 20:46:49 +0000 |
commit | f82292113dcffb0a7a99c055e75bbdecc7207b6e (patch) | |
tree | 1db6c794bfc6aea95743569b5e21b303948354eb | |
parent | aa2a1cdcc50dbd10890ebb5632d8b7f427ca99f4 (diff) | |
parent | 200722eb5e1524c5d0c1f4d9861e3803ea5f53a1 (diff) | |
download | puffin-f82292113dcffb0a7a99c055e75bbdecc7207b6e.tar.gz |
Merge "Allow user to specify quality when using brotli utils" am: 0859a51988 am: 200722eb5e
Original change: https://android-review.googlesource.com/c/platform/external/puffin/+/1907030
Change-Id: I30838953b2b9823c1a7f7dbbd363127807af6fa2
-rw-r--r-- | src/brotli_util.cc | 12 | ||||
-rw-r--r-- | src/include/puffin/brotli_util.h | 7 | ||||
-rw-r--r-- | src/include/puffin/common.h | 11 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/brotli_util.cc b/src/brotli_util.cc index e36e98d..587a844 100644 --- a/src/brotli_util.cc +++ b/src/brotli_util.cc @@ -20,14 +20,15 @@ constexpr auto kDefaultParamLgwin = 20; bool BrotliEncode(const uint8_t* input, size_t input_size, - UniqueStreamPtr output_stream) { + UniqueStreamPtr output_stream, + int quality) { std::unique_ptr<BrotliEncoderState, decltype(&BrotliEncoderDestroyInstance)> encoder(BrotliEncoderCreateInstance(nullptr, nullptr, nullptr), BrotliEncoderDestroyInstance); TEST_AND_RETURN_FALSE(encoder != nullptr); BrotliEncoderSetParameter(encoder.get(), BROTLI_PARAM_QUALITY, - kDefaultParamQuality); + quality); BrotliEncoderSetParameter(encoder.get(), BROTLI_PARAM_LGWIN, kDefaultParamLgwin); @@ -57,6 +58,13 @@ bool BrotliEncode(const uint8_t* input, bool BrotliEncode(const uint8_t* input, size_t input_size, + UniqueStreamPtr output_stream) { + return BrotliEncode(input, input_size, std::move(output_stream), + kDefaultParamQuality); +} + +bool BrotliEncode(const uint8_t* input, + size_t input_size, std::vector<uint8_t>* output) { TEST_AND_RETURN_FALSE(output != nullptr); return BrotliEncode(input, input_size, MemoryStream::CreateForWrite(output)); diff --git a/src/include/puffin/brotli_util.h b/src/include/puffin/brotli_util.h index 07240c3..cee84ba 100644 --- a/src/include/puffin/brotli_util.h +++ b/src/include/puffin/brotli_util.h @@ -23,6 +23,13 @@ bool BrotliEncode(const uint8_t* input, size_t input_size, std::vector<uint8_t>* output); +// Similar to the above, but quality controls how well the compression is +// |quality| should be between 0 and 11 +bool BrotliEncode(const uint8_t* input, + size_t input_size, + UniqueStreamPtr output_stream, + int quality); + // Decompress |input_size| bytes of data with brotli, and write the result to // |output_stream|. bool BrotliDecode(const uint8_t* input, diff --git a/src/include/puffin/common.h b/src/include/puffin/common.h index 07b8589..61e9eb2 100644 --- a/src/include/puffin/common.h +++ b/src/include/puffin/common.h @@ -31,13 +31,20 @@ using Buffer = std::vector<uint8_t>; // defined an extra class so the users of puffin do not have to include // puffin.pb.h and deal with its use. struct ByteExtent { - ByteExtent(uint64_t offset, uint64_t length) + constexpr ByteExtent(uint64_t offset, uint64_t length) : offset(offset), length(length) {} - bool operator==(const ByteExtent& other) const { + constexpr bool operator==(const ByteExtent& other) const { return this->length == other.length && this->offset == other.offset; } + constexpr bool operator<(const ByteExtent& other) const { + if (offset != other.offset) { + return offset < other.offset; + } + return length < other.length; + } + uint64_t offset; uint64_t length; }; |